Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add multi-arch image(amd64 and s390x) build and publish #23

Merged
merged 1 commit into from
Sep 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,26 @@ sudo: required
services:
- docker

script:
- bash ./build.sh
jobs:
allow_failures:
- if: arch = s390x
include:
- stage: build amd64
workspaces:
create:
name: ws1
paths:
- tag.txt
script:
- bash ./build.sh
- stage: build s390x
arch: s390x
workspaces:
use: ws1
script:
- bash ./build.sh
- stage: make multi-arch images
workspaces:
use: ws1
script:
- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash ./multi-arch-image.sh; fi'
51 changes: 29 additions & 22 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,51 @@
set -e

image="alpine/git"

ARCH=${TRAVIS_CPU_ARCH:-"amd64"}
LATEST_TAG=$(git ls-remote --tags origin |awk -F \/ '{print $NF}'|grep ^1.0. |sort -Vr|head -1)
if [[ -z "${LATEST_TAG}" ]]
then
NEXT_TAG="1.0.0"
else
NEXT_TAG=$(docker run --rm alpine/semver:5.5.0 semver -c -i patch ${LATEST_TAG})
if [[ "$ARCH" == "amd64" ]]
then
NEXT_TAG=$(docker run --rm alpine/semver:5.5.0 semver -c -i patch ${LATEST_TAG})
echo ${NEXT_TAG} > tag.txt
else
NEXT_TAG=$(cat tag.txt)
fi
fi
echo ${NEXT_TAG}

docker build --no-cache -t ${image}:${NEXT_TAG} .
docker tag ${image}:${NEXT_TAG} ${image}:latest
docker build --no-cache -t ${image}:${NEXT_TAG}-${ARCH} .
docker tag ${image}:${NEXT_TAG}-${ARCH} ${image}:latest-${ARCH}

# add another tag with git version, with this way, we can check this git image health
VERSION=($(docker run -i --rm ${image}:latest version|awk '{print $NF}'))
VERSION=($(docker run -i --rm ${image}:latest-${ARCH} version|awk '{print $NF}'))
echo ${VERSION}
docker tag ${image}:${NEXT_TAG} ${image}:v${VERSION}
docker tag ${image}:${NEXT_TAG}-${ARCH} ${image}:v${VERSION}-${ARCH}

if [[ "$TRAVIS_BRANCH" == "master" && "$TRAVIS_PULL_REQUEST" == false ]]; then
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
docker push ${image}:${NEXT_TAG}
docker push ${image}:latest
docker push ${image}:v${VERSION}

# push the tag
git remote set-url origin https://${GITHUB_NAME}:${GITHUB_TOKEN}@github.com/alpine-docker/git.git
echo "Set github Username & Email"
git config user.name "ci"
git config user.email "ci"
echo "Create & Push Tag"
git tag ${NEXT_TAG}
git push origin ${NEXT_TAG}
docker push ${image}:${NEXT_TAG}-${ARCH}
docker push ${image}:latest-${ARCH}
docker push ${image}:v${VERSION}-${ARCH}
if [[ "$ARCH" == "amd64" ]]; then
# push the tag
git remote set-url origin https://${GITHUB_NAME}:${GITHUB_TOKEN}@github.com/alpine-docker/git.git
echo "Set github Username & Email"
git config user.name "ci"
git config user.email "ci"
echo "Create & Push Tag"
git tag ${NEXT_TAG}
git push origin ${NEXT_TAG}
fi
fi

if [[ "$TRAVIS_BRANCH" == "feature/non-root" && "$TRAVIS_PULL_REQUEST" == false ]]; then
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
docker tag ${image}:v${VERSION} ${image}:user
docker tag ${image}:v${VERSION} ${image}:v${VERSION}-user
docker push ${image}:user
docker push ${image}:v${VERSION}-user
docker tag ${image}:v${VERSION}-${ARCH} ${image}-${ARCH}:user-${ARCH}
docker tag ${image}:v${VERSION}-${ARCH} ${image}-${ARCH}:v${VERSION}-user-${ARCH}
docker push ${image}:user-${ARCH}
docker push ${image}:v${VERSION}-user-${ARCH}
fi
42 changes: 42 additions & 0 deletions multi-arch-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash

# Prerequisite
# Make sure you set secret enviroment variables in Travis CI
# DOCKER_USERNAME
# DOCKER_PASSWORD

set -e

function get_arch_images(){
image=$1; shift || fatal "usage error"
tag=$1; shift || fatal "usage error"
archs="amd64 s390x"
for arch in $archs; do
if [[ "$(docker pull ${image}:${tag}-${arch} >/dev/null 2>&1 ; echo $?)" == 0 ]]; then
echo "${image}:${tag}-${arch} "
fi
done
}

image="alpine/git"
if [[ "$TRAVIS_BRANCH" == "master" && "$TRAVIS_PULL_REQUEST" == false ]]; then
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
NEXT_TAG=$(cat tag.txt)
VERSION=$(docker run -i --rm ${image}:latest-amd64 version|awk '{print $NF}')
#create and push multi-arch 3 images - latest, ${NEXT_TAG} and v${VERSION}
DOCKER_CLI_EXPERIMENTAL="enabled" docker manifest create ${image}:${NEXT_TAG} $(get_arch_images ${image} ${NEXT_TAG})
DOCKER_CLI_EXPERIMENTAL="enabled" docker manifest push --purge ${image}:${NEXT_TAG}
DOCKER_CLI_EXPERIMENTAL="enabled" docker manifest create ${image}:latest $(get_arch_images ${image} "latest")
DOCKER_CLI_EXPERIMENTAL="enabled" docker manifest push --purge ${image}:latest
DOCKER_CLI_EXPERIMENTAL="enabled" docker manifest create ${image}:v${VERSION} $(get_arch_images ${image} v${VERSION})
DOCKER_CLI_EXPERIMENTAL="enabled" docker manifest push --purge ${image}:v${VERSION}
fi

if [[ "$TRAVIS_BRANCH" == "feature/non-root" && "$TRAVIS_PULL_REQUEST" == false ]]; then
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
#create and push multi-arch 2 images - user and v${VERSION}-user
DOCKER_CLI_EXPERIMENTAL="enabled" docker manifest create ${image}:user $(get_arch_images ${image} "user")
DOCKER_CLI_EXPERIMENTAL="enabled" docker manifest push --purge ${image}:user
DOCKER_CLI_EXPERIMENTAL="enabled" docker manifest create ${image}:v${VERSION}-user $(get_arch_images ${image} v${VERSION}-user)
DOCKER_CLI_EXPERIMENTAL="enabled" docker manifest push --purge ${image}:v${VERSION}-user
fi