diff --git a/frontend/Dockerfile b/frontend/Dockerfile index b222d7f1a..5ec90fe81 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -8,18 +8,14 @@ FROM node:12.19.0-alpine3.10 as base ENV DOCKER_WORKDIR="/app" ## We Cannot do `$(date -u +'%Y-%m-%dT%H:%M:%SZ')` here so we use unix timestamp=0 ENV BUILD_DATE="1970-01-01T00:00:00.00Z" -ENV VUE_APP_BUILD_DATE="${BUILD_DATE}" ## We cannot do $(npm run version).${BUILD_NUMBER} here so we default to 0.0.0.0 ENV BUILD_VERSION="0.0.0.0" -ENV VUE_APP_BUILD_VERSION="${BUILD_VERSION}" ## We cannot do `$(git rev-parse --short HEAD)` here so we default to 0000000 ENV BUILD_COMMIT="0000000" -ENV VUE_APP_BUILD_COMMIT="${BUILD_COMMIT}" ## SET NODE_ENV ENV NODE_ENV="production" ## App relevant Envs ENV PORT="3000" -# TODO ENV VUE_APP_PORT="${PORT}" # Labels LABEL org.label-schema.build-date="${BUILD_DATE}" diff --git a/frontend/src/config/index.js b/frontend/src/config/index.js index 1409db9ad..54c2c7aeb 100644 --- a/frontend/src/config/index.js +++ b/frontend/src/config/index.js @@ -6,20 +6,9 @@ const pkg = require('../../package') const version = { APP_VERSION: pkg.version, - BUILD_COMMIT: - process.env.BUILD_COMMIT || - // the check for undefined is because of a conflict between webpack-dotenv and vue cli env filtering - (process.env.VUE_APP_BUILD_COMMIT !== 'undefined' ? process.env.VUE_APP_BUILD_COMMIT : null) || - null, + BUILD_COMMIT: process.env.BUILD_COMMIT || null, // self reference of `version.BUILD_COMMIT` is not possible at this point, hence the duplicate code - BUILD_COMMIT_SHORT: ( - process.env.BUILD_COMMIT || - (process.env.VUE_APP_BUILD_COMMIT !== 'undefined' ? process.env.VUE_APP_BUILD_COMMIT : null) || - '0000000' - ).substr(0, 7), - // unused - // BUILD_DATE: process.env.BUILD_DATE || process.env.VUE_APP_BUILD_DATE || '1970-01-01T00:00:00.00Z', - // BUILD_VERSION: process.env.BUILD_VERSION || process.env.VUE_APP_BUILD_VERSION || '0.0.0.0', + BUILD_COMMIT_SHORT: (process.env.BUILD_COMMIT || '0000000').substr(0, 7), } const environment = { diff --git a/frontend/vue.config.js b/frontend/vue.config.js index 698aca1de..45903e9cf 100644 --- a/frontend/vue.config.js +++ b/frontend/vue.config.js @@ -1,7 +1,6 @@ const path = require('path') -const dotenv = require('dotenv-webpack') - -process.env.VUE_APP_BUILD_COMMIT = process.env.BUILD_COMMIT +const webpack = require('webpack') +const Dotenv = require('dotenv-webpack') // vue.config.js module.exports = { @@ -25,8 +24,17 @@ module.exports = { assets: path.join(__dirname, 'src/assets'), }, }, - // eslint-disable-next-line new-cap - plugins: [new dotenv()], + plugins: [ + new Dotenv(), + new webpack.DefinePlugin({ + // Those are Environment Variables transmitted via Docker + // 'process.env.DOCKER_WORKDIR': JSON.stringify(process.env.DOCKER_WORKDIR), + // 'process.env.BUILD_DATE': JSON.stringify(process.env.BUILD_DATE), + // 'process.env.BUILD_VERSION': JSON.stringify(process.env.BUILD_VERSION), + 'process.env.BUILD_COMMIT': JSON.stringify(process.env.BUILD_COMMIT), + // 'process.env.PORT': JSON.stringify(process.env.PORT), + }), + ], }, css: { // Enable CSS source maps.