@@ -3,85 +3,133 @@ name: Docker
33on :
44 push :
55 branches :
6- - master # Will be `dev`
6+ - master
77 tags :
8- - v* # Publish `v1.2.3` tags as releases.
9-
10- pull_request : # Run tests for any PRs.
11-
8+ - v*
129
1310jobs :
14- test : # See also https://docs.docker.com/docker-hub/builds/automated-testing/
11+ prepare :
1512 runs-on : ubuntu-latest
16-
13+ outputs :
14+ matrix : ${{ steps.filter.outputs.matrix }}
15+ targets : ${{ steps.targets.outputs.targets }}
1716 steps :
18- - uses : actions/checkout@v2
19-
20- - name : Run tests
17+ -
18+ name : Checkout
19+ uses : actions/checkout@v4
20+ -
21+ name : Generate matrix
22+ id : generate
23+ uses : docker/bake-action/subaction/matrix@v6
24+ with :
25+ fields : target,platforms
26+ -
27+ name : Filter matrix
28+ id : filter
29+ run : |
30+ matrix=$(echo '${{ steps.generate.outputs.matrix }}' | \
31+ jq -c '[.[] | select(.target | IN("novnc", "websockify", "dev") | not)]')
32+ echo "matrix=$matrix" >> $GITHUB_OUTPUT
33+ -
34+ name : Extract unique targets
35+ id : targets
2136 run : |
22- if [ -f docker-compose.test.yml ]; then
23- docker-compose --file docker-compose.test.yml build
24- docker-compose --file docker-compose.test.yml run sut
25- else
26- docker build --build-arg OS="debian:trixie-slim" --file Dockerfile .
27- fi
37+ targets=$(echo '${{ steps.filter.outputs.matrix }}' | \
38+ jq -c '[.[].target] | unique')
39+ echo "targets=$targets" >> $GITHUB_OUTPUT
2840
2941 build :
30- runs-on : ubuntu-latest
31-
32- needs : test # Ensure test job passes before pushing image.
33- if : github.event_name == 'push'
34- permissions :
35- contents : read
36- packages : write
37-
42+ runs-on : ${{ startsWith(matrix.platforms, 'linux/arm') && 'ubuntu-24.04-arm' || 'ubuntu-latest' }}
43+ needs :
44+ - prepare
3845 strategy :
46+ fail-fast : false
3947 matrix :
40- os : [bookworm-slim, bookworm, trixie, trixie-slim]
41- include :
42- - os : bookworm-slim
43- image : debian:bookworm-slim
44- - os : bookworm
45- image : debian:bookworm
46- - os : trixie-slim
47- image : debian:trixie-slim
48- - os : trixie
49- image : debian:trixie
50-
48+ include : ${{ fromJson(needs.prepare.outputs.matrix) }}
5149 steps :
52- - name : Set up QEMU
53- uses : docker/setup-qemu-action@v2
54-
55- - name : Set up Docker Buildx
56- uses : docker/setup-buildx-action@v2
57-
58- - name : Dockerhub Login
59- uses : docker/login-action@v1.10.0
50+ -
51+ name : Checkout
52+ uses : actions/checkout@v4
53+ -
54+ name : Set up Docker Buildx
55+ uses : docker/setup-buildx-action@v3
56+ -
57+ name : Dockerhub Login
58+ uses : docker/login-action@v3
6059 with :
6160 username : max06net
6261 password : ${{ secrets.DOCKERHUB_TOKEN }}
62+ -
63+ name : Build and push by digest
64+ id : build
65+ uses : docker/bake-action@v6
66+ with :
67+ targets : ${{ matrix.target }}
68+ set : |
69+ ${{ matrix.target }}.platform=${{ matrix.platforms }}
70+ ${{ matrix.target }}.tags=docker.io/max06net/base-gui
71+ ${{ matrix.target }}.output=type=image,push-by-digest=true,name-canonical=true,push=true
72+ provenance : false
73+ -
74+ name : Export digest
75+ run : |
76+ mkdir -p ${{ runner.temp }}/digests
77+ digest=$(echo '${{ steps.build.outputs.metadata }}' | jq -r '."${{ matrix.target }}"."containerimage.digest"')
78+ touch "${{ runner.temp }}/digests/${digest#sha256:}"
79+ -
80+ name : Upload digest
81+ uses : actions/upload-artifact@v4
82+ with :
83+ name : digests-${{ matrix.target }}-${{ startsWith(matrix.platforms, 'linux/arm') && 'arm64' || 'amd64' }}
84+ path : ${{ runner.temp }}/digests/*
85+ if-no-files-found : error
86+ retention-days : 1
6387
64- - name : Docker meta
88+ merge :
89+ runs-on : ubuntu-latest
90+ needs :
91+ - prepare
92+ - build
93+ strategy :
94+ fail-fast : false
95+ matrix :
96+ target : ${{ fromJson(needs.prepare.outputs.targets) }}
97+ steps :
98+ -
99+ name : Download digests
100+ uses : actions/download-artifact@v4
101+ with :
102+ path : ${{ runner.temp }}/digests
103+ pattern : digests-${{ matrix.target }}-*
104+ merge-multiple : true
105+ -
106+ name : Dockerhub Login
107+ uses : docker/login-action@v3
108+ with :
109+ username : max06net
110+ password : ${{ secrets.DOCKERHUB_TOKEN }}
111+ -
112+ name : Set up Docker Buildx
113+ uses : docker/setup-buildx-action@v3
114+ -
115+ name : Docker meta
65116 id : meta
66- uses : docker/metadata-action@v3
117+ uses : docker/metadata-action@v5
67118 with :
68- images : max06net/base-gui
119+ images : docker.io/ max06net/base-gui
69120 tags : |
70- type=semver,pattern={{version}}-${{ matrix.os }}
71- type=semver,pattern={{major}}.{{minor}}-${{ matrix.os }}
72- type=semver,pattern={{major}}-${{ matrix.os }}
73- type=edge,branch=master,suffix=-${{ matrix.os }}
74-
75- - name : Build and push Docker images
76- uses : docker/build-push-action@v4
77- with :
78- build-args : |
79- OS=${{ !matrix.image && matrix.os || matrix.image }}
80- # platforms: # optional
81- pull : true
82- push : true
83- tags : ${{ steps.meta.outputs.tags }}
84- labels : ${{ steps.meta.outputs.labels }}
85- platforms : linux/amd64,linux/arm64
86- # env:
87- # OS: ${{ matrix.os }}
121+ type=semver,pattern={{version}},suffix=-${{ matrix.target }}
122+ type=semver,pattern={{major}}.{{minor}},suffix=-${{ matrix.target }}
123+ type=semver,pattern={{major}},suffix=-${{ matrix.target }}
124+ type=edge,branch=master,suffix=-${{ matrix.target }}
125+ -
126+ name : Create manifest list and push
127+ working-directory : ${{ runner.temp }}/digests
128+ run : |
129+ docker buildx imagetools create \
130+ $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
131+ $(printf 'docker.io/max06net/base-gui@sha256:%s ' *)
132+ -
133+ name : Inspect image
134+ run : |
135+ docker buildx imagetools inspect docker.io/max06net/base-gui:${{ steps.meta.outputs.version }}
0 commit comments