While AWS does have components to achieve continuous deployment with CodeBuild/CodePipeline and ECS (and blue/green deployments) or EKS (with deployment via Lambda functions), these solutions are often complex to set up and require a lot of (or at least more than desired) resources, which, of course have an impact on the cost. Especially in the deployment phase, it gets more difficult to get everything up and running. We wanted something simpler & faster, and maybe this solution might help other people as well. To give you an idea: all the containers run on one single t2.micro EC2 isntance, which is almost for free.
It goes without saying this is not a suitable setup for production, but quite handy for the staging environment. The deployment process
The first step is easy: to build the containers, we use CodePipeline in combination with CodeBuild, and we skip the deployment step in the pipeline. It is only used for getting a trigger from the repo to launch the CodeBuild project. The CodeBuild project builds the service or application, the container, and pushes the container to the ECR and updates the tags. If your code is in CodeCommit, and container is stored in ECR, this is literally only a few clicks of work.
As mentioned before, (in our opinion) the complexity lies in the second step with the automatic deployment of the container(s) to a container host when we use standard AWS services/resources. We spend some time looking for a solution to do this "push", as is this is the most logical thing to to do. But eventually, we came up with a solution that was the opposite: a "pull" mechanism. Watchtower
In this quest for easy automatic deployment of the latest version of docker containers, we stumbled upon a component called Watchtower: https://containrrr.dev/watchtower/
In essence, watchtower is running in docker. It's able to poll the docker repository (or event multiple repo's) of your (other installed) containers in the same docker host, at a configurable interval. When a new version of a container is detected, watchtower will stop the container, pull the latest images & restart. In other words, if we tag the container of our dev branch build, and use this tag with Watchtower, he latest version will be automatically deployed. The downtime of this is equal to the stop and the start of a container, which is a matter of one or two seconds (depending on the container).
A basic docker-compose setup for Watchtower is as simple as this: