22# Build tag from release name when release is published.
33# Build 'latest' tag when release is published and marked as 'latest'.
44name : Publish release image
5-
65on :
76 workflow_dispatch :
87 release :
98 types : [published]
10-
119env :
1210 QEMU_PLATFORMS : arm64,arm
1311 BUILDX_PLATFORMS : " linux/amd64,linux/arm64,linux/arm/v7"
1412 DOCKER_HUB_REPO : flant/shell-operator
1513 GHCR_IO_REPO : ghcr.io/flant/shell-operator
16-
1714jobs :
1815 check :
1916 name : Check
7370 core.setOutput('run_publish', runPublish.toString());
7471 core.setOutput('image_tag', imageTag);
7572 core.setOutput('additional_tag', additionalTag);
76-
7773 publish_image :
7874 name : Build and publish
7975 runs-on : [ubuntu-latest]
8278 if : needs.check.outputs.run_publish == 'true'
8379 steps :
8480 - uses : actions/checkout@v4
85-
8681 - name : Prepare environment
8782 env :
8883 ADDITIONAL_TAG : ${{ needs.check.outputs.additional_tag }}
@@ -116,25 +111,21 @@ jobs:
116111 echo "ADDITIONAL_DOCKER_HUB_IMAGE_NAME = $ADDITIONAL_DOCKER_HUB_IMAGE_NAME" && \
117112 echo "ADDITIONAL_GHCR_IO_IMAGE_NAME = $ADDITIONAL_GHCR_IO_IMAGE_NAME"
118113 echo "========================================="
119-
120114 - name : Set up QEMU
121115 uses : docker/setup-qemu-action@v3.6.0
122116 with :
123117 platforms : " ${{ env.QEMU_PLATFORMS }}"
124-
125118 - name : Set up Docker Buildx
126119 id : buildx
127120 uses : docker/setup-buildx-action@v3
128121 with :
129122 version : latest
130-
131123 - name : Login to Github Container Registry
132124 uses : docker/login-action@v3.4.0
133125 with :
134126 registry : ghcr.io
135127 username : ${{ secrets.GHCR_IO_USER }}
136128 password : ${{ secrets.GHCR_IO_PASS }}
137-
138129 - name : Build and push multi-arch image
139130 run : |
140131 echo "Build and push $FINAL_IMAGE_NAME with version '$APP_VERSION'."
@@ -147,45 +138,19 @@ jobs:
147138 --tag $GHCR_IO_IMAGE_NAME \
148139 --push \
149140 .
150-
151141 - name : Inspect binaries
152- run : |
153- # Image for one arhitecture has digest in config field.
154- # Image with multiple manifests has digest in each manifest.
155- manifests=$(docker buildx imagetools inspect "${GHCR_IO_IMAGE_NAME}" --raw)
156- if grep manifests <<<"${manifests}" 2>&1 >/dev/null ; then
157- jq -r '.manifests[]? | .digest + " " + .platform.os + "/" + .platform.architecture' <<<"${manifests}"
158- else
159- echo $(echo -n "${manifests}" | openssl dgst -sha256 | sed s/^.stdin.*\ //) ' linux/amd64'
160- fi \
161- | while read digest platform ; do
162- if [[ ${BUILDX_PLATFORMS} != *"${platform}"* ]] ; then
163- echo "====================================="
164- echo "Ignore image for non-runnable platform ${platform}"
165- echo " ${image}"
166- echo "====================================="
167- continue
168- fi
169- image=${GHCR_IO_IMAGE_NAME}@${digest}
170- echo "====================================="
171- echo "Inspect image for platform ${platform}"
172- echo " ${image}"
173- echo "====================================="
174- docker run --rm --platform ${platform} --entrypoint sh ${image} -c \
175- 'apk add file > /dev/null; file /bin/kubectl; file /bin/busybox; file /shell-operator'
176- done
177-
142+ run: "# Image for one arhitecture has digest in config field.\n# Image with multiple manifests has digest in each manifest.\nmanifests=$(docker buildx imagetools inspect \"${GHCR_IO_IMAGE_NAME}\" --raw)\nif grep manifests <<<\"${manifests}\" 2>&1 >/dev/null ; then\n jq -r '.manifests[]? | .digest + \" \" + .platform.os + \"/\" + .platform.architecture' <<<\"${manifests}\"\nelse\n echo $(echo -n \"${manifests}\" | openssl dgst -sha256 | sed s/^.stdin.*\\ //) ' linux/amd64'\nfi \\\n| while read digest platform ; do\n if [[ ${BUILDX_PLATFORMS} != *\"${platform}\"* ]] ; then\n echo \"=====================================\"\n echo \"Ignore image for non-runnable platform ${platform}\"\n echo \" ${image}\"\n echo \"=====================================\"\n continue \n fi\n image=${GHCR_IO_IMAGE_NAME}@${digest}\n echo \"=====================================\"\n echo \"Inspect image for platform ${platform}\"\n echo \" ${image}\"\n echo \"=====================================\"\n docker run --rm --platform ${platform} --entrypoint sh ${image} -c \\\n 'apk add file > /dev/null; file /bin/kubectl; file /bin/busybox; file /shell-operator'\ndone\n"
178143 - name : Copy image to Docker Hub
179144 env :
180145 DOCKER_USER : ${{ secrets.DOCKER_USER }}
181146 DOCKER_PASS : ${{ secrets.DOCKER_PASS }}
182147 run : |
183148 echo "Download crane tool ..."
184-
149+
185150 CRANE_VERSION=$(curl -s "https://api.github.com/repos/google/go-containerregistry/releases/latest" | jq -r '.tag_name')
186151 CRANE_OS=Linux # or Darwin, Windows
187152 CRANE_ARCH=x86_64 # or arm64, x86_64, armv6, i386, s390x, riscv64
188-
153+
189154 echo "Crane version: ${CRANE_VERSION}, OS: ${CRANE_OS}, ARCH: ${CRANE_ARCH}"
190155 curl -sL "https://github.com/google/go-containerregistry/releases/download/${CRANE_VERSION}/go-containerregistry_${CRANE_OS}_${CRANE_ARCH}.tar.gz" > go-containerregistry.tar.gz
191156 echo "Extract crane tool ..."
0 commit comments