Skip to content

Commit 0cadff8

Browse files
nicola-lunghiNicola Lunghishenxianpeng
authored
feat: use targets from docker-bake.hcl (#103)
* CI: use targets from docker-bake.hcl * fix: Update CI.yml to fix syntax error * fix: Update CI.yml to fix empty input * fixup! fix: Update CI.yml to fix empty input * fix: add condition to login step * fix: update type to image to avoid push=true see: https://docs.docker.com/reference/cli/docker/buildx/build/#output --------- Co-authored-by: Nicola Lunghi <nicola.lunghi@fortaegis.com> Co-authored-by: Xianpeng Shen <xianpeng.shen@gmail.com>
1 parent f67f8ee commit 0cadff8

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

.github/workflows/CI.yml

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,26 @@ concurrency:
2020
cancel-in-progress: true
2121

2222
jobs:
23+
extract-targets:
24+
runs-on: ubuntu-latest
25+
outputs:
26+
targets: ${{ steps.get-targets.outputs.targets }}
27+
steps:
28+
- uses: actions/checkout@v4
29+
- name: Extract targets as JSON array
30+
uses: dcarbone/install-jq-action@v2
31+
- name: Get targets from bake file
32+
id: get-targets
33+
run: |
34+
TARGETS=$(docker buildx bake --file docker-bake.hcl --print | jq -c '[.target | keys[] | select(. != "default")]')
35+
echo "targets=$TARGETS" >> "$GITHUB_OUTPUT"
36+
2337
build:
38+
needs: extract-targets
39+
runs-on: ubuntu-latest
2440
strategy:
2541
matrix:
26-
target: [ "all", "20", "20-alpine", "19", "19-alpine", "18", "18-alpine", "17", "17-alpine", "16", "16-alpine", "15", "14", "13", "12", "11", "10", "9", "8", "7"]
27-
runs-on: ubuntu-latest
42+
target: ${{ fromJson(needs.extract-targets.outputs.targets) }}
2843
steps:
2944
- uses: actions/checkout@v4
3045

@@ -34,17 +49,18 @@ jobs:
3449
- name: Check formatting
3550
run: make install-deps && make lint
3651

37-
- name: Login container registries
38-
run: |
39-
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
40-
echo '${{ secrets.DOCKER_PASSWORD }}' | docker login -u '${{ secrets.DOCKER_USERNAME }}' --password-stdin
41-
4252
- name: Check buildx bake
4353
run: docker buildx bake --file docker-bake.hcl --print
4454

4555
- name: Build image for tag ${{ matrix.target }}
4656
run: docker buildx bake --file docker-bake.hcl ${{ matrix.target }}
4757

58+
- name: Login container registries
59+
if: github.ref == 'refs/heads/master' && github.event_name == 'workflow_dispatch'
60+
run: |
61+
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
62+
echo '${{ secrets.DOCKER_PASSWORD }}' | docker login -u '${{ secrets.DOCKER_USERNAME }}' --password-stdin
63+
4864
- name: Publish image for tag ${{ matrix.target }}
4965
if: github.ref == 'refs/heads/master' && github.event_name == 'workflow_dispatch'
5066
run: docker buildx bake --file docker-bake.hcl ${{ matrix.target }} --push

docker-bake.hcl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ target "all" {
4545
"${GITHUB_REPO}:all"
4646
]
4747
platforms = ["linux/amd64", "linux/arm64"]
48-
output = ["type=registry"]
48+
output = ["type=image"]
4949
}
5050

5151
target "clang-tools" {
@@ -65,7 +65,7 @@ target "clang-tools" {
6565
"${GITHUB_REPO}:${tgt}"
6666
]
6767
platforms = ["linux/amd64", "linux/arm64"]
68-
output = ["type=registry"]
68+
output = ["type=image"]
6969
}
7070

7171
target "clang-tools" {
@@ -85,7 +85,7 @@ target "clang-tools" {
8585
"${GITHUB_REPO}:${tgt}"
8686
]
8787
platforms = ["linux/amd64", "linux/arm64"]
88-
output = ["type=registry"]
88+
output = ["type=image"]
8989
}
9090

9191
target "clang-tools" {
@@ -105,7 +105,7 @@ target "clang-tools" {
105105
"${GITHUB_REPO}:${tgt}"
106106
]
107107
platforms = ["linux/amd64", "linux/arm64"]
108-
output = ["type=registry"]
108+
output = ["type=image"]
109109
}
110110

111111
target "clang-tools" {
@@ -124,7 +124,7 @@ target "clang-tools" {
124124
"${GITHUB_REPO}:${tgt}"
125125
]
126126
platforms = ["linux/amd64", "linux/arm64"]
127-
output = ["type=registry"]
127+
output = ["type=image"]
128128
}
129129

130130
target "clang-tools" {
@@ -143,7 +143,7 @@ target "clang-tools" {
143143
"${GITHUB_REPO}:${tgt}"
144144
]
145145
platforms = ["linux/amd64", "linux/arm64"]
146-
output = ["type=registry"]
146+
output = ["type=image"]
147147
}
148148

149149
target "clang-tools" {
@@ -162,7 +162,7 @@ target "clang-tools" {
162162
"${GITHUB_REPO}:${tgt}"
163163
]
164164
platforms = ["linux/amd64", "linux/arm64"]
165-
output = ["type=registry"]
165+
output = ["type=image"]
166166
}
167167

168168
target "clang-tools" {
@@ -180,6 +180,6 @@ target "clang-tools" {
180180
"${DOCKER_REPO}:${tgt}",
181181
"${GITHUB_REPO}:${tgt}"
182182
]
183-
platforms = ["linux/amd64", "linux/arm64"]
184-
output = ["type=registry"]
183+
platforms = ["linux/amd64"]
184+
output = ["type=image"]
185185
}

0 commit comments

Comments
 (0)