Merge pull request #178 from MarkSchmitt/travis-multiarch-builds

Automatic CI/CD multiarch docker builds
This commit is contained in:
Jonas Winkler 2020-12-23 14:35:47 +01:00 committed by GitHub
commit 6907b91420
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 101 additions and 0 deletions

View File

@ -33,6 +33,106 @@ jobs:
- ng build --prod
after_success: true
- stage: build_docker
name: amd64 docker build
services:
- docker
before_install:
- true
install:
- true
after_success:
- true
script:
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
- docker build -f Dockerfile --tag=${DOCKER_REPO}:${TRAVIS_COMMIT}-amd64 .
- docker push ${DOCKER_REPO}:${TRAVIS_COMMIT}-amd64
on:
condition: '"${BUILD_DOCKER}" = 1'
- stage: build_docker
name: arm64v8 docker build
services:
- docker
before_install:
- true
install:
- true
after_success:
- true
script:
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
# travis_wait 60 tells travis to wait for up to 60 minutes - default is 20, which is too short
- travis_wait 60 docker build -f Dockerfile --tag=${DOCKER_REPO}:${TRAVIS_COMMIT}-arm64v8 .
- docker push ${DOCKER_REPO}:${TRAVIS_COMMIT}-arm64v8
arch: arm64-graviton2
virt: vm
group: edge
on:
condition: '"${BUILD_DOCKER}" = 1'
- stage: build_docker
name: arm32v7 docker build
services:
- docker
before_install:
- true
install:
- true
after_success:
- true
script:
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
# register binfmt stuff for qemu-static binaries so we can use userland-emulation
- docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
# replace the multi-arch reference with a specific, arm32v7 version. else docker will use the platform specific one,
# which is amd64.
- sed -i "s/FROM node:15/FROM node@$(docker manifest inspect node:15 | jq -r '.manifests [] | select (.platform.variant == "v7") | .digest')/g" Dockerfile
- sed -i "s/FROM python:3.7-slim/FROM python@$(docker manifest inspect python:3.7-slim | jq -r '.manifests [] | select (.platform.variant == "v7") | .digest')/g" Dockerfile
# travis_wait 60 tells travis to wait for up to 60 minutes - default is 20, which is too short
- travis_wait 60 docker build -f Dockerfile --tag=${DOCKER_REPO}:${TRAVIS_COMMIT}-arm32v7 .
- docker push ${DOCKER_REPO}:${TRAVIS_COMMIT}-arm32v7
env:
- DOCKER_CLI_EXPERIMENTAL=enabled # required for manifest support
on:
condition: '"${BUILD_DOCKER}" = 1'
- stage: publish_manifest
env:
- DOCKER_CLI_EXPERIMENTAL=enabled # required for manifest support
services:
- docker
before_install:
- true
install:
- true
after_success:
- true
script:
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
- docker manifest create ${DOCKER_REPO}:${TRAVIS_COMMIT} ${DOCKER_REPO}:${TRAVIS_COMMIT}-amd64 ${DOCKER_REPO}:${TRAVIS_COMMIT}-arm64v8 ${DOCKER_REPO}:${TRAVIS_COMMIT}-arm32v7
- docker manifest annotate ${DOCKER_REPO}:${TRAVIS_COMMIT} ${DOCKER_REPO}:${TRAVIS_COMMIT}-arm32v7 --os linux --arch arm --variant v7
- docker manifest annotate ${DOCKER_REPO}:${TRAVIS_COMMIT} ${DOCKER_REPO}:${TRAVIS_COMMIT}-arm64v8 --os linux --arch arm64 --variant v8
- docker manifest push --purge ${DOCKER_REPO}:${TRAVIS_COMMIT}
- |
if [ "${TRAVIS_BRANCH}" = "master" ]; then
echo "Master branch detected"
DOCKER_TAG="latest"
else
DOCKER_TAG=${TRAVIS_TAG}
fi
- |
if [ "${DOCKER_TAG}" != "" ]; then
echo "Create Tag ${DOCKER_TAG}"
docker manifest create ${DOCKER_REPO}:${DOCKER_TAG} ${DOCKER_REPO}:${TRAVIS_COMMIT}-amd64 ${DOCKER_REPO}:${TRAVIS_COMMIT}-arm64v8 ${DOCKER_REPO}:${TRAVIS_COMMIT}-arm32v7
docker manifest annotate ${DOCKER_REPO}:${DOCKER_TAG} ${DOCKER_REPO}:${TRAVIS_COMMIT}-arm32v7 --os linux --arch arm --variant v7
docker manifest annotate ${DOCKER_REPO}:${DOCKER_TAG} ${DOCKER_REPO}:${TRAVIS_COMMIT}-arm64v8 --os linux --arch arm64 --variant v8
docker manifest push --purge ${DOCKER_REPO}:${DOCKER_TAG}
else
echo "Not a tag and not on master, so not pushing tag/master specific manifest"
fi
on:
condition: '"${BUILD_DOCKER}" = 1'
before_install:
- sudo apt-get update -qq

View File

@ -41,6 +41,7 @@ RUN apt-get update \
libpq-dev \
libqpdf-dev \
libxml2 \
libxslt-dev \
optipng \
pngquant \
qpdf \