In this visual post, We will discuss the basic steps required to set up a continuous integration workflow of the Github repository to Amazon ECS using actions.

1 ) Create repository on Github

Create Github Repository

2 ) Click on Actions Tab

Action Tab Github

3 ) Click on “Setup Workflow”

Set up workflow for AWS ECS

4 ) Github will automatically prompt for creating an aws.yml file

5 ) Configure the aws.yml file for the intended workflow. In our case, It is to be able to push a new image to Elastic Container registry on every push.

a) Specifying when the workflow should be triggered

on:
  push:
    branches:
      - release
      - master

This configures the workflow to be triggered when code is pushed to either release or master branch.

b) Specifying the job that needs to run

jobs:
  deploy:
    name: Deploy
    runs-on: ubuntu-latest

c) Specifying individual steps that needs to be run as part of the workflow

i) Checkout the latest code

   steps:
    - name: Checkout
      uses: actions/[email protected]

ii) Configure AWS account and login onto ECR account

- name: Configure AWS credentials
      uses: aws-actions/[email protected]
      with:
        aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
        aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        aws-region: us-east-2

    - name: Login to Amazon ECR
      id: login-ecr
      uses: aws-actions/[email protected]

We need to configure aws access keys onto github secrets for the workflow to be able to pull from

For our case, We need to get Amazon User Id and Secret Key by creating an Amazon IAM user. How to get amazon IAM userid and secret key is documented in a post here.

 aws-region: ap-south-1

iii) Create a repository on ECR on Amazon AWS

iv) We need to update the name of the repository in the code for aws.yml

  - name: Build, tag, and push image to Amazon ECR
      id: build-image
      env:
        ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
        ECR_REPOSITORY: <<NAME_OF_THE_REPOSITORY_GOES_HERE>>
        IMAGE_TAG: <<NAME_OF_THE_IMAGE_GOES_HERE>>