Skip to content

Commit 7725522

Browse files
committed
on-tag improvements
1 parent 9f2c30c commit 7725522

File tree

2 files changed

+82
-51
lines changed

2 files changed

+82
-51
lines changed

.github/workflows/on-tag.yml

Lines changed: 71 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ jobs:
102102
QEMU_VERSION: v4.2.0
103103
run: docker run --rm --privileged "meedamian/simple-qemu:${QEMU_VERSION}" -p yes
104104

105-
# TODO: add labels, see: https://github.com/lncm/docker-lnd/blob/3a26bc667c441e94958b876170f87d538cb5a07a/.github/workflows/on-tag.yml#L102-L107
106105
- name: Build IPFS
107106
run: >
108107
docker build --no-cache .
@@ -111,6 +110,12 @@ jobs:
111110
--build-arg "GOARCH=${GOARCH}"
112111
--build-arg "GOARM=${GOARM}"
113112
--build-arg "FLAVOR=${{matrix.flavor}}"
113+
--label "arch=${{matrix.arch}}"
114+
--label "commit=${{github.sha}}"
115+
--label "git-tag=${TAG}"
116+
--label "guilty=${{github.actor}}"
117+
--label "repo-url=${{github.repositoryUrl}}"
118+
--label "flavor=${FLAVOR}"
114119
--tag "${APP}:${FLAV_ARCH}"
115120
116121
- name: Show built image details
@@ -148,34 +153,48 @@ jobs:
148153
path: binary/
149154

150155

151-
docker-hub-push:
152-
name: Tag & deploy to Docker Hub. Only after successful build, and test of a pushed git tag
156+
docker-hub:
157+
name: Tag & deploy to Docker Hub. Only after all builds & tests succeed
158+
153159
runs-on: ubuntu-18.04
154160
needs: build
155161

156-
env:
157-
APP: ipfs
158-
159162
steps:
160163
- uses: actions/[email protected]
161164

162-
- name: Enable Docker manifest features
163-
run: |
164-
mkdir -p ~/.docker
165-
echo '{ "experimental": "enabled" }' > ~/.docker/config.json
166-
sudo systemctl restart docker
167-
168165
- name: Setup environment
169166
run: |
170-
VERSION="$(echo "${GITHUB_REF}" | grep 'refs/tags/' | awk -F/ '{print $NF}')"
171-
echo ::set-env name=VERSION::"${VERSION}"
167+
echo ::set-env name=DOCKER_USER::"${GITHUB_ACTOR,,}"
168+
169+
SLUG="$(echo ${GITHUB_REPOSITORY,,} | sed 's/docker-//')"
170+
echo ::set-env name=SLUG::"${SLUG}"
172171
173-
echo ::set-env name=SLUG::"$(echo ${GITHUB_REPOSITORY,,} | sed 's/docker-//')"
172+
echo ::set-env name=APP::"$(echo "${SLUG}" | awk -F/ '{print $NF}')"
174173
175-
- name: Print Docker version
176-
run: docker version
174+
TAG="$(echo "${GITHUB_REF}" | grep 'refs/tags/' | awk -F/ '{print $NF}')"
175+
echo ::set-env name=TAG::"${TAG}"
177176
178-
- name: Download build artifact
177+
echo ::set-env name=VERSION::"$(echo "${TAG}" | cut -d+ -f1)"
178+
echo ::set-env name=BUILD::"$(echo "+${TAG}" | cut -d+ -f3)"
179+
180+
- name: Print just set ENV VARs
181+
run: |
182+
printf "Just set env vars:\n"
183+
printf " USER: %s\n" "${DOCKER_USER}"
184+
printf " TAG: %s\n" "${TAG}"
185+
printf " SLUG: %s\n" "${SLUG}"
186+
printf " APP: %s\n" "${APP}"
187+
printf "VERSION: %s\n" "${VERSION}"
188+
printf " BUILD: %s\n" "${BUILD}"
189+
190+
- name: Enable manifests & print Docker version
191+
run: |
192+
mkdir -p ~/.docker
193+
echo '{ "experimental": "enabled" }' > ~/.docker/config.json
194+
sudo systemctl restart docker
195+
docker version
196+
197+
- name: Download images built in build job
179198
uses: actions/[email protected]
180199
with:
181200
name: docker-images
@@ -184,47 +203,62 @@ jobs:
184203
run: sha256sum docker-images/*
185204

186205
- name: Load images locally
187-
run: ls docker-images/ | xargs -I % docker load -i "docker-images/%"
188-
189-
- name: List all tagged images
190-
run: docker images "${APP}"
206+
run: ls -d docker-images/* | xargs -I % docker load -i "%"
191207

208+
# `ipfs:fuse-arm64` -> `lncm/ipfs:v0.4.22-fuse-arm64-build1`
209+
# `ipfs:fuse-arm64` -> `lncm/ipfs:v0.4.22-fuse-arm64`
210+
# `ipfs:nofuse-arm64` -> `lncm/ipfs:v0.4.22-nofuse-arm64-build1`
211+
# `ipfs:nofuse-arm64 -> `lncm/ipfs:v0.4.22-nofuse-arm64`
192212
- name: Version-tag all images
193213
run: |
194-
for arch in $(docker images "${APP}" --format "{{.Tag}}"); do
195-
docker tag "${APP}:${arch}" "${SLUG}:${VERSION}-${arch}"
214+
for tag in $(docker images ${APP} --format "{{.Tag}}"); do
215+
docker tag "${APP}:${tag}" "${SLUG}:${VERSION}-${tag}-${BUILD}"
216+
docker tag "${APP}:${tag}" "${SLUG}:${VERSION}-${tag}"
196217
done
197218
198219
- name: List all tagged images
199220
run: docker images "${SLUG}"
200221

201222
- name: Login to Docker Hub
202-
run: echo "${{secrets.DOCKER_TOKEN}}" | docker login -u="meedamian" --password-stdin
223+
run: |
224+
echo "Logging in as ${DOCKER_USER}…"
225+
echo "${{secrets.DOCKER_TOKEN}}" | docker login -u="${DOCKER_USER}" --password-stdin
203226
204227
- name: Push all images
205-
run: |
206-
for image in $(docker images "${SLUG}" --format "{{.Repository}}:{{.Tag}}"); do
207-
docker push "${image}"
208-
done
228+
run: docker images "${SLUG}" --format "{{.Repository}}:{{.Tag}}" | xargs -I % docker push %
209229

210230
- name: Get convenience Docker tag suggestions
211231
id: tags
212232
uses: meeDamian/[email protected]
213233

214-
- name: Create version-exact manifest
215-
run: ./scripts/ci-create-manifest.sh "${SLUG}" "${VERSION}"
234+
- name: Create :X.Y.Z manifests
235+
run: |
236+
./scripts/ci-create-manifest.sh "${SLUG}" "${VERSION}" "fuse" "${VERSION}-fuse"
237+
./scripts/ci-create-manifest.sh "${SLUG}" "${VERSION}" "nofuse" "${VERSION}-nofuse"
238+
./scripts/ci-create-manifest.sh "${SLUG}" "${VERSION}" "nofuse"
216239
217-
- name: Create minor-version manifest
240+
- name: Create :X.Y manifests
218241
if: steps.tags.outputs.minor != ''
219-
run: ./scripts/ci-create-manifest.sh "${SLUG}" "${VERSION}" "${{steps.tags.outputs.minor}}"
242+
run: |
243+
SHORT="${{steps.tags.outputs.minor}}"
244+
./scripts/ci-create-manifest.sh "${SLUG}" "${VERSION}" "fuse" "${SHORT}-fuse"
245+
./scripts/ci-create-manifest.sh "${SLUG}" "${VERSION}" "nofuse" "${SHORT}-nofuse"
246+
./scripts/ci-create-manifest.sh "${SLUG}" "${VERSION}" "nofuse"
220247
221-
- name: Create major-version manifest
248+
- name: Create :X manifests
222249
if: steps.tags.outputs.major != ''
223-
run: ./scripts/ci-create-manifest.sh "${SLUG}" "${VERSION}" "${{steps.tags.outputs.major}}"
250+
run: |
251+
SHORT="${{steps.tags.outputs.major}}"
252+
./scripts/ci-create-manifest.sh "${SLUG}" "${VERSION}" "fuse" "${SHORT}-fuse"
253+
./scripts/ci-create-manifest.sh "${SLUG}" "${VERSION}" "nofuse" "${SHORT}-nofuse"
254+
./scripts/ci-create-manifest.sh "${SLUG}" "${VERSION}" "nofuse"
224255
225-
- name: Create latest-version manifest
256+
- name: Create :latest manifests
226257
if: steps.tags.outputs.latest != ''
227-
run: ./scripts/ci-create-manifest.sh "${SLUG}" "${VERSION}" "${{steps.tags.outputs.latest}}"
258+
run: |
259+
./scripts/ci-create-manifest.sh "${SLUG}" "${VERSION}" "fuse" "fuse"
260+
./scripts/ci-create-manifest.sh "${SLUG}" "${VERSION}" "nofuse" "nofuse"
261+
./scripts/ci-create-manifest.sh "${SLUG}" "${VERSION}" "nofuse" "${{steps.tags.outputs.latest}}"
228262
229263
- name: List all tagged images
230264
run: docker images "${SLUG}"

scripts/ci-create-manifest.sh

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
1-
#!/bin/bash
2-
set -e
1+
#!/usr/bin/env bash
2+
3+
set -eo pipefail
34

45
SLUG=$1
56
VERSION=$2
7+
FLAVOR=$3
8+
SHORT_VERSION=${4:-${VERSION}}
69

7-
SHORT_VERSION=$3
8-
if [[ -z "${SHORT_VERSION}" ]]; then
9-
SHORT_VERSION="${VERSION}"
10-
fi
11-
12-
BASE="${SLUG}:${VERSION}"
13-
14-
IMAGE_AMD64="${BASE}-linux-amd64"
15-
IMAGE_ARM64="${BASE}-linux-arm64"
16-
IMAGE_ARM6="${BASE}-linux-arm32v6"
17-
IMAGE_ARM7="${BASE}-linux-arm32v7"
10+
BASE="${SLUG}:${VERSION}-${FLAVOR}"
1811

12+
IMAGE_AMD64="${BASE}-amd64"
13+
IMAGE_ARM64="${BASE}-arm64"
14+
IMAGE_ARM6="${BASE}-arm32v6"
15+
IMAGE_ARM7="${BASE}-arm32v7"
1916

2017
MANIFEST="${SLUG}:${SHORT_VERSION}"
2118

2219
docker -D manifest create "${MANIFEST}" "${IMAGE_AMD64}" "${IMAGE_ARM64}" "${IMAGE_ARM6}" "${IMAGE_ARM7}"
23-
docker manifest annotate "${MANIFEST}" "${IMAGE_ARM64}" --os linux --arch arm64
20+
docker manifest annotate "${MANIFEST}" "${IMAGE_ARM64}" --os linux --arch arm64 --variant v8
2421
docker manifest annotate "${MANIFEST}" "${IMAGE_ARM7}" --os linux --arch arm --variant v7
2522
docker manifest annotate "${MANIFEST}" "${IMAGE_ARM6}" --os linux --arch arm --variant v6
2623
docker manifest push "${MANIFEST}"

0 commit comments

Comments
 (0)