Github Actions Build - 在多个文件夹上推送到 ECR

Azi*_*aib 7 .net python automation docker github-actions

我的 GitHub 存储库中有以下文件夹结构。

docker
  serverless
    dotnet
      2.1
        Dockerfile
      3.1
        Dockerfile
    python
      3.8
        Dockerfile
Run Code Online (Sandbox Code Playgroud)

现在我已经使用 github-actions 自动构建并推送到 ECR。

是否可以使用 github-actions 遍历每个文件夹并触发构建?

我想如果更改被推送到

  • 2.1Dockerfile图像应始终使用 2.1 标记并推送到 ECR

  • 如果更改在 3.1 中Dockerfile,则应始终标记为 3.1 并推送到 ECR。

关于如何使用 github-actions 实现这一目标的任何想法?

jid*_*ula 0

您可以使用on.<push|pull_request>.paths触发器。指定后paths,任何更改任何内容的推送paths都将触发工作流程。您可以在 2 个工作流程中使用此触发器(每个版本一个):

# 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
Run Code Online (Sandbox Code Playgroud)
# 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
Run Code Online (Sandbox Code Playgroud)