Skip to content

Poll the ECS service deployment status in the app rollout step - #552

Open
CarsonDavis wants to merge 4 commits into
ci/faster-deploysfrom
ci/poll-deployment-status
Open

CarsonDavis wants to merge 4 commits into
ci/faster-deploysfrom
ci/poll-deployment-status

Conversation

@CarsonDavis

@CarsonDavis CarsonDavis commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Line breakdown

Category Lines added %
Config/build 72 70%
Docs 31 30%
Total 103 100%

The deploy job now waits on the ECS service deployment's own status, so a rollback fails the job on the next poll instead of after the 20-minute timeout.

What this does

  • Rollbacks fail the job right away: if ECS rolls the rollout back (any ROLLBACK_* status, such as a circuit-breaker rollback), the job fails on the next 15-second poll.
  • A stopped deployment also fails right away: the log shows Deployment failed: <STATUS> (<reason>).
  • Success no longer waits for old tasks to drain: the job passes when the deployment reaches SUCCESSFUL (new tasks healthy), which finished about a minute sooner on the last dev deploy.
  • It tracks only the deployment this update started: it records a time 30 seconds before the update (to absorb runner clock skew), then takes the newest of the service's deployments created after that time (list-service-deployments --created-at after=...), waiting up to about 60 seconds for one to appear.
  • Same-image re-runs pass: if no deployment appears (an unchanged image starts none), the job passes when the service is ACTIVE and its only active image is the new one, logging "already serving ; nothing to roll", and fails with "No new deployment appeared" otherwise.
  • A denied status check fails right away: an AccessDenied, UnauthorizedOperation or InvalidParameterException error from describe-service-deployments is printed and exits 1 instead of retrying for 20 minutes, as does a describe that returns no deployment ("Deployment not found"), while other describe errors are still retried.
  • The 20-minute timeout is only a backstop now: its message reports the last deployment status it saw.
  • The deploy role gains ecs:ListServiceDeployments and ecs:DescribeServiceDeployments: the grant covers only that environment's admin service ARN and its deployments (service-deployment/mmgis-<env>/mmgis-<env>-admin/*).

Decisions to review

  1. Done means the deployment reached SUCCESSFUL, not that only the new image is left running. A green step no longer guarantees the old-image tasks have stopped; nothing after this step depends on that today.
  2. A rollback that has only started (ROLLBACK_REQUESTED / ROLLBACK_IN_PROGRESS) fails the job immediately. The alternative was to wait for ROLLBACK_SUCCESSFUL or ROLLBACK_FAILED and report which one; failing early is faster, but you have to check the console to see whether the service ended up healthy on the old image.
  3. If no deployment appears, the step falls back to the old image check instead of failing. This lets a re-run for the same commit pass; the alternative was to always fail when no deployment appears.
  4. The IAM grant lives in the bootstrap root, which someone applies by hand, while the workflow change ships on merge. If this merges before the apply, every deploy still rolls out the new image, then fails right away on the denied call. The cluster/service/id ARN format was checked against live dev ARNs, and IAM policy simulation shows the new statement allows both calls while the current live role denies them.

Before merging / follow-ups

  • Before merging: apply the bootstrap root (infrastructure/terraform/bootstrap) for each environment. The live dev deploy role does not have ecs:ListServiceDeployments or ecs:DescribeServiceDeployments today.
  • Production gets the same behavior: deploy-production.yml calls the same reusable app-deploy.yml.
  • Verified: actionlint (no new findings), shellcheck and bash -n on the extracted step; mocked runs of the success, rollback, stopped, no-deployment-already-on-new-image (exit 0), no-deployment-not-on-new-image (exit 1), AccessDenied (immediate exit 1), missing-deployment (exit 1), and timeout paths; and read-only live checks on dev that list-service-deployments with the --created-at filter returns the latest deployment ARN (and nothing when no deployment is newer), and that describe-service-deployments returns SUCCESSFUL. The workflow itself has not run yet.

The rollout step waited for the old Express configuration to drain
(about a minute past ECS reporting SUCCESSFUL) and could not see a
rollback, so a failed rollout only surfaced at the 20-minute timeout.
Poll the deployment named by currentDeployment with
describe-service-deployments instead: exit 0 on SUCCESSFUL, exit 1 with
the status and reason on STOPPED or any ROLLBACK_* status.

Grant the deploy role ecs:DescribeServiceDeployments on its own admin
service's deployments; the new poll needs it.
@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Terraform plan preview — development

Commit 1dd8776 · run log

Plan: 2 to add, 0 to change, 2 to destroy.

Show plan

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
-/+ destroy and then create replacement

Terraform will perform the following actions:

  # module.mmgis.aws_ecs_task_definition.admin must be replaced
-/+ resource "aws_ecs_task_definition" "admin" {
      ~ arn                      = "arn:aws:ecs:us-west-2:853558080719:task-definition/mmgis-development-admin:93" -> (known after apply)
      ~ arn_without_revision     = "arn:aws:ecs:us-west-2:853558080719:task-definition/mmgis-development-admin" -> (known after apply)
      ~ container_definitions    = jsonencode(
          ~ [
              ~ {
                  ~ image            = "853558080719.dkr.ecr.us-west-2.amazonaws.com/mmgis-development:00e7e0a" -> "853558080719.dkr.ecr.us-west-2.amazonaws.com/mmgis-development:f3758bd"
                  - mountPoints      = []
                    name             = "mmgis"
                  ~ portMappings     = [
                      ~ {
                          - hostPort      = 8888
                            # (2 unchanged attributes hidden)
                        },
                    ]
                  - systemControls   = []
                  - volumesFrom      = []
                    # (4 unchanged attributes hidden)
                },
            ] # forces replacement
        )
      ~ enable_fault_injection   = false -> (known after apply)
      ~ id                       = "mmgis-development-admin" -> (known after apply)
      ~ revision                 = 93 -> (known after apply)
      - tags                     = {} -> null
        # (13 unchanged attributes hidden)

        # (1 unchanged block hidden)
    }

  # module.mmgis.aws_ecs_task_definition.publish must be replaced
-/+ resource "aws_ecs_task_definition" "publish" {
      ~ arn                      = "arn:aws:ecs:us-west-2:853558080719:task-definition/mmgis-development-publish:93" -> (known after apply)
      ~ arn_without_revision     = "arn:aws:ecs:us-west-2:853558080719:task-definition/mmgis-development-publish" -> (known after apply)
      ~ container_definitions    = jsonencode(
          ~ [
              ~ {
                  ~ image            = "853558080719.dkr.ecr.us-west-2.amazonaws.com/mmgis-development:00e7e0a" -> "853558080719.dkr.ecr.us-west-2.amazonaws.com/mmgis-development:f3758bd"
                  - mountPoints      = []
                    name             = "mmgis"
                  - portMappings     = []
                  - systemControls   = []
                  - volumesFrom      = []
                    # (5 unchanged attributes hidden)
                },
            ] # forces replacement
        )
      ~ enable_fault_injection   = false -> (known after apply)
      ~ id                       = "mmgis-development-publish" -> (known after apply)
      ~ revision                 = 93 -> (known after apply)
      - tags                     = {} -> null
        # (13 unchanged attributes hidden)

        # (1 unchanged block hidden)
    }

Plan: 2 to add, 0 to change, 2 to destroy.

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Terraform plan preview — production

Commit 1dd8776 · run log

Plan: 2 to add, 0 to change, 2 to destroy.

Show plan

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
-/+ destroy and then create replacement

Terraform will perform the following actions:

  # module.mmgis.aws_ecs_task_definition.admin must be replaced
-/+ resource "aws_ecs_task_definition" "admin" {
      ~ arn                      = "arn:aws:ecs:us-west-2:853558080719:task-definition/mmgis-production-admin:3" -> (known after apply)
      ~ arn_without_revision     = "arn:aws:ecs:us-west-2:853558080719:task-definition/mmgis-production-admin" -> (known after apply)
      ~ container_definitions    = jsonencode(
          ~ [
              ~ {
                  ~ image            = "853558080719.dkr.ecr.us-west-2.amazonaws.com/mmgis-production:78929ce" -> "853558080719.dkr.ecr.us-west-2.amazonaws.com/mmgis-production:8f0f450"
                  - mountPoints      = []
                    name             = "mmgis"
                  ~ portMappings     = [
                      ~ {
                          - hostPort      = 8888
                            # (2 unchanged attributes hidden)
                        },
                    ]
                  - systemControls   = []
                  - volumesFrom      = []
                    # (4 unchanged attributes hidden)
                },
            ] # forces replacement
        )
      ~ enable_fault_injection   = false -> (known after apply)
      ~ id                       = "mmgis-production-admin" -> (known after apply)
      ~ revision                 = 3 -> (known after apply)
      - tags                     = {} -> null
        # (13 unchanged attributes hidden)

        # (1 unchanged block hidden)
    }

  # module.mmgis.aws_ecs_task_definition.publish must be replaced
-/+ resource "aws_ecs_task_definition" "publish" {
      ~ arn                      = "arn:aws:ecs:us-west-2:853558080719:task-definition/mmgis-production-publish:3" -> (known after apply)
      ~ arn_without_revision     = "arn:aws:ecs:us-west-2:853558080719:task-definition/mmgis-production-publish" -> (known after apply)
      ~ container_definitions    = jsonencode(
          ~ [
              ~ {
                  ~ image            = "853558080719.dkr.ecr.us-west-2.amazonaws.com/mmgis-production:78929ce" -> "853558080719.dkr.ecr.us-west-2.amazonaws.com/mmgis-production:8f0f450"
                  - mountPoints      = []
                    name             = "mmgis"
                  - portMappings     = []
                  - systemControls   = []
                  - volumesFrom      = []
                    # (5 unchanged attributes hidden)
                },
            ] # forces replacement
        )
      ~ enable_fault_injection   = false -> (known after apply)
      ~ id                       = "mmgis-production-publish" -> (known after apply)
      ~ revision                 = 3 -> (known after apply)
      - tags                     = {} -> null
        # (13 unchanged attributes hidden)

        # (1 unchanged block hidden)
    }

Plan: 2 to add, 0 to change, 2 to destroy.

currentDeployment is null in the update response and the deployment is
created a few seconds later, so find it with list-service-deployments
filtered to deployments created after the update was sent. If none
appears (an unchanged image starts no deployment), pass only when the
service already runs just the new image.

Fail immediately on AccessDenied instead of retrying for 20 minutes,
and on a describe that returns no deployment. Grant the deploy role
ecs:ListServiceDeployments and list the service ARN as a resource too;
note both permissions in the deploy role facts.
An invalid deployment ARN never clears on retry. Taking T0 30 s in the past tolerates runner clock skew; the per-environment concurrency group keeps other deployments out of that window.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant