You have Github repository with application code and a Dockerfile to build the code image. You can use Github Actions to create workflow. This workflow will get triggered on any commit to the repository and will build the docker image and push it to AWS Elastic Container Registry.
1. Create and keep ready AWS ECR repository to upload the image. You can login to AWS console and create AWS ECR repository. In the below example I have created repository by name “test-hello-world“. Note down the AccountID, Region and Repository name from the URI, we will need later.
2. Now create a repository in Github for your application. Add your app code and Dockerfile to build the image. I have provide sample golang app code and Dockerfile. You can download it from – https://github.com/subudear/helloworld
“hello-world.go” code. It just shows “Hello World” for index page and shows “Service Health Check : Pass” for /health path.
Github Action workflow file dockerimage.yaml content:
3. You have to create secrets in repository so that the workflow can access them during the execution of job.
Create following secrets in repository-
4. Once Secrets are created, make any change to the app code and commit it. It will trigger the workflow. It will build and push the docker image to AWS ECR.