From 4a6dd66ecd733c56e92db461d7871f5e1e47e198 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Thu, 5 Mar 2020 13:37:07 +0100 Subject: [PATCH] Added scripts to pass version when building docker image --- Dockerfile | 4 +++- hooks/build | 10 ++++++++++ scripts/build.js | 3 ++- 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100755 hooks/build diff --git a/Dockerfile b/Dockerfile index 02684ce2..39e2368d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,8 @@ FROM node:12.14.1-alpine as node COPY . /shlink-web-client -RUN cd /shlink-web-client && npm install && npm run build +ARG VERSION="latest" +ENV VERSION ${VERSION} +RUN cd /shlink-web-client && npm install && npm run build -- ${VERSION} --no-dist FROM nginx:1.17.7-alpine LABEL maintainer="Alejandro Celaya " diff --git a/hooks/build b/hooks/build new file mode 100755 index 00000000..f912acdd --- /dev/null +++ b/hooks/build @@ -0,0 +1,10 @@ +#!/bin/bash +set -ex + +if [[ ${SOURCE_BRANCH} == 'master' ]]; then + SHLINK_WEB_CLIENT_RELEASE='latest' +else + SHLINK_WEB_CLIENT_RELEASE=${SOURCE_BRANCH#?} +fi + +docker build --build-arg VERSION=${SHLINK_WEB_CLIENT_RELEASE} -t ${IMAGE_NAME} . diff --git a/scripts/build.js b/scripts/build.js index 2178b7b5..f76af2d4 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -44,6 +44,7 @@ if (!checkRequiredFiles([ paths.appHtml, paths.appIndexJs ])) { const argvSliceStart = 2; const argv = process.argv.slice(argvSliceStart); const writeStatsJson = argv.indexOf('--stats') !== -1; +const withoutDist = argv.indexOf('--no-dist') !== -1; const { version, hasVersion } = getVersionFromArgs(argv); // Generate configuration @@ -102,7 +103,7 @@ checkBrowsers(paths.appPath, isInteractive) process.exit(1); } ) - .then(() => hasVersion && zipDist(version)) + .then(() => hasVersion && !withoutDist && zipDist(version)) .catch((err) => { if (err && err.message) { console.log(err.message);