-
Notifications
You must be signed in to change notification settings - Fork 3.7k
feat(ci): promote Trigger.dev tasks in lockstep with the ECS traffic cutover #5725
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
Open
TheodoreSpeaks
wants to merge
10
commits into
staging
Choose a base branch
from
trigger-deploy
base: staging
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
30e1270
feat(ci): promote Trigger.dev tasks in lockstep with the ECS traffic …
TheodoreSpeaks b207a52
fix(ci): harden Trigger.dev cutover gate — reject stale executions, v…
TheodoreSpeaks f7135b0
fix(ci): widen promote-trigger job timeout above the poll budget
TheodoreSpeaks 0d85d3b
fix(ci): hold AWS session for the full poll and skip wait when the ap…
TheodoreSpeaks 7bdaa1d
feat(ci): extend lockstep Trigger.dev promotion to dev (preview branch)
TheodoreSpeaks 2f006f0
fix(ci): don't block dev task promotion on a non-app build-dev leg fa…
TheodoreSpeaks a4483d4
chore(ci): use one Trigger.dev PAT for all envs (drop DEV_TRIGGER_ACC…
TheodoreSpeaks c7c2aab
fix(ci): reliable digest reads for no-op detection, robust version pa…
TheodoreSpeaks 2d908f8
fix(ci): give dev promote-trigger a 20-min margin over its poll budget
TheodoreSpeaks 4b9c850
fix(ci): require promote-images + deploy-trigger success explicitly f…
TheodoreSpeaks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| #!/usr/bin/env bash | ||
| # Waits for the ECS blue/green deploy triggered by a specific app image push to | ||
| # reach its traffic cutover (CodeDeploy AllowTraffic == Succeeded), then exits 0. | ||
| # | ||
| # ECR app images use a floating tag (latest/staging) with no git SHA, so the | ||
| # only durable key linking this CI push to its ECS deploy is the image DIGEST. | ||
| # Correlation: image digest -> CodePipeline execution (AppEcrImage revision) -> | ||
| # Deploy action externalExecutionId (== CodeDeploy deployment id) -> AllowTraffic. | ||
| # | ||
| # Usage: wait-for-ecs-cutover.sh <pipeline-name> <image-digest> | ||
| # Requires: awscli v2, configured credentials with codedeploy + codepipeline read. | ||
| set -euo pipefail | ||
|
|
||
| PIPELINE="${1:?pipeline name required}" | ||
| DIGEST="${2:?image digest required}" | ||
|
|
||
| POLL_INTERVAL="${POLL_INTERVAL:-15}" | ||
| # 70 min covers a prod deploy whose Deploy stage is queued behind a prior | ||
| # deploy's ~50-min termination bake before its own traffic shift begins. | ||
| OVERALL_TIMEOUT="${OVERALL_TIMEOUT:-4200}" | ||
|
|
||
| deadline=$(( $(date +%s) + OVERALL_TIMEOUT )) | ||
| remaining() { echo $(( deadline - $(date +%s) )); } | ||
| log() { echo "[wait-for-ecs-cutover] $*"; } | ||
| fail_if_expired() { | ||
| if [ "$(remaining)" -le 0 ]; then | ||
| log "ERROR: timed out after ${OVERALL_TIMEOUT}s waiting for: $1" | ||
| exit 1 | ||
| fi | ||
| } | ||
|
|
||
| log "Pipeline: $PIPELINE" | ||
| log "Target app image digest: $DIGEST" | ||
|
|
||
| # Phase A: find the pipeline execution whose ECR source revision matches our | ||
| # digest. --max-items bounds the fetch (the CLI otherwise auto-paginates the whole | ||
| # execution history); our push is the newest execution, so it's on the first page. | ||
| # The revisionId match is done server-side via JMESPath; grep isolates the UUID | ||
| # from any trailing pagination-token line in text output. | ||
| EXECUTION_ID="" | ||
| while [ -z "$EXECUTION_ID" ]; do | ||
| fail_if_expired "pipeline execution matching digest" | ||
| EXECUTION_ID=$(aws codepipeline list-pipeline-executions \ | ||
| --pipeline-name "$PIPELINE" --max-items 30 \ | ||
| --query "pipelineExecutionSummaries[?sourceRevisions[?actionName=='ECR_Source' && revisionId=='$DIGEST']].pipelineExecutionId" \ | ||
| --output text 2>/dev/null | tr '\t ' '\n\n' | grep -Em1 '^[0-9a-f-]{36}$' || true) | ||
| if [ -z "$EXECUTION_ID" ]; then | ||
| log "No matching pipeline execution yet; retry in ${POLL_INTERVAL}s (remaining $(remaining)s)" | ||
| sleep "$POLL_INTERVAL" | ||
| fi | ||
| done | ||
|
cursor[bot] marked this conversation as resolved.
|
||
| log "Matched pipeline execution: $EXECUTION_ID" | ||
|
TheodoreSpeaks marked this conversation as resolved.
|
||
|
|
||
| # Phase B: resolve the CodeDeploy deployment id from the Deploy action. This may | ||
| # stay empty for a while if the Deploy stage is queued behind a prior deploy. | ||
| DEPLOYMENT_ID="" | ||
| while [ -z "$DEPLOYMENT_ID" ] || [ "$DEPLOYMENT_ID" = "None" ]; do | ||
| fail_if_expired "CodeDeploy deployment id (Deploy stage may be queued behind a prior deploy's bake)" | ||
| status=$(aws codepipeline get-pipeline-execution \ | ||
| --pipeline-name "$PIPELINE" --pipeline-execution-id "$EXECUTION_ID" \ | ||
| --query 'pipelineExecution.status' --output text 2>/dev/null || true) | ||
| case "$status" in | ||
| Failed|Stopped|Superseded) | ||
| log "ERROR: pipeline execution $EXECUTION_ID ended in status $status before deploy" | ||
| exit 1 | ||
| ;; | ||
|
TheodoreSpeaks marked this conversation as resolved.
|
||
| esac | ||
| DEPLOYMENT_ID=$(aws codepipeline list-action-executions \ | ||
| --pipeline-name "$PIPELINE" \ | ||
| --filter pipelineExecutionId="$EXECUTION_ID" \ | ||
| --query "actionExecutionDetails[?stageName=='Deploy'].output.executionResult.externalExecutionId | [0]" \ | ||
| --output text 2>/dev/null || true) | ||
| if [ -z "$DEPLOYMENT_ID" ] || [ "$DEPLOYMENT_ID" = "None" ]; then | ||
| log "Deploy stage not started yet (pipeline status: $status); retry in ${POLL_INTERVAL}s (remaining $(remaining)s)" | ||
| sleep "$POLL_INTERVAL" | ||
| fi | ||
| done | ||
| log "CodeDeploy deployment: $DEPLOYMENT_ID" | ||
|
|
||
| # Phase C: wait for the traffic cutover (AllowTraffic lifecycle event Succeeded). | ||
| while true; do | ||
| fail_if_expired "AllowTraffic (traffic cutover)" | ||
| dstatus=$(aws deploy get-deployment --deployment-id "$DEPLOYMENT_ID" \ | ||
| --query 'deploymentInfo.status' --output text 2>/dev/null || true) | ||
| case "$dstatus" in | ||
| Failed|Stopped) | ||
| log "ERROR: CodeDeploy deployment $DEPLOYMENT_ID ended in status $dstatus; not promoting" | ||
| exit 1 | ||
| ;; | ||
| esac | ||
| target_id=$(aws deploy list-deployment-targets --deployment-id "$DEPLOYMENT_ID" \ | ||
| --query 'targetIds[0]' --output text 2>/dev/null || true) | ||
| at_status="" | ||
| if [ -n "$target_id" ] && [ "$target_id" != "None" ]; then | ||
| at_status=$(aws deploy get-deployment-target --deployment-id "$DEPLOYMENT_ID" --target-id "$target_id" \ | ||
| --query "deploymentTarget.ecsTarget.lifecycleEvents[?lifecycleEventName=='AllowTraffic'].status | [0]" \ | ||
| --output text 2>/dev/null || true) | ||
| if [ "$at_status" = "Succeeded" ]; then | ||
| log "Traffic cutover complete (AllowTraffic Succeeded) for $DEPLOYMENT_ID" | ||
|
TheodoreSpeaks marked this conversation as resolved.
Outdated
|
||
| exit 0 | ||
|
TheodoreSpeaks marked this conversation as resolved.
|
||
| fi | ||
| fi | ||
| log "Deployment $DEPLOYMENT_ID status=$dstatus AllowTraffic=${at_status:-pending}; wait ${POLL_INTERVAL}s (remaining $(remaining)s)" | ||
| sleep "$POLL_INTERVAL" | ||
| done | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.