-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: deprecate setup-fastly.sh and update deployment instructions #136
Conversation
Thanks for the PR 😍 How to test these changes in your application
Diff between recipe versionsIn order to help with the review stage, I'm in charge of computing the diff between the various versions of patched recipes. shopware/fastly-meta6.4 vs 6.6diff --git a/shopware/fastly-meta/6.4/bin/setup-fastly.sh b/shopware/fastly-meta/6.6/bin/setup-fastly.sh
index 2c2f627..95f3e68 100755
--- a/shopware/fastly-meta/6.4/bin/setup-fastly.sh
+++ b/shopware/fastly-meta/6.6/bin/setup-fastly.sh
@@ -1,136 +1,7 @@
#!/usr/bin/env bash
-# fail on error
-set -e
+echo "This script is deprecated and will be removed in the next major release. Please use vendor/bin/shopware-deployment-helper fastly:snippet:deploy directly."
-if [[ -z "$FASTLY_API_TOKEN" ]]; then
- echo "Environment variable FASTLY_API_TOKEN is not set. Skipping"
- exit 0
-fi
+sleep 5
-if [[ -z "$FASTLY_SERVICE_ID" ]]; then
- echo "Environment variable FASTLY_SERVICE_ID is not set. Skipping"
- exit 0
-fi
-
-CWD="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
-PROJECT_ROOT="${PROJECT_ROOT:-"$(dirname "$CWD")"}"
-
-cd "$PROJECT_ROOT"
-
-created_version=0
-
-create_version_if_not_done() {
- if [[ "$created_version" == "1" ]]; then
- return
- fi
-
- echo "Creating version from active version"
- fastly service-version clone --version=active
- created_version=1
-}
-
-get_md5()
-{
- if builtin command -v md5 > /dev/null; then
- echo "$1" | md5
- elif builtin command -v md5sum > /dev/null ; then
- echo "$1" | md5sum | awk '{print $1}'
- else
- echo "Neither md5 nor md5sum were found in the PATH"
- return 1
- fi
-
- return 0
-}
-
-install_fastly_cli() {
- if [[ -f "/tmp/fastly/fastly" ]]; then
- export PATH="/tmp/fastly:$PATH"
- return
- fi
-
- mkdir -p /tmp/fastly
-
- arch=$(uname -m)
- os="linux"
- version="v10.6.4"
-
- if [[ "$arch" == "x86_64" ]]; then
- arch="amd64"
- fi
-
- if [[ "$OSTYPE" == "darwin"* ]]; then
- os="darwin"
- fi
-
- echo "Detected OS: ${os} and architecture: ${arch}"
-
- file="https://github.com/fastly/cli/releases/download/${version}/fastly_${version}_${os}-${arch}.tar.gz"
-
- echo "Downloading ${file}"
-
- curl -L "${file}" | tar xz -C /tmp/fastly/
- export PATH="/tmp/fastly:$PATH"
-}
-
-install_fastly_cli
-
-# Fastly tries to write into /app on platformsh and this throws an error
-export HOME=/tmp
-
-for sub in ./config/fastly/*; do
- if ! find "$sub" -name '*.vcl' | grep . >/dev/null; then
- # No VCL files in "$sub"; moving on to the next dir
- continue
- fi
- for vcl in "$sub"/*.vcl; do
- trigger=$(basename "$vcl" .vcl)
- priority=$(echo "$trigger" | awk -F '.' '$2 ~ /^[0-9]+$/ { print $2 }')
- if test -z "$priority"; then
- priority="100"
- else
- trigger=$(basename "$trigger" ".$priority")
- fi
- vcl_type=$(basename "$sub")
-
- # For backward compatibility, default VCLs doesn't include trigger in their name
- if [[ "$trigger" == "default" ]]; then
- name="shopware_${vcl_type}"
- else
- name="shopware_${vcl_type}_${trigger}"
- fi
-
- echo "Found VCL snippet $trigger of type $vcl_type with priority $priority"
-
- if fastly vcl snippet describe --version=active "--name=$name" > /dev/null; then
- # The snippet exists on remote
- localContent=$(cat "$vcl")
- localContentMd5=$(get_md5 "$localContent")
-
- remoteContent=$(fastly vcl snippet describe --version=active "--name=$name" --json | jq -r '.Content')
- remoteContentMd5=$(get_md5 "$remoteContent")
-
- if [[ "$localContentMd5" != "$remoteContentMd5" ]]; then
- echo "Snippet ${name} has changed. Updating"
-
- create_version_if_not_done
-
- fastly vcl snippet update "--name=$name" "--content=${vcl}" "--type=${vcl_type}" "--priority=${priority}" --version=latest
- else
- echo "Snippet ${name} is up to date"
- fi
- else
- create_version_if_not_done
-
- fastly vcl snippet create "--name=$name" "--content=${vcl}" "--type=${vcl_type}" "--priority=${priority}" --version=latest
- fi
- done
-done
-
-
-if [[ "$created_version" == "1" ]]; then
- echo "Activating latest version"
-
- fastly service-version activate --version latest
-fi
+php vendor/bin/shopware-deployment-helper fastly:snippet:deploy
diff --git a/shopware/fastly-meta/6.4/config/packages/fastly.yaml b/shopware/fastly-meta/6.6/config/packages/prod/fastly.yaml
similarity index 50%
rename from shopware/fastly-meta/6.4/config/packages/fastly.yaml
rename to shopware/fastly-meta/6.6/config/packages/prod/fastly.yaml
index 704768a..3ff54bb 100644
--- a/shopware/fastly-meta/6.4/config/packages/fastly.yaml
+++ b/shopware/fastly-meta/6.6/config/packages/prod/fastly.yaml
@@ -1,8 +1,11 @@
-when@prod:
- storefront:
+# yaml-language-server: $schema=https://raw.githubusercontent.com/shopware/shopware/trunk/config-schema.json
+
+shopware:
+ http_cache:
# Uncomment all to enable soft purge
- # http_cache:
+ # Allow to serve the out-dated cache for 300 seconds
# stale_while_revalidate: 300
+ # Allow to serve the out-dated cache for an hour if the origin server is offline
# stale_if_error: 3600
reverse_proxy:
enabled: true
@@ -10,5 +13,4 @@ when@prod:
enabled: true
api_key: '%env(FASTLY_API_TOKEN)%'
service_id: '%env(FASTLY_SERVICE_ID)%'
- # Uncomment to enable soft purge
- # soft_purge: '1'
+ soft_purge: '1'
diff --git a/shopware/fastly-meta/6.4/post-install.txt b/shopware/fastly-meta/6.6/post-install.txt
index 60560a5..396697a 100644
--- a/shopware/fastly-meta/6.4/post-install.txt
+++ b/shopware/fastly-meta/6.6/post-install.txt
@@ -1,2 +1,4 @@
* Add your FASTLY_API_TOKEN and FASTLY_SERVICE_ID into .env
- * Run setup-fastly.sh to deploy the Fastly vcl files
+ * Run vendor/bin/shopware-deployment-helper fastly:snippet:deploy to deploy the Fastly snippets
+ * The Fastly snippets are now deployed and you can start using the Fastly CDN
+ * The snippets are also updated on regular vendor/bin/shopware-deployment-helper run runs |
No description provided.