Skip to content

Commit 4eecb08

Browse files
committed
Handle multi-arch docker image tagging
1 parent fa697a1 commit 4eecb08

File tree

1 file changed

+72
-1
lines changed

1 file changed

+72
-1
lines changed

src/hooks/post_push

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,75 @@
66
curl -Lo manifest-tool https://github.com/estesp/manifest-tool/releases/download/v0.9.0/manifest-tool-linux-amd64
77
chmod +x manifest-tool
88

9-
./manifest-tool push from-spec multi-arch-manifest.yaml
9+
# Generate the manifest file.
10+
# Parameter 1 is the multi-arch image name, e.g. ckulka/baikal:0.5.1
11+
# Parameter 2 is the base-image for the variants, e.g. ckulka/baikal:0.5.1-apache
12+
function generate_manifest {
13+
NAME=$1
14+
RELEASE_TAG=$2
15+
16+
cat > manifest-generated.yaml << EOF
17+
image: ${NAME}:${RELEASE_TAG}
18+
manifests:
19+
- image: ${NAME}:${RELEASE_TAG}-amd64
20+
platform:
21+
architecture: amd64
22+
os: linux
23+
- image: ${NAME}:${RELEASE_TAG}-arm32v7
24+
platform:
25+
architecture: arm
26+
os: linux
27+
variant: v7
28+
EOF
29+
30+
echo "manifest: "
31+
cat manifest-generated.yaml
32+
}
33+
34+
function docker_tag_exists() {
35+
curl --silent -f -lSL https://index.docker.io/v1/repositories/$1/tags/$2 > /dev/null
36+
}
37+
38+
# Example: values
39+
# ${DOCKER_REPO} = index.docker.io/guysoft/custompios-test
40+
# ${IMAGE_NAME} = index.docker.io/guysoft/custompios-test:1.2.4-amd64
41+
# ${DOCKER_TAG} = 1.2.4-amd64
42+
43+
44+
# If we're building the "devel" branch, then also push it as "latest"
45+
if [[ "$DOCKER_TAG" == "amd64" ]] || [[ "$DOCKER_TAG" == "arm32v7" ]]
46+
then
47+
echo "Pushing multi-arch manifest $DOCKER_REPO:latest"
48+
./manifest-tool push from-spec multi-arch-manifest.yaml
49+
50+
# Handle release
51+
else
52+
echo "handeling: ${DOCKER_REPO}|${IMAGE_NAME}|${DOCKER_TAG}"
53+
54+
RELEASE_TAG=${DOCKER_TAG%%-*}
55+
56+
REPO_NAME=${IMAGE_NAME##*/} ; REPO_NAME=${REPO_NAME%%:*}
57+
REPO_NAME_AND_USER=${IMAGE_NAME%%/${REPO_NAME}*}
58+
USER_NAME=${REPO_NAME_AND_USER##*/}
59+
60+
NAME=${USER_NAME}/${REPO_NAME}
61+
62+
# Example: values
63+
# ${NAME} = guysoft/custompios
64+
# ${RELEASE_TAG} = 1.2.3
65+
66+
generate_manifest "${NAME}" "${RELEASE_TAG}"
67+
68+
if docker_tag_exists ${NAME} ${RELEASE_TAG}-amd64 ;then
69+
if docker_tag_exists ${NAME} ${RELEASE_TAG}-arm32v7;then
70+
echo "Pushing multi-arch manifest"
71+
./manifest-tool push from-spec manifest-generated.yaml
72+
else
73+
echo "arm32v7 image is missing, not pushing manifest"
74+
fi
75+
76+
else
77+
echo "amd64 image is missing, not pushing manifest"
78+
fi
79+
80+
fi

0 commit comments

Comments
 (0)