From 91daec852f8471c64732a6560cee19b81488b48c Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 17 May 2020 10:02:36 +0200 Subject: [PATCH] Added parallel docker image multi-arch building --- .travis.yml | 45 ++++++++++++++++++++++------------- scripts/docker/build | 30 +++++++++++++++++++---- scripts/docker/install-docker | 12 ++++++++++ 3 files changed, 66 insertions(+), 21 deletions(-) create mode 100755 scripts/docker/install-docker diff --git a/.travis.yml b/.travis.yml index 18ca48f6..6b6be159 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,21 @@ +dist: bionic + language: node_js -node_js: - - "12.14.1" +jobs: + fast_finish: true + include: + - name: "Docker publish" + node_js: '12.14.1' + if: NOT type = pull_request + env: + - DOCKER_PUBLISH="true" + - name: "CI" + node_js: '12.14.1' + env: + - DOCKER_PUBLISH="false" + allow_failures: + - name: "Docker publish" cache: directories: @@ -11,35 +25,34 @@ services: - docker install: - - npm ci + - if [[ ${DOCKER_PUBLISH} == 'true' ]]; then sudo bash ./scripts/docker/install-docker ; fi + - if [[ ${DOCKER_PUBLISH} == 'false' ]]; then npm ci ; fi before_script: - - echo "Building commit range ${TRAVIS_COMMIT_RANGE}" - - export MUTATION_FILES=$(git diff ${TRAVIS_COMMIT_RANGE:-origin/master} --name-only | grep -E 'src\/(.*).(js|ts|jsx|tsx)$' | paste -sd ",") + - if [[ ${DOCKER_PUBLISH} == 'false' ]]; then echo "Building commit range ${TRAVIS_COMMIT_RANGE}" ; fi + - if [[ ${DOCKER_PUBLISH} == 'false' ]]; then export MUTATION_FILES=$(git diff ${TRAVIS_COMMIT_RANGE:-origin/master} --name-only | grep -E 'src\/(.*).(js|ts|jsx|tsx)$' | paste -sd ",") ; fi script: - - npm run lint - - npm run test:ci - - if [[ $TRAVIS_PULL_REQUEST != 'false' ]]; then docker build -t shlink-web-client:test . ; fi - - if [[ $TRAVIS_PULL_REQUEST != 'false' ]]; then npm run mutate:ci ; fi + - if [[ ${DOCKER_PUBLISH} == 'true' ]]; then bash ./scripts/docker/build ; fi + - if [[ ${DOCKER_PUBLISH} == 'false' ]]; then npm run lint ; fi + - if [[ ${DOCKER_PUBLISH} == 'false' ]]; then npm run test:ci ; fi + - if [[ ${DOCKER_PUBLISH} == 'false' ]]; then docker build -t shlink-web-client:test . ; fi + - if [[ ${DOCKER_PUBLISH} == 'false' ]]; then npm run mutate:ci ; fi after_success: - - node_modules/.bin/ocular coverage/clover.xml + - if [[ ${DOCKER_PUBLISH} == 'false' ]]; then node_modules/.bin/ocular coverage/clover.xml ; fi # Before deploying, build dist file for current travis tag before_deploy: - - if [[ ! -z $TRAVIS_TAG ]]; then npm run build ${TRAVIS_TAG#?} ; fi + - if [[ ! -z $TRAVIS_TAG && ${DOCKER_PUBLISH} == 'false' ]]; then npm run build ${TRAVIS_TAG#?} ; fi deploy: - - provider: script - script: bash ./scripts/docker/build - on: - all_branches: true - condition: $TRAVIS_PULL_REQUEST == 'false' - provider: releases api_key: secure: jBvPwC7EAbViaNR83rwMSt5XQDK0Iu9rgvEMa7GoyShbHcvUCCPd73Tu9quNpKi6NKsDY3INHgtch3vgonjGNGDGJ+yDyIBzXcvsAX2x3UcHpRbgY12uiINVmQxBI1+OVQB016Nm+cKC/i5Z36K4EmDbYfo+MrKndngM6AjcQFTwI8EwniIMaQgg4gNes//K8NhP5u0c3gwG+Q6jEGnq6uH3kcRgh6/epIZYpQyxjqWqKwF77sgcYj+X2Nf6XxtB5neuCi301UKLoLx8G0skh/Lm6KAIO4s9iIhIFa3UpoF21Ka0TxLpd2JxalLryCnFGlWWE6lxC9Htmc0TeRowJQlGdJXCskJ37xT9MljKY0fwNMu06VS/FUgykuCv+jP3zQu51pKu7Ew7+WeNPjautoOTu54VkdGyHcf2ThBNEyJQuiEwAQe4u7yAxY6R5ovEdvHBSIg4w1E5/Mxy5SMTCUlIAv6H7QQ1X9Z/zJm9HH5KeKz5tsHvQ/RIdSpgHXq/tC8o4Yup/LCFucXfrgvy/8pJoO1UpOlmvm62974NFfo0EG5YWwv6brUqz3QXpMjb8sWqgjltYMYJX3J7WZ34rIc+zt4NAmfhqgczaOC4pUGCiJ8jX3rMWIaQRn1AJ+5V337jL9fNDpTHny4phQjHrMJ1e0HZuNp0Xb5Q8wgqDPM= file: "./dist/shlink-web-client_${TRAVIS_TAG#?}_dist.zip" skip_cleanup: true on: + all_branches: true + condition: ${DOCKER_PUBLISH} == 'false' tags: true diff --git a/scripts/docker/build b/scripts/docker/build index 00245e67..657b9b0a 100755 --- a/scripts/docker/build +++ b/scripts/docker/build @@ -1,13 +1,33 @@ #!/bin/bash + set -e +PLATFORMS="linux/arm/v7,linux/arm64/v8,linux/amd64" +# PLATFORMS="linux/amd64" +DOCKER_IMAGE="shlinkio/shlink-web-client" +BUILDX_VER=v0.4.1 +export DOCKER_CLI_EXPERIMENTAL=enabled + +mkdir -vp ~/.docker/cli-plugins/ ~/dockercache +curl --silent -L "https://github.com/docker/buildx/releases/download/${BUILDX_VER}/buildx-${BUILDX_VER}.linux-amd64" > ~/.docker/cli-plugins/docker-buildx +chmod a+x ~/.docker/cli-plugins/docker-buildx + +docker buildx create --use + echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin if [[ -z $TRAVIS_TAG ]]; then - docker build -t shlinkio/shlink-web-client:latest . - docker push shlinkio/shlink-web-client:latest + docker buildx build --push \ + --platform ${PLATFORMS} \ + -t ${DOCKER_IMAGE}:latest . + else - docker build --build-arg VERSION=${TRAVIS_TAG#?} -t shlinkio/shlink-web-client:${TRAVIS_TAG#?} -t shlinkio/shlink-web-client:stable . - docker push shlinkio/shlink-web-client:${TRAVIS_TAG#?} - docker push shlinkio/shlink-web-client:stable + TAGS="-t ${DOCKER_IMAGE}:${TRAVIS_TAG#?}" + # Push stable tag only if this is not an alpha or beta release + [[ $TRAVIS_TAG != *"alpha"* && $TRAVIS_TAG != *"beta"* ]] && TAGS="${TAGS} -t ${DOCKER_IMAGE}:stable" + + docker buildx build --push \ + --build-arg SHLINK_VERSION=${TRAVIS_TAG#?} \ + --platform ${PLATFORMS} \ + ${TAGS} . fi diff --git a/scripts/docker/install-docker b/scripts/docker/install-docker new file mode 100755 index 00000000..58289a16 --- /dev/null +++ b/scripts/docker/install-docker @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +set -ex + +# install latest docker version +curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - +add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" +apt-get update +apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce + +# enable multiarch execution +docker run --rm --privileged multiarch/qemu-user-static --reset -p yes