CI/CD

Github Project: AWS CI/CD using Docker

This project is for developers using docker containers in AWS as ECS Tasks who want to build docker images automatically by AWS CodeBuild when a change is committed to a branch.

Building and pushing images can be time consuming and the more builds and pushes, the more mistakes. A CI/CD for docker containers requires the pipeline to build, tag, and push images to the repository. This saves time and keeps source in a central location with the other repositories. This article assume you have knowledge about how to manually build docker images. This article will look at the configuration of Github Actions, CodePipeline, and CodeBuild.

GitHub

The pipeline is triggered by Github Webhooks. Webhooks allow for configuration for the trigger for example below runs the pipeline based an event.

Below is an important Actions setting to allow read access to the repositories.

CodePipline

This developer tool creates pipelines that orchestrate the integration and deployment. View the screenshot below to notice that this pipeline is named docker-pipline using pipeline V2. It has two stages, Source and Build. There are other stages that can appear in a pipeline however we will focus on the CI/CD with Docker capabilities in this article.

CodeBuild

CodeBuild was the AWS service chosen to perform the build stage of the deployment. Other applications such as Jenkins could be used for this stage however CodeBuild was easy to configure and worked well with the Dockerfile script. It only takes a few parameters to get the build stage running by selecting a primary source. GitHub was chosen however other public repositories can be selected along with multiple sources.

Codebuild has two important files:

  • Dockerfile
  • buildspec.yml

The Dockerfile is the file used to create a Docker image. It specifies information like any base images, operating systems, or applications to install in the new image.

The buildspec.yml contains the environmental variables to identify the repository and AWS account, and roles with the proper permissions to read from the repositories, create files for the Docker images, login, and push the resulting zip file up to AWS. This was specified by default to be an S3 bucket however this can be changed to another repository or target source.

The system diagram indicates that the final stage involves pushing the images up to the AWS ECR.