env/process.env working in docker & without

This commit is contained in:
Ulf Gebhardt 2021-09-15 14:30:11 +02:00
parent 9cf1221040
commit f9af5f961f
No known key found for this signature in database
GPG Key ID: 81308EFE29ABFEBD
3 changed files with 15 additions and 22 deletions

View File

@ -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}"

View File

@ -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 = {

View File

@ -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.