[subaction/matrix] Generate multiple matrices when targets reference other targets as build contexts
维护者通常 1 天内回复
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 48/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- docker, github-actions, typescript
调研方向
从 matrix subaction 入手,追踪当前目标列表如何从 docker-bake.hcl 示例生成。通过生成按依赖关系分组的矩阵,以及 staged GitHub Actions workflow 可以使用的 jobs_amount 和 matrices 输出(且不会重复构建依赖项)来定义完成标准。
由索引模型根据 Issue 内容生成。
描述
Description
We'd like to use the matrix subaction to generate multiple matrices, since we have a couple of targets that depend on other targets and would like to avoid building the same target multiple times.
As an example, consider the following docker-bake.hcl (containing targets with Dockerfiles that can't be easily merged into a multi-stage Dockerfile):
group "default" {
targets = ["apps", "special-app"]
}
target "base" {
context = "basedir"
tags = ["base:latest"]
}
target "apps" {
name = "app_${version}"
context = "appdir/${version}"
matrix = {
version = ["1-0-0", "2-0-0", "2-1-5"]
}
tags = ["app:${version}"]
contexts = {
base = "target:base"
}
}
target "special-app" {
context = "appdir/special"
tags = ["special-app:latest"]
contexts = {
app = "target:app_2-0-0"
}
}
Now we commit and push a change to basedir/Dockerfile, which triggers a GitHub workflow that builds these targets on multiple runners using the matrix subaction and pushes them to our registry.
Currently the subaction generates the following matrix:
[{"target": "base"}, {"target": "app_1-0-0"}, {"target": "app_2-0-0"}, {"target": "app_2-1-5"}, {"target": "special-app"}]
This generates 5 workflow jobs running in parallel, but most of them spend time building dependent targets first, which other jobs are already building. This results in a lot of duplicate work which could be avoided.
Ideally the subaction would generate multiple matrices like this:
[
[{"target": "base"}],
[{"target": "app_1-0-0"}, {"target": "app_2-0-0"}, {"target": "app_2-1-5"}],
[{"target": "special-app"}]
]
This way we could define multiple jobs that depend on the previous ones and supply them with one matrix each.
Snippet of an example workflow using multiple matrices
jobs:
generate:
runs-on: ubuntu-latest
outputs:
jobs_amount: ${{ steps.generate.outputs.jobs_amount }}
matrices: ${{ steps.generate.outputs.matrices }}
steps:
- uses: actions/checkout@v6
- id: generate
uses: docker/bake-action/subaction/matrix@multiple-matrices
stage_1:
needs:
- generate
if: ${{ fromJson(needs.generate.outputs.jobs_amount) >= 1 }}
strategy:
matrix:
include: ${{ toJson(fromJson(needs.generate.outputs.matrices)[0]) }}
steps:
# ...
stage_2:
needs:
- generate
- stage_1
if: ${{ fromJson(needs.generate.outputs.jobs_amount) >= 2 }}
strategy:
matrix:
include: ${{ toJson(fromJson(needs.generate.outputs.matrices)[1]) }}
steps:
# ...
stage_3:
needs:
- generate
- stage_2
if: ${{ fromJson(needs.generate.outputs.jobs_amount) >= 3 }}
strategy:
matrix:
include: ${{ toJson(fromJson(needs.generate.outputs.matrices)[2]) }}
steps:
# ...
We imagine that this usecase is common enough to be supported here and would like to contribute that feature, since we already made it for our own workflows.
Would you be interested in this feature?
- 主要语言
- TypeScript
- 星标
- 302
- 派生
- 42
- 平均合并
- 1 天 2 小时
- 30 天内合并 PR
- 7
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
docker/bake-action 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 48/100
docker/bake-action#488 · 3 条评论 ·
维护者通常 1 天内回复
-
kind/enhancement status/triage
难度 4/5 3-5 天 新手友好度 52/100
docker/bake-action#458 · 1 条评论 ·
维护者通常 1 天内回复
-
status/triage
难度 3/5 1-2 天 新手友好度 35/100
docker/bake-action#322 · 1 条评论 ·
维护者通常 1 天内回复
-
status/needs-more-info
难度 4/5 3-5 天 新手友好度 25/100
docker/bake-action#312 · 2 条评论 ·
维护者通常 1 天内回复
-
status/needs-investigation
难度 2/5 1-3 小时 新手友好度 35/100
docker/bake-action#306 · 2 条评论 ·
维护者通常 1 天内回复
查看 docker/bake-action 的全部 Issue
相似的 Issue
-
bug low priority
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
enhancement good first issue
难度 2/5 1-3 小时 新手友好度 66/100
laaielichter/Godotwright#81 ·
维护者通常 1 天内回复
-
gebied: infra
难度 2/5 1-3 小时 新手友好度 72/100
VincentSmedinga/sc-heerenveen-fansite#538 ·
维护者通常 1 天内回复
-
CI grants a token it does not need, never cancels superseded runs, and cannot fail on lint warnings未关闭good first issue help wanted type:infrastructure type:security
难度 2/5 1-3 小时 新手友好度 70/100
Open-Glassbeetle/glassbeetle#247 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 72/100
维护者通常 1 天内回复