From 91daec852f8471c64732a6560cee19b81488b48c Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 17 May 2020 10:02:36 +0200 Subject: [PATCH 1/6] 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 From 544384d85ebd8721d5cf153d5e7cd74899281cf5 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 17 May 2020 10:04:05 +0200 Subject: [PATCH 2/6] Updated runtimne versions --- .scrutinizer.yml | 2 +- .travis.yml | 4 ++-- Dockerfile | 4 ++-- docker-compose.yml | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index e7caa7ac..c78907be 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -1,6 +1,6 @@ build: environment: - node: v12.14.1 + node: v12.16.3 tools: external_code_coverage: timeout: 1200 diff --git a/.travis.yml b/.travis.yml index 6b6be159..c22e2261 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,12 +6,12 @@ jobs: fast_finish: true include: - name: "Docker publish" - node_js: '12.14.1' + node_js: '12.16.3' if: NOT type = pull_request env: - DOCKER_PUBLISH="true" - name: "CI" - node_js: '12.14.1' + node_js: '12.16.3' env: - DOCKER_PUBLISH="false" allow_failures: diff --git a/Dockerfile b/Dockerfile index a3ec3090..7c2adc9d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:12.14.1-alpine as node +FROM node:12.16.3-alpine as node COPY . /shlink-web-client ARG VERSION="latest" ENV VERSION ${VERSION} @@ -10,7 +10,7 @@ RUN cd /shlink-web-client && \ # If no dist file exsts, build from scratch if [[ ! -f ${DIST_FILE} ]]; then npm install && npm run build -- ${VERSION} --no-dist ; fi -FROM nginx:1.17.7-alpine +FROM nginx:1.17.10-alpine LABEL maintainer="Alejandro Celaya " RUN rm -r /usr/share/nginx/html && rm /etc/nginx/conf.d/default.conf COPY config/docker/nginx.conf /etc/nginx/conf.d/default.conf diff --git a/docker-compose.yml b/docker-compose.yml index 47f8cbfe..301104b2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,7 @@ version: '3' services: shlink_web_client_node: container_name: shlink_web_client_node - image: node:12.14.1-alpine + image: node:12.16.3-alpine command: /bin/sh -c "cd /home/shlink/www && npm install && npm run start" volumes: - ./:/home/shlink/www From 68253c3bc461c8370b3040b98036590d17007dd5 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 17 May 2020 10:12:39 +0200 Subject: [PATCH 3/6] Disabled multi-arch building until everything is compatible --- scripts/docker/build | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/docker/build b/scripts/docker/build index 657b9b0a..278d6e0e 100755 --- a/scripts/docker/build +++ b/scripts/docker/build @@ -2,8 +2,8 @@ set -e -PLATFORMS="linux/arm/v7,linux/arm64/v8,linux/amd64" -# PLATFORMS="linux/amd64" +#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 From 0a3a97242b71e646f0377b9ad1f39b05be990c56 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 17 May 2020 10:13:33 +0200 Subject: [PATCH 4/6] Simplified docker image building, as it will now be run in a different job as the dist file release --- .dockerignore | 1 + Dockerfile | 7 +------ 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.dockerignore b/.dockerignore index 29f4e6b1..63f72310 100644 --- a/.dockerignore +++ b/.dockerignore @@ -4,3 +4,4 @@ ./node_modules ./test ./shlink-web-client.gif +./dist diff --git a/Dockerfile b/Dockerfile index 7c2adc9d..674afa8b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,12 +3,7 @@ COPY . /shlink-web-client ARG VERSION="latest" ENV VERSION ${VERSION} RUN cd /shlink-web-client && \ - UNCOMPRESSED="shlink-web-client_${VERSION}_dist" && \ - DIST_FILE="./dist/${UNCOMPRESSED}.zip" && \ - # If a dist file already exists, just unzip it - if [[ -f ${DIST_FILE} ]]; then unzip ${DIST_FILE} && mv ./${UNCOMPRESSED} ./build ; fi && \ - # If no dist file exsts, build from scratch - if [[ ! -f ${DIST_FILE} ]]; then npm install && npm run build -- ${VERSION} --no-dist ; fi + npm install && npm run build -- ${VERSION} --no-dist FROM nginx:1.17.10-alpine LABEL maintainer="Alejandro Celaya " From f36e42d9c15da8910a54e515889b773ccfc43eca Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 17 May 2020 10:16:53 +0200 Subject: [PATCH 5/6] Fixed travis config error --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c22e2261..9791f204 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ jobs: env: - DOCKER_PUBLISH="true" - name: "CI" - node_js: '12.16.3' + node_js: '12.16.3' env: - DOCKER_PUBLISH="false" allow_failures: From 4565a64cd895cde485d40e48d744a1d7a04df8a1 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 17 May 2020 10:28:49 +0200 Subject: [PATCH 6/6] Rolled back node version for scrutinizer --- .scrutinizer.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index c78907be..e7caa7ac 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -1,6 +1,6 @@ build: environment: - node: v12.16.3 + node: v12.14.1 tools: external_code_coverage: timeout: 1200