Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

[subaction/matrix] Generate multiple matrices when targets reference other targets as build contexts

Abierto
#435 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@jeliebig ya está trabajando en esto.

Desde el 1/7/2026.

  • #472 de @jeliebig — abierto

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
48/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Tranquilo
Stack tecnológico
docker, github-actions, typescript
Área
ci-cd, devops

Línea de trabajo

Comienza en la matrix subaction y sigue cómo se genera la lista de destinos actual a partir del ejemplo docker-bake.hcl. Define la finalización produciendo matrices agrupadas por dependencias, además de salidas jobs_amount y matrices que el flujo de trabajo de GitHub Actions por etapas pueda consumir sin duplicar builds dependientes.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

kind/enhancement
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?

Lenguaje dominante
TypeScript
Estrellas
302
Forks
42
Merge medio
1 d 2 h
PR fusionados (30 d)
7

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de docker/bake-action

Todos los issues de docker/bake-action

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.