Skip to content

Commit

Permalink
Handle multi-arch docker image tagging
Browse files Browse the repository at this point in the history
  • Loading branch information
guysoft committed Nov 17, 2019
1 parent fa697a1 commit 4eecb08
Showing 1 changed file with 72 additions and 1 deletion.
73 changes: 72 additions & 1 deletion src/hooks/post_push
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,75 @@
curl -Lo manifest-tool https://github.com/estesp/manifest-tool/releases/download/v0.9.0/manifest-tool-linux-amd64
chmod +x manifest-tool

./manifest-tool push from-spec multi-arch-manifest.yaml
# Generate the manifest file.
# Parameter 1 is the multi-arch image name, e.g. ckulka/baikal:0.5.1
# Parameter 2 is the base-image for the variants, e.g. ckulka/baikal:0.5.1-apache
function generate_manifest {
NAME=$1
RELEASE_TAG=$2

cat > manifest-generated.yaml << EOF
image: ${NAME}:${RELEASE_TAG}
manifests:
- image: ${NAME}:${RELEASE_TAG}-amd64
platform:
architecture: amd64
os: linux
- image: ${NAME}:${RELEASE_TAG}-arm32v7
platform:
architecture: arm
os: linux
variant: v7
EOF

echo "manifest: "
cat manifest-generated.yaml
}

function docker_tag_exists() {
curl --silent -f -lSL https://index.docker.io/v1/repositories/$1/tags/$2 > /dev/null
}

# Example: values
# ${DOCKER_REPO} = index.docker.io/guysoft/custompios-test
# ${IMAGE_NAME} = index.docker.io/guysoft/custompios-test:1.2.4-amd64
# ${DOCKER_TAG} = 1.2.4-amd64


# If we're building the "devel" branch, then also push it as "latest"
if [[ "$DOCKER_TAG" == "amd64" ]] || [[ "$DOCKER_TAG" == "arm32v7" ]]
then
echo "Pushing multi-arch manifest $DOCKER_REPO:latest"
./manifest-tool push from-spec multi-arch-manifest.yaml

# Handle release
else
echo "handeling: ${DOCKER_REPO}|${IMAGE_NAME}|${DOCKER_TAG}"

RELEASE_TAG=${DOCKER_TAG%%-*}

REPO_NAME=${IMAGE_NAME##*/} ; REPO_NAME=${REPO_NAME%%:*}
REPO_NAME_AND_USER=${IMAGE_NAME%%/${REPO_NAME}*}
USER_NAME=${REPO_NAME_AND_USER##*/}

NAME=${USER_NAME}/${REPO_NAME}

# Example: values
# ${NAME} = guysoft/custompios
# ${RELEASE_TAG} = 1.2.3

generate_manifest "${NAME}" "${RELEASE_TAG}"

if docker_tag_exists ${NAME} ${RELEASE_TAG}-amd64 ;then
if docker_tag_exists ${NAME} ${RELEASE_TAG}-arm32v7;then
echo "Pushing multi-arch manifest"
./manifest-tool push from-spec manifest-generated.yaml
else
echo "arm32v7 image is missing, not pushing manifest"
fi

else
echo "amd64 image is missing, not pushing manifest"
fi

fi

0 comments on commit 4eecb08

Please sign in to comment.