From 38fc402b16b25378e9f5fedea985a6b05f44d5a8 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Fri, 20 Mar 2020 07:12:07 +0100 Subject: [PATCH 1/2] Improved docker build script to avoid duplicating code --- scripts/docker/build | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/docker/build b/scripts/docker/build index 8331532e..48b49934 100755 --- a/scripts/docker/build +++ b/scripts/docker/build @@ -3,12 +3,12 @@ set -e echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin -# If a tag exists, build both that tag and stable -if [[ ! -z $TRAVIS_TAG ]]; then - docker build --build-arg VERSION=${TRAVIS_TAG#?} -t shlinkio/shlink-web-client:${TRAVIS_TAG#?} -t shlinkio/shlink-web-client:stable . +if [[ -z $TRAVIS_TAG ]]; then + docker build -t shlinkio/shlink-web-client:latest . +else + docker build --build-arg VERSION=${TRAVIS_TAG#?} -t shlinkio/shlink-web-client:${TRAVIS_TAG#?} -t shlinkio/shlink-web-client:stable -t shlinkio/shlink-web-client:latest . docker push shlinkio/shlink-web-client:${TRAVIS_TAG#?} docker push shlinkio/shlink-web-client:stable fi -docker build -t shlinkio/shlink-web-client:latest . docker push shlinkio/shlink-web-client:latest From b5a188e802863045f6f93f10c219885d8642fa61 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Fri, 20 Mar 2020 09:12:43 +0100 Subject: [PATCH 2/2] Improved building process so that already generated dist files are reused when building docker image is possible --- .dockerignore | 1 - .travis.yml | 2 +- Dockerfile | 8 +++++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.dockerignore b/.dockerignore index 16a99eb2..29f4e6b1 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,7 +1,6 @@ ./.github ./build ./coverage -./dist ./node_modules ./test ./shlink-web-client.gif diff --git a/.travis.yml b/.travis.yml index 58a3ad4a..bb6c5f63 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,7 +28,7 @@ after_success: # Before deploying, build dist file for current travis tag before_deploy: - - npm run build ${TRAVIS_TAG#?} + - if [[ ! -z $TRAVIS_TAG ]]; then npm run build ${TRAVIS_TAG#?} ; fi deploy: - provider: script diff --git a/Dockerfile b/Dockerfile index 39e2368d..a3ec3090 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,13 @@ FROM node:12.14.1-alpine as node COPY . /shlink-web-client ARG VERSION="latest" ENV VERSION ${VERSION} -RUN cd /shlink-web-client && npm install && npm run build -- ${VERSION} --no-dist +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 FROM nginx:1.17.7-alpine LABEL maintainer="Alejandro Celaya "