$ show sil-org/ecs-deploy
This repository provides a single, well-tested Bash script (`ecs-deploy`) that automates blue/green deployments on AWS ECS. It fetches the current task definition, creates a new revision with an updated Docker image tag, registers it, updates the ECS service (or directly runs a task), and waits for the deployment to complete. The script handles various edge cases: image name parsing (including domain, port, repository, tag, digest, and ECR-style URLs), role assumption, rollback, and cleaning up old task definition revisions. It is packaging-ready as a Docker image and includes a GitHub Action for CI/CD pipelines. The codebase is in maintenance-only mode but remains fully functional and widely used. Its primary reuse pattern is the standalone shell script itselfβdownloadable and integrable into any deployment pipeline. A hidden gem is the `parseImageName` function, which implements robust Docker image name parsing via regex and environment variable overrides, and the test suite (`test.bats`) demonstrates a clean pattern for unit-testing Bash functions while mocking external dependencies.
The LLM identified 2 files worth highlighting for reuse:
The main executable, a Bash script that orchestrates blue/green deployments on AWS ECS. It parses complex Docker image names (including domain, port, repository, tag, digest, and ECR formats), retrieves and modifies task definitions via AWS CLI, registers new revisions, and updates services with configurable deployment parameters. It also supports running tasks directly, rollback, and cleanup of old revisions. The script is self-contained, requiring only `aws` and `jq`, and can be extracted and reused as a standalone deployment tool in any AWS environment. Its function-based structure and explicit error handling make it a solid reference for shell-based infrastructure automation.
A Bats test suite that demonstrates how to unit-test Bash functions in isolation by sourcing the script and mocking inputs (e.g., JSON task definitions for `createNewTaskDefJson` tests). It covers image parsing, argument validation, task definition JSON construction (including Fargate, multi-container, proxy configurations), and revision cleanup logic. The pattern of testing pure functions with Bats while mocking external commands (AWS CLI) is a reusable and non-obvious approach for ensuring shell script reliability in CI/CD.