Last active
November 17, 2024 19:05
-
-
Save SamJUK/b3becaf6723acf4208eb5b8d92ef24f4 to your computer and use it in GitHub Desktop.
Warden.DEV SPX Installation for versions `0.14.3` and below.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env sh | |
| # | |
| # A fairly simple shell script to install and configure PHP-SPX within a Warden.dev Environment | |
| # | |
| # @NOTE: This approach only works for versions upto `0.14.3` and below. You can check this with `warden version` | |
| # For versions 0.15.0 and above, track this discussion: https://github.com/orgs/wardenenv/discussions/719 | |
| # Or, use @bgorski implementation instead https://gist.github.com/SamJUK/b3becaf6723acf4208eb5b8d92ef24f4?permalink_comment_id=5288398#gistcomment-5288398 | |
| # | |
| # Usage: | |
| # - Download the script: `curl https://... > ~/warden-install-spx.sh` | |
| # - Set Permissions on the script `chmod +x ~/warden-install-spx.sh` | |
| # - cd to your warden project `cd ~/Projects/magento.test` | |
| # - Run the downloaded script `sh ~/warden-install-spx.sh` | |
| # | |
| # - Navigate to the SPX control panel `https://app.mywebsite.test/?SPX_KEY=dev&SPX_UI_URI=/` and enable profiling | |
| # - Hit the pages you want to profile | |
| # - Navigate back to the SPX control panel to view the traces | |
| # | |
| set -e | |
| echo "-------------------------" | |
| echo " Warden SPX Installation " | |
| echo "-------------------------" | |
| echo "[i] Checking if this is a Warden Project" | |
| warden env config >/dev/null | |
| echo "[i] Checking if SPX is already installed" | |
| RC=$(warden shell -c "php -m | grep SPX; echo $?") | |
| [ "$RC" != "0" ] && exit 255 | |
| echo "[i] Installing Dependencies" | |
| warden shell -c "sudo yum install -y php-devel" | |
| echo "[i] Downloading SPX Source Code" | |
| warden shell -c "rm -rf /tmp/spx; git clone https://github.com/NoiseByNorthwest/php-spx.git /tmp/spx" | |
| echo "[i] Building SPX Extension" | |
| warden shell -c "cd /tmp/spx && phpize && ./configure && make && sudo make install" | |
| echo "[i] Writing SPX Configuration" | |
| warden shell -c " | |
| cat - <<EOF | sudo tee -a /etc/php.d/99-spx.ini | |
| extension=spx.so | |
| spx.debug=1 | |
| spx.http_enabled=1 | |
| spx.http_ip_whitelist=* | |
| spx.http_key=dev | |
| spx.http_trusted_proxies=REMOTE_ADDR | |
| EOF | |
| " | |
| echo "[i] Add Varnish Cache Bypass" | |
| warden env exec varnish sh -c "sed -i '#^.*SPX_ENABLED.*$#d' /etc/varnish/default.vcl" | |
| warden env exec varnish sh -c "sed -i 's#sub vcl_recv {#sub vcl_recv {\nif (req.url ~ \"SPX_UI_URI|SPX_KEY\" || req.http.Cookie ~ \"SPX_ENABLED\") { return (pass); }#g' /etc/varnish/default.vcl" | |
| echo "[i] Reloading Varnish Config" | |
| T=$(date +%s) | |
| warden env exec varnish sh -c "varnishadm vcl.load reload$T /etc/varnish/default.vcl; varnishadm vcl.use reload$T;" | |
| echo "[i] Restarting PHP-FPM Container" | |
| warden env restart php-fpm |
Author
Thanks for the heads up @bgorski, I'll update the gist to include a disclaimer it does not work with 0.15.0 or above.
I'll look at getting a PR submitted to finish the implementation, if your not working on anything yourself, as its definitely going to catch me out in the future :^)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@SamJUK just to let you know, this will no longer work on the latest Warden version (or actually on the latest version of some containers). Right now we're in a temporary state where some foundations for more streamlined SPX support are already included (e.g. in nginx config) and it renders the old way of adding SPX support obsolete.
For anyone interested, to make SPX in Warden work now, you can add or modify the .warden/warden-env.yml file in your project and add the following things:
where x-volumes and x-extra_hosts are taken from
environments/includes/php-fpm.base.ymlin your warden installation (the ones above work for 0.15.0) and php-spx is a new container that will handle all requests that have SPX enabled.In order to enable SPX in your requests, add the following cookies or URL params:
To go to your SPX web UI, just use the following URL: https://yourproject.test/?SPX_UI_URI=/ where yourproject.test matches the domain you use for your project.
I'm not sure how long it will work this way, since I guess that some easier method of enabling SPX will get added to Warden in the future, but hopefully it will save someone some time setting this up for as long as there's no better way.