1111 types : [created]
1212
1313jobs :
14- build-and-push-docker :
14+ prepare :
1515 runs-on : ubuntu-22.04
16+ outputs :
17+ version : ${{ steps.meta.outputs.version }}
18+ is_prerelease : ${{ steps.meta.outputs.is_prerelease }}
19+ platforms : ${{ steps.meta.outputs.platforms }}
20+ matrix : ${{ steps.meta.outputs.matrix }}
21+ steps :
22+ - name : Compute version and platforms
23+ id : meta
24+ run : |
25+ if [[ $GITHUB_REF == refs/tags/* ]]; then
26+ VERSION=${GITHUB_REF#refs/tags/}
27+ else
28+ VERSION=$GITHUB_REF_NAME
29+ fi
30+ if [ -z "$VERSION" ]; then
31+ VERSION="rc"
32+ fi
33+
34+ IS_PRERELEASE="${{ github.event.release.prerelease }}"
35+ PLATFORMS="linux/amd64,linux/arm64,linux/arm/v7"
36+ MATRIX='{"include":[{"platform":"linux/amd64","runner":"ubuntu-22.04"},{"platform":"linux/arm64","runner":"ubuntu-22.04-arm"},{"platform":"linux/arm/v7","runner":"ubuntu-22.04-arm"}]}'
37+
38+ echo "version=${VERSION}" >> $GITHUB_OUTPUT
39+ echo "is_prerelease=${IS_PRERELEASE}" >> $GITHUB_OUTPUT
40+ echo "platforms=${PLATFORMS}" >> $GITHUB_OUTPUT
41+ echo "matrix=${MATRIX}" >> $GITHUB_OUTPUT
42+
43+ build-and-push-docker :
44+ needs : prepare
45+ strategy :
46+ fail-fast : false
47+ matrix : ${{ fromJSON(needs.prepare.outputs.matrix) }}
48+ runs-on : ${{ matrix.runner }}
1649 steps :
1750 - name : Checkout code
1851 uses : actions/checkout@v4
1952 with :
2053 ref : ${{ github.event.inputs.branch || github.ref_name }}
2154
55+ # QEMU only needed for arm/v7 (armv7 emulated on aarch64 runner)
2256 - name : Set up QEMU
57+ if : matrix.platform == 'linux/arm/v7'
2358 uses : docker/setup-qemu-action@v3
59+ with :
60+ platforms : linux/arm/v7
2461
2562 - name : Set up Docker Buildx
2663 uses : docker/setup-buildx-action@v3
2966 uses : actions/cache@v4
3067 with :
3168 path : /tmp/.buildx-cache
32- key : ${{ runner.os }}-buildx-${{ github.sha }}
69+ key : ${{ runner.os }}-${{ matrix.platform }}- buildx-${{ github.sha }}
3370 restore-keys : |
34- ${{ runner.os }}-buildx-
71+ ${{ runner.os }}-${{ matrix.platform }}- buildx-
3572
3673 - name : Install dependencies
3774 run : npm install
@@ -40,66 +77,110 @@ jobs:
4077 id : meta
4178 uses : docker/metadata-action@v5
4279 with :
43- images : freikin /dawarich
80+ images : ${{ secrets.DOCKERHUB_USERNAME }} /dawarich
4481
4582 - name : Login to Docker Hub
4683 uses : docker/login-action@v3.1.0
4784 with :
4885 username : ${{ secrets.DOCKERHUB_USERNAME }}
4986 password : ${{ secrets.DOCKERHUB_TOKEN }}
5087
51- - name : Set Docker tags
52- id : docker_meta
88+ - name : Prepare platform pair
89+ id : platform
5390 run : |
54- # Debug output
55- echo "GITHUB_REF: $GITHUB_REF"
56- echo "GITHUB_REF_NAME: $GITHUB_REF_NAME"
91+ PAIR=$(echo "${{ matrix.platform }}" | tr '/' '-')
92+ echo "pair=${PAIR}" >> "$GITHUB_OUTPUT"
5793
58- # Extract version from GITHUB_REF or use GITHUB_REF_NAME
59- if [[ $GITHUB_REF == refs/tags/* ]]; then
60- VERSION=${GITHUB_REF#refs/tags/}
61- else
62- VERSION=$GITHUB_REF_NAME
63- fi
94+ - name : Build and push by digest
95+ id : build
96+ uses : docker/build-push-action@v5
97+ with :
98+ context : .
99+ file : ./docker/Dockerfile
100+ platforms : ${{ matrix.platform }}
101+ outputs : type=image,name=${{ secrets.DOCKERHUB_USERNAME }}/dawarich,push-by-digest=true,name-canonical=true,push=true
102+ labels : ${{ steps.meta.outputs.labels }}
103+ cache-from : type=local,src=/tmp/.buildx-cache
104+ cache-to : type=local,dest=/tmp/.buildx-cache-new,mode=max
64105
65- # Additional safety check - if VERSION is empty, use a default
66- if [ -z "$VERSION" ]; then
67- VERSION="rc"
68- fi
106+ - name : Rotate cache
107+ run : |
108+ rm -rf /tmp/.buildx-cache
109+ mv /tmp/.buildx-cache-new /tmp/.buildx-cache
110+
111+ - name : Export digest
112+ run : |
113+ mkdir -p "${{ runner.temp }}/digests"
114+ DIGEST="${{ steps.build.outputs.digest }}"
115+ touch "${{ runner.temp }}/digests/${DIGEST#sha256:}"
69116
70- echo "Using VERSION: $VERSION"
117+ - name : Upload digest
118+ uses : actions/upload-artifact@v4
119+ with :
120+ name : digest-${{ steps.platform.outputs.pair }}
121+ path : ${{ runner.temp }}/digests/*
122+ if-no-files-found : error
123+ retention-days : 1
71124
72- TAGS="freikin/dawarich:${VERSION}"
125+ merge :
126+ needs : [prepare, build-and-push-docker]
127+ runs-on : ubuntu-22.04
128+ steps :
129+ - name : Checkout code
130+ uses : actions/checkout@v4
131+ with :
132+ ref : ${{ github.event.inputs.branch || github.ref_name }}
73133
74- # Set platforms based on version type and release type
75- PLATFORMS="linux/amd64,linux/arm64,linux/arm/v8,linux/arm/v7"
134+ - name : Login to Docker Hub
135+ uses : docker/login-action@v3.1.0
136+ with :
137+ username : ${{ secrets.DOCKERHUB_USERNAME }}
138+ password : ${{ secrets.DOCKERHUB_TOKEN }}
76139
77- # Add :rc tag for pre-releases
78- if [ "${{ github.event.release.prerelease }}" = "true" ]; then
79- TAGS="${TAGS},freikin/dawarich:rc"
80- # For RC builds, only use amd64
81- PLATFORMS="linux/amd64"
82- fi
140+ - name : Set up Docker Buildx
141+ uses : docker/setup-buildx-action@v3
83142
84- # Add :latest tag only if release is not a pre-release
85- if [ "${{ github.event.release.prerelease }}" != "true" ]; then
86- TAGS="${TAGS},freikin/dawarich:latest"
87- fi
143+ - name : Download all digests
144+ uses : actions/download-artifact@v4
145+ with :
146+ path : ${{ runner.temp }}/digests
147+ pattern : digest-*
148+ merge-multiple : true
88149
89- echo "Final TAGS: $TAGS"
90- echo "PLATFORMS: $PLATFORMS"
150+ - name : Build Docker tags
151+ id : docker_tags
152+ run : |
153+ IMAGE="${{ secrets.DOCKERHUB_USERNAME }}/dawarich"
154+ VERSION="${{ needs.prepare.outputs.version }}"
155+ IS_PRERELEASE="${{ needs.prepare.outputs.is_prerelease }}"
156+
157+ TAGS="${IMAGE}:${VERSION}"
158+
159+ if [ "$IS_PRERELEASE" = "true" ]; then
160+ TAGS="${TAGS},${IMAGE}:rc"
161+ else
162+ TAGS="${TAGS},${IMAGE}:latest"
163+ fi
91164
92165 echo "tags=${TAGS}" >> $GITHUB_OUTPUT
93- echo "platforms=${PLATFORMS}" >> $GITHUB_OUTPUT
94166
95- - name : Build and push
96- uses : docker/build-push-action@v5
97- with :
98- context : .
99- file : ./docker/Dockerfile
100- push : true
101- tags : ${{ steps.docker_meta.outputs.tags }}
102- labels : ${{ steps.meta.outputs.labels }}
103- platforms : ${{ steps.docker_meta.outputs.platforms }}
104- cache-from : type=local,src=/tmp/.buildx-cache
105- cache-to : type=local,dest=/tmp/.buildx-cache
167+ - name : Create manifest list and push
168+ working-directory : ${{ runner.temp }}/digests
169+ run : |
170+ TAGS="${{ steps.docker_tags.outputs.tags }}"
171+
172+ TAG_ARGS=""
173+ IFS=',' read -ra TAG_LIST <<< "$TAGS"
174+ for TAG in "${TAG_LIST[@]}"; do
175+ TAG_ARGS="${TAG_ARGS} -t ${TAG}"
176+ done
177+
178+ SOURCES=$(printf "${{ secrets.DOCKERHUB_USERNAME }}/dawarich@sha256:%s " *)
179+
180+ docker buildx imagetools create ${TAG_ARGS} ${SOURCES}
181+
182+ - name : Inspect final image
183+ run : |
184+ TAGS="${{ steps.docker_tags.outputs.tags }}"
185+ FIRST_TAG="${TAGS%%,*}"
186+ docker buildx imagetools inspect "${FIRST_TAG}"
0 commit comments