Github Actions Build - Push to ECR on Multiple Folders

Viewed 530

I have below folder structure in my GitHub repository.

docker
  serverless
    dotnet
      2.1
        Dockerfile
      3.1
        Dockerfile
    python
      3.8
        Dockerfile

Now I have automate the build and push to ECR using github-actions.

Is it possible using github-actions to traverse through each folder and trigger build?

I want if changes are pushed to

  • 2.1 Dockerfile the image should always be tagged with 2.1 tag and pushed to ECR

and

  • If changes are in 3.1 Dockerfile it should always be tagged with 3.1 and pushed to ECR.

Any ideas on how to achieve this using github-actions?

1 Answers

You can use the on.<push|pull_request>.paths trigger. When paths is specified, any push that changes anything in paths will trigger the workflow. You can use this trigger in 2 workflows (one for each version):

# Trigger build for 2.1
on:
  push:
    branches:
      - 'main'
    paths:
      - docker/serverless/dotnet/2.1/Dockerfile

name: Build and push 2.1 image

jobs:
  buildpush:
    runs-on: 'ubuntu-latest'
    steps:
      - uses: actions/checkout@v2
      # build and push steps go here
# Trigger build for 3.1
on:
  push:
    branches:
     - 'main'
    paths:
     - docker/serverless/dotnet/3.1/Dockerfile

name: Build and push 3.1 image

jobs:
  buildpush:
    runs-on: 'ubuntu-latest'
    steps:
      - uses: actions/checkout@v2
      # build and push steps go here
Related