Run migrations as an explicit ECS task before deploy - #110
Merged
saqibmanan merged 2 commits intoAug 18, 2026
Conversation
Bumps aws-actions/amazon-ecs-deploy-task-definition v1 -> v2 (purely additive per its changelog) to use its built-in run-task support: runs a standalone task on the new task definition, waits for it to stop, and fails the whole action on a non-zero container exit -- before the service update ever happens. Network config (subnets, security groups, public-IP assignment) is read from the currently running service via describe-services rather than hardcoded, so the migration task always runs in the same network context as the app.
mkdir/chmod/touch on api/migrations existed only to let the runtime makemigrations step (removed earlier) write new migration files. migrate doesn't need to write to that directory, just read committed migrations, so this block has been dead weight since makemigrations was dropped.
3 tasks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Phase 3 of the ECS CD-pipeline plan. Stacked on #109 — merge #108 → #109 → this, in order.
Migrations previously only ran inside
docker-entrypoint.shon every container boot — no distinct pass/fail signal in the deploy pipeline itself, and (per the plan) a theoretical race under Fargate's rolling deployment window.deploy-to-ecs.yml: bumpedaws-actions/amazon-ecs-deploy-task-definitionv1 → v2 (checked its changelog — purely additive feature releases since v1, no breaking changes to the inputs already in use) to use its built-inrun-tasksupport. Its source confirms the standalone task is awaited and its exit code checked before the service update ever runs — a failed migration now fails the whole deploy job loudly, before any new code ships, instead of being buried in container boot logs nobody's watching.aws ecs describe-services→ subnets/security groups/public-IP assignment) rather than hardcoding it or adding new secrets — the migration task always runs in the exact same network context as the real app.docker-entrypoint.sh: dropped the now-deadmkdir/chmod/touchmigrations-directory scaffolding (only ever needed to support the runtimemakemigrationsstep removed in Fix health-check false-green and unsafe runtime migrations #108).One deviation from my own plan, worth flagging explicitly: the plan originally said to also remove
migrate --noinputfrom the entrypoint. I didn't — this same Dockerfile/entrypoint is whatdocker-compose.yml'sbackendservice uses for local dev, and removing it would have silently broken migrations ondocker compose up. Left it in as a no-op safety net (migrate is idempotent, so re-running it after the ECS one-off task already applied everything is harmless) with a comment explaining why. The value of the explicit pipeline step — a loud, blocking, pre-deploy failure — doesn't require the entrypoint call to be gone.Test plan
amazon-ecs-deploy-task-definition's CHANGELOG.md and compiledindex.jssource directly (viagh api) to confirmrun-task/wait-for-task-stoppedwaits for the task and calls a realtasksExitCode()check that throws (failing the job) on non-zero exit, and that this happens strictly beforeupdateEcsService()actionlintclean on every line this PR touches (pre-existing findings on untouched lines: outdatedcheckout@v3/configure-aws-credentials@v1, unrelatedSC2086quoting)bash -n+shellcheckclean on the entrypoint diffdescribe-servicesnetwork-config lookup andrun-taskcall against real AWS — no credentials in my environment. This is exactly what Phase 6's staged rollout (build-only first, then one supervised real deploy) is for.