2323 runs-on : ubuntu-latest
2424 outputs :
2525 images : ${{ steps.collect.outputs.images }}
26+ tags : ${{ steps.collect.outputs.tags }}
2627 do_build : ${{ steps.collect.outputs.do_build }}
2728 steps :
2829 - name : Checkout repository
@@ -41,95 +42,116 @@ jobs:
4142 done > latest_manifests.txt
4243 images=$(while IFS= read -r line; do
4344 if ! grep "$line" manifests.txt >/dev/null 2>&1; then
44- echo $line | awk -F' ' '{printf "{\"platform\": \"%s\", \"tag\": \"%s\"}\n", $1,$2}'
45+ echo $line | awk -F' ' '{printf "{\"platform\": \"linux/ %s\", \"tag\": \"%s\"}\n", $1,$2}'
4546 fi
46- done < "latest_manifests.txt" | sed 's/amd64/ubuntu-24.04/g;s/ arm64/ ubuntu-24.04-arm/g ' | jq -cs '.')
47+ done < "latest_manifests.txt" | jq -cs '.[] | (select(.platform == "linux/ arm64" ) | .runner = " ubuntu-24.04-arm"), (select(.platform == "linux/amd64" ) | .runner = "ubuntu-latest") ' | jq -cs '.' )
4748 mv latest_manifests.txt manifests.txt
4849 echo $images | jq
4950 echo images="$images" >> $GITHUB_OUTPUT
5051 ([[ "$images" != "[]" ]] && echo do_build=true || echo do_build=false ) >> $GITHUB_OUTPUT
52+ tags=$(echo $images | jq '.[].tag' | sort | uniq | jq -cs '. | map({tag: .})' )
53+ echo $tags | jq
54+ echo tags="$tags" >> $GITHUB_OUTPUT
5155 - name : Upload file
5256 uses : actions/upload-artifact@v4
5357 with :
5458 name : manifests
5559 path : manifests.txt
60+ - uses : actions/cache/save@v4
61+ with :
62+ path : manifests.txt
63+ key : manifests
5664 build :
5765 needs : prepare
5866 if : ${{ needs.prepare.outputs.do_build != 'false' }}
5967 strategy :
6068 fail-fast : false
6169 matrix :
6270 include : ${{ fromJson(needs.prepare.outputs.images) }}
63- runs-on : ${{ matrix.platform }}
71+ runs-on : ${{ matrix.runner }}
6472 steps :
6573 - name : Checkout repository
6674 uses : actions/checkout@v3
6775
6876 - name : Pull image
77+ id : image
6978 run : |
70- uname -a
71- docker pull ${{ env.IMAGE_REPO }}/${{ env.IMAGE_NAME }}:${{ matrix.tag }}
72- version=$(docker image inspect ${{ env.IMAGE_REPO }}/${{ env.IMAGE_NAME }}:${{ matrix.tag }} --format '{{index .Config.Labels "com.intersystems.platform-version"}}' | cut -d'.' -f1-2)
73- hash=$(docker images ${{ env.IMAGE_REPO }}/${{ env.IMAGE_NAME }}:${{ matrix.tag }} --no-trunc -q)
74- echo "Platform version: $version"
79+ base=${{ env.IMAGE_REPO }}/${{ env.IMAGE_NAME }}:${{ matrix.tag }}
80+ docker pull $base
81+ labels=$(docker image inspect --format '{{range $k, $v := .Config.Labels}}--label {{$k}}="{{$v}}" {{end}}' $base)
82+ version=$(docker image inspect --format '{{index .Config.Labels "com.intersystems.platform-version"}}' $base | cut -d'.' -f1-2)
83+ originalbase=$(docker history $base --format '{{.CreatedBy}}' --no-trunc | grep 'LABEL org.opencontainers.image.ref.name=' | cut -d'=' -f2 )
84+ originalbase+=:$(docker history $base --format '{{.CreatedBy}}' --no-trunc | grep 'LABEL org.opencontainers.image.version=' | cut -d'=' -f2 )
85+ echo base=$base >> $GITHUB_OUTPUT
86+ echo labels=$labels >> $GITHUB_OUTPUT
87+ echo version=$version >> $GITHUB_OUTPUT
88+ echo originalbase=$originalbase >> $GITHUB_OUTPUT
7589 - name : Login to Docker Hub
7690 uses : docker/login-action@v2
7791 with :
7892 username : ${{ secrets.DOCKERHUB_USERNAME }}
7993 password : ${{ secrets.DOCKERHUB_TOKEN }}
80- - name : Build IRIS Light image
81- id : image
82- run : |
83- suffix=$(uname -m | sed 's/aarch64/arm64/' | sed 's/x86_64/amd64/')
84- source ./make.sh "${{ env.IMAGE_REPO }}/${{ env.IMAGE_NAME }}:${{ matrix.tag }}" "${{ env.TARGET_IMAGE }}" $suffix
85- for img in "${IMAGES[@]}"; do
86- echo "::notice ::Built image: $img"
87- docker push $img
88- done
89- for tag in "${TAGS[@]}"; do echo $tag >> ${{ github.run_id }}_${{ matrix.tag }}_${{ matrix.platform }}_images.txt; done
90- echo images="${IMAGES[@]}" >> $GITHUB_OUTPUT
91- echo tags="${TAGS[@]}" >> $GITHUB_OUTPUT
92- - name : Upload file
93- uses : actions/upload-artifact@v4
94+ - name : Set up Docker Buildx
95+ uses : docker/setup-buildx-action@v3
96+ - name : Build and push by digest
97+ id : build
98+ uses : docker/build-push-action@v6
9499 with :
95- name : ${{ github.run_id }}_${{ matrix.tag }}_${{ matrix.platform }}
96- path : ${{ github.run_id }}_${{ matrix.tag }}_${{ matrix.platform }}_*.txt
97- metadata :
98- runs-on : ubuntu-latest
99- needs : build
100- steps :
101- - name : Download artifacts of matrix jobs
102- uses : actions/download-artifact@v4
103- with :
104- path : ./
105- merge-multiple : true
106- - name : Images
107- id : images
100+ context : .
101+ build-args : |
102+ BASE_IMAGE=${{ steps.image.outputs.base }}
103+ ORIGINAL_BASE=${{ steps.image.outputs.originalbase }}
104+ labels : ${{ steps.image.outputs.labels }}
105+ push : true
106+ tags : ${{ env.TARGET_IMAGE }}
107+ outputs : type=image,push-by-digest=true,name-canonical=true,push=true
108+ - name : Save digest as artifact
108109 run : |
109- echo tags=`cat ${{ github.run_id }}_*_images.txt | sed 's/-amd64//g;s/-arm64//g' | sort | uniq | jq -Rsc 'split("\n") | map(select(length > 0))'` >> $GITHUB_OUTPUT
110- - uses : actions/cache/save@v4
110+ mkdir -p "$RUNNER_TEMP/digests"
111+ digest="${{ steps.build.outputs.digest }}"
112+ # strip "sha256:" prefix, use remainder as filename
113+ echo ${{ steps.image.outputs.version }} > "$RUNNER_TEMP/digests/${digest#sha256:}"
114+ shell : bash
115+ - name : Upload digest
116+ uses : actions/upload-artifact@v4
111117 with :
112- path : manifests.txt
113- key : manifests
114- outputs :
115- tags : ${{ steps.images.outputs.tags }}
116-
118+ name : digests-${{ matrix.tag }}-${{ matrix.runner }}
119+ path : ${{ runner.temp }}/digests/*
120+ if-no-files-found : error
121+ retention-days : 1
117122 merge :
118- runs-on : ubuntu-latest
119- needs : metadata
123+ needs :
124+ - prepare
125+ - build
120126 strategy :
121127 fail-fast : false
122128 matrix :
123- tag : ${{ fromJson(needs.metadata.outputs.tags) }}
129+ include : ${{ fromJson(needs.prepare.outputs.tags) }}
130+ runs-on : ubuntu-latest
124131 steps :
132+ - name : Download digests
133+ uses : actions/download-artifact@v4
134+ with :
135+ path : ${{ runner.temp }}/digests
136+ pattern : digests-${{ matrix.tag }}-*
137+ merge-multiple : true
125138 - name : Login to Docker Hub
126139 uses : docker/login-action@v2
127140 with :
128141 username : ${{ secrets.DOCKERHUB_USERNAME }}
129142 password : ${{ secrets.DOCKERHUB_TOKEN }}
130- - name : Images
143+ - name : Set up Docker Buildx
144+ uses : docker/setup-buildx-action@v3
145+
146+ - name : Create multi-arch manifest and push
147+ working-directory : ${{ runner.temp }}/digests
131148 run : |
132- docker manifest create ${{ env.TARGET_IMAGE }}:${{ matrix.tag }} \
133- ${{ env.TARGET_IMAGE }}:${{ matrix.tag }}-amd64 \
134- ${{ env.TARGET_IMAGE }}:${{ matrix.tag }}-arm64
135- docker manifest push ${{ env.TARGET_IMAGE }}:${{ matrix.tag }}
149+ # turn each file name (a sha256 without prefix) into IMAGE@sha256:...
150+ version=$(cat * | head -1)
151+ docker buildx imagetools create \
152+ -t ${{ env.TARGET_IMAGE }}:${{ matrix.tag }} \
153+ -t ${{ env.TARGET_IMAGE }}:$version \
154+ $(printf '${{ env.TARGET_IMAGE }}@sha256:%s ' *)
155+
156+ - name : Inspect final image (optional)
157+ run : docker buildx imagetools inspect ${{ env.TARGET_IMAGE }}:${{ matrix.tag }}
0 commit comments