From 64325a003a8a8534928fa95a963a6eb857aa0c60 Mon Sep 17 00:00:00 2001 From: Charles de Beauchesne Date: Thu, 19 Nov 2026 14:37:18 +0100 Subject: [PATCH] ci: configure the snapshot expiry rule without jq The aws-cli image has no jq, so configure-branch-snapshot-expiry fails with "jq: command not found". It never ran before: the pipeline always stopped earlier on devcontainer_to_ghcr, removed in #146. Use the AWS CLI's --query instead. A read error other than NoSuchLifecycleConfiguration now stops the job, instead of being read as "no rules" and replacing every rule of the bucket. Co-Authored-By: Claude Opus 5.5 --- .gitlab-ci.yml | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7bb2d34..36bbf17 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -257,21 +257,24 @@ configure-branch-snapshot-expiry: BUCKET=rum-auto-instrumentation RULE_ID=expire-httpd-branch-snapshots - # Fetch existing lifecycle config (empty array if none) - EXISTING=$(aws s3api get-bucket-lifecycle-configuration --bucket "$BUCKET" 2>/dev/null | jq '.Rules // []' || echo '[]') - - # Build the desired rule - RULE=$(jq -n '{ - ID: $id, - Filter: { Prefix: "httpd/branch-snapshots/" }, - Status: "Enabled", - Expiration: { Days: 30 } - }' --arg id "$RULE_ID") - - # Replace existing rule with same ID, or append - UPDATED=$(echo "$EXISTING" | jq --argjson rule "$RULE" ' - [.[] | select(.ID != $rule.ID)] + [$rule] - ') + # The aws-cli image has no jq: use the CLI's own --query (JMESPath). + # Keep the other rules of the bucket. No lifecycle config yet means no rule. + if ! OTHERS=$(aws s3api get-bucket-lifecycle-configuration --bucket "$BUCKET" \ + --query "Rules[?ID!='$RULE_ID']" --output json 2>/tmp/get-lifecycle.err); then + grep -q NoSuchLifecycleConfiguration /tmp/get-lifecycle.err || { cat /tmp/get-lifecycle.err; exit 1; } + OTHERS='[]' + fi + OTHERS=$(echo "$OTHERS" | tr -d '\n' | sed 's/[[:space:]]*$//') + [ "$OTHERS" = "null" ] && OTHERS='[]' + + RULE="{\"ID\": \"$RULE_ID\", \"Filter\": {\"Prefix\": \"httpd/branch-snapshots/\"}, \"Status\": \"Enabled\", \"Expiration\": {\"Days\": 30}}" + + # Append our rule to the other ones + if [ "$OTHERS" = "[]" ]; then + UPDATED="[$RULE]" + else + UPDATED="${OTHERS%]}, $RULE]" + fi aws s3api put-bucket-lifecycle-configuration \ --bucket "$BUCKET" \