Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -250,24 +250,24 @@ jobs:
# Get current config
gcloud compute url-maps export stg-activitypub --global --project ${GCP_PROJECT} > config.yml
# Delete unnecessary fields
yq 'del(.fingerprint)' config.yml -i
yq 'del(.creationTimestamp)' config.yml -i
yq -i 'del(.fingerprint)' config.yml
yq -i 'del(.creationTimestamp)' config.yml
export DEFAULT_SERVICE="https://www.googleapis.com/compute/v1/projects/ghost-activitypub/global/backendServices/stg-netherlands-activitypub-api"
export PR_SERVICE="https://www.googleapis.com/compute/v1/projects/ghost-activitypub/global/backendServices/stg-pr-${{ github.event.pull_request.number }}-api"
# Add host rules and path matchers if they don't exist
yq '.hostRules = (.hostRules // [{"hosts": ["activitypub.ghostinfra.net"], "pathMatcher": "staging-environments"}])' config.yml > config.yml.tmp
mv config.yml.tmp config.yml
yq '.pathMatchers = (.pathMatchers // [{"name": "staging-environments", "defaultService": "'"$DEFAULT_SERVICE"'", "routeRules": []}])' config.yml > config.yml.tmp
mv config.yml.tmp config.yml
yq -i '.hostRules = (.hostRules // [{"hosts": ["activitypub.ghostinfra.net"], "pathMatcher": "staging-environments"}])' config.yml
yq -i '.pathMatchers = (.pathMatchers // [{"name": "staging-environments", "defaultService": "'"$DEFAULT_SERVICE"'", "routeRules": []}])' config.yml
# Remove existing route rules for the PR service
yq '.pathMatchers[] |= (.routeRules |= map(select((.routeAction.weightedBackendServices // []) | length == 0 or .routeAction.weightedBackendServices[0].backendService != env(PR_SERVICE))))' config.yml > config.yml.tmp
mv config.yml.tmp config.yml
yq -i '.pathMatchers[] |= (.routeRules |= map(select((.routeAction.weightedBackendServices // []) | length == 0 or .routeAction.weightedBackendServices[0].backendService != env(PR_SERVICE))))' config.yml
# Add new route rules for the PR service
Comment on lines +253 to 262
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Ensure yq is installed before use
You’re invoking yq -i on multiple lines, but GitHub’s Ubuntu runners don’t include yq by default. Add an installation step prior to any yq command to avoid failures:

- name: Install yq
  run: |
    sudo apt-get update
    sudo apt-get install -y yq

Place this immediately before your “Add route to GCP Load Balancer” step.

export MAX_PRIORITY=$(yq '[.pathMatchers[] | select(.name == "staging-environments") | .routeRules[]?.priority] | max // 0' config.yml)
export NEXT_PRIORITY=$((MAX_PRIORITY + 1))
export HEADER_MATCHES=$(echo "$LABELS" | jq -c '[.[] | select(.name | test("\\.ghost\\.is$")) | { "headerName": "X-Forwarded-Host", "exactMatch": "\(.name)" }'])
yq '.pathMatchers[0].routeRules += [{"priority": '"$NEXT_PRIORITY"', "matchRules": [{"prefixMatch": "/", "headerMatches": '$HEADER_MATCHES'}], "routeAction": {"weightedBackendServices": [ { "backendService": "'$PR_SERVICE'", "weight": 100 } ] } }]' config.yml > config.yml.tmp
mv config.yml.tmp config.yml
LABELS_JSON=$(echo "$LABELS" | jq -c '[.[] | select(.name | test("\\.ghost\\.is$")) | .name]')
for LABEL in $(echo "$LABELS_JSON" | jq -r '.[]'); do
echo "Adding route for label: $LABEL"
yq -i '.pathMatchers[0].routeRules += [{"priority": '$NEXT_PRIORITY', "matchRules": [{"prefixMatch": "/", "headerMatches": [{ "headerName": "X-Forwarded-Host", "exactMatch": "'$LABEL'" }]}], "routeAction": {"weightedBackendServices": [ { "backendService": "'$PR_SERVICE'", "weight": 100 } ] } }]' config.yml
export NEXT_PRIORITY=$((NEXT_PRIORITY + 1))
done
echo "Updating url map with:"
cat config.yml
gcloud compute url-maps import stg-activitypub --source=config.yml --global --project ${GCP_PROJECT} --quiet
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/ephemeral-staging-teardown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,11 @@ jobs:
# Get current config
gcloud compute url-maps export stg-activitypub --global --project ${GCP_PROJECT} > config.yml
# Delete unnecessary fields
yq 'del(.fingerprint)' config.yml -i
yq 'del(.creationTimestamp)' config.yml -i
yq -i 'del(.fingerprint)' config.yml
yq -i 'del(.creationTimestamp)' config.yml
export PR_SERVICE="https://www.googleapis.com/compute/v1/projects/ghost-activitypub/global/backendServices/stg-pr-${PR_NUMBER}-api"
# Remove existing route rules for the PR service
yq '.pathMatchers[] |= (.routeRules |= map(select((.routeAction.weightedBackendServices // []) | length == 0 or .routeAction.weightedBackendServices[0].backendService != env(PR_SERVICE))))' config.yml > config.yml.tmp
mv config.yml.tmp config.yml
yq -i '.pathMatchers[] |= (.routeRules |= map(select((.routeAction.weightedBackendServices // []) | length == 0 or .routeAction.weightedBackendServices[0].backendService != env(PR_SERVICE))))' config.yml
echo "Updating url map with:"
cat config.yml
gcloud compute url-maps import stg-activitypub --source=config.yml --global --project ${GCP_PROJECT} --quiet
Expand Down
Loading