【问题标题】:Github Actions Build - Push to ECR on Multiple FoldersGithub Actions Build - 在多个文件夹上推送到 ECR
【发布时间】:2021-07-10 10:32:58
【问题描述】:

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

docker
  serverless
    dotnet
      2.1
        Dockerfile
      3.1
        Dockerfile
    python
      3.8
        Dockerfile

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

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

如果更改被推送到我想要

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

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

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

【问题讨论】:

  • 我发布了一个答案,描述了如何根据路径触发工作流。这是否足够,或者您是否需要一些关于如何构建 Docker 镜像并将其推送到容器注册表的指导?
  • @jidicula repo 是 monorepo,所以下面的 CI 步骤可以在一个工作流文件中?
  • 您可以在一个存储库中拥有多个工作流。将操作拆分为工作流的决定很大程度上取决于它们的触发方式 - 因为您想要的结果取决于 2 个不同的触发器,所以您需要 2 个工作流文件。

标签: python .net docker automation github-actions


【解决方案1】:

您可以使用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
# 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

【讨论】:

    猜你喜欢
    • 2021-05-21
    • 2016-05-12
    • 2021-10-18
    • 1970-01-01
    • 2021-12-20
    • 2020-12-18
    • 1970-01-01
    • 2020-12-08
    • 2020-04-21
    相关资源
    最近更新 更多