diff --git a/.env.local.dist b/.env.local.dist new file mode 100644 index 000000000..951a04b94 --- /dev/null +++ b/.env.local.dist @@ -0,0 +1 @@ +// for local .env entries \ No newline at end of file diff --git a/.env.shell b/.env.shell new file mode 100644 index 000000000..ac6181fc5 --- /dev/null +++ b/.env.shell @@ -0,0 +1 @@ +BUILD_COMMIT="$(git rev-parse HEAD)" \ No newline at end of file diff --git a/.gitignore b/.gitignore index 02347691f..a5dadd281 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ messages.pot .skeema nbproject .metadata +/.env diff --git a/deployment/bare_metal/build_frontend.sh b/deployment/bare_metal/build_frontend.sh index fc0feb747..4b3a8a444 100755 --- a/deployment/bare_metal/build_frontend.sh +++ b/deployment/bare_metal/build_frontend.sh @@ -2,7 +2,10 @@ # For that to work, node v12.19.0 needs to be installed with nvm for root # or NPM_BIN Path and NVM_DIR must be adjusted -cd /var/www/html/gradido/frontend +cd /var/www/html/gradido +eval "echo \"$(cat .env.shell)\"" > .env +export BUILD_COMMIT="$(git rev-parse HEAD)" +cd frontend NPM_BIN=/root/.nvm/versions/node/v12.19.0/bin/npm diff --git a/docker-compose.override.yml b/docker-compose.override.yml index 5eb808b99..84906a5a9 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -13,7 +13,6 @@ services: environment: - NODE_ENV="development" # - DEBUG=true - - NUXT_BUILD=/tmp/nuxt # avoid file permission issues when `rm -rf .nuxt/` volumes: # This makes sure the docker container has its own node modules. # Therefore it is possible to have a different node version on the host machine diff --git a/docker-compose.yml b/docker-compose.yml index 70d36521e..652daae13 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -22,14 +22,13 @@ services: # Envs used in Dockerfile # - DOCKER_WORKDIR="/app" # - PORT=3000 - - BUILD_DATE - - BUILD_VERSION - - BUILD_COMMIT + # - BUILD_DATE="1970-01-01T00:00:00.00Z" + # - BUILD_VERSION="0.0.0.0" + # - BUILD_COMMIT="0000000" - NODE_ENV="production" - # Application only envs - #- HOST=0.0.0.0 # This is nuxt specific, alternative value is HOST=webapp - #env_file: - # - ./frontend/.env + # env_file: + # - ./.env + # - ./frontend/.env ######################################################### ## MARIADB ############################################## diff --git a/frontend/.env.dist b/frontend/.env.dist index a22b31307..1252faf5b 100644 --- a/frontend/.env.dist +++ b/frontend/.env.dist @@ -2,3 +2,4 @@ LOGIN_API_URL=http://localhost/login_api/ COMMUNITY_API_URL=http://localhost/api/ ALLOW_REGISTER=true GRAPHQL_URI=http://localhost:4000/graphql +//BUILD_COMMIT=0000000 \ No newline at end of file diff --git a/frontend/src/config/index.js b/frontend/src/config/index.js index dd35eb185..54c2c7aeb 100644 --- a/frontend/src/config/index.js +++ b/frontend/src/config/index.js @@ -1,13 +1,20 @@ -// ATTENTION: DO NOT PUT ANY SECRETS IN HERE (or the .env) +// ATTENTION: DO NOT PUT ANY SECRETS IN HERE (or the .env). +// The whole contents is exposed to the client // Load Package Details for some default values const pkg = require('../../package') +const version = { + APP_VERSION: pkg.version, + 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 || '0000000').substr(0, 7), +} + const environment = { NODE_ENV: process.env.NODE_ENV, DEBUG: process.env.NODE_ENV !== 'production' || false, PRODUCTION: process.env.NODE_ENV === 'production' || false, - ALLOW_REGISTER: process.env.ALLOW_REGISTER !== 'false', } const server = { @@ -16,10 +23,15 @@ const server = { GRAPHQL_URI: process.env.GRAPHQL_URI || 'http://localhost:4000/graphql', } +const options = { + ALLOW_REGISTER: process.env.ALLOW_REGISTER !== 'false', +} + const CONFIG = { + ...version, ...environment, ...server, - APP_VERSION: pkg.version, + ...options, } export default CONFIG diff --git a/frontend/src/views/Layout/ContentFooter.spec.js b/frontend/src/views/Layout/ContentFooter.spec.js index 8d0c6dfbd..4b360d581 100644 --- a/frontend/src/views/Layout/ContentFooter.spec.js +++ b/frontend/src/views/Layout/ContentFooter.spec.js @@ -59,6 +59,21 @@ describe('ContentFooter', () => { 'https://github.com/gradido/gradido/releases/latest', ) }) + + it('has last commit hash', async () => { + wrapper.setData({ shortHash: 'ACCEDED' }) + wrapper.setData({ hash: 'ACCEDEDC001D00DC001D00DC001D00DC001CAFA' }) + await wrapper.vm.$nextTick() + expect(wrapper.find('div.copyright').findAll('a').at(2).text()).toEqual('(ACCEDED)') + }) + + it('links to last release commit', async () => { + wrapper.setData({ hash: 'ACCEDEDC001D00DC001D00DC001D00DC001CAFA' }) + await wrapper.vm.$nextTick() + expect(wrapper.find('div.copyright').findAll('a').at(2).attributes('href')).toEqual( + 'https://github.com/gradido/gradido/commit/ACCEDEDC001D00DC001D00DC001D00DC001CAFA', + ) + }) }) describe('links to gradido.net', () => { diff --git a/frontend/src/views/Layout/ContentFooter.vue b/frontend/src/views/Layout/ContentFooter.vue index 09a2418fd..4350e3f55 100755 --- a/frontend/src/views/Layout/ContentFooter.vue +++ b/frontend/src/views/Layout/ContentFooter.vue @@ -15,6 +15,13 @@ App version {{ version }} + + ({{ shortHash }}) + @@ -59,6 +66,8 @@ export default { return { year: new Date().getFullYear(), version: CONFIG.APP_VERSION, + hash: CONFIG.BUILD_COMMIT, + shortHash: CONFIG.BUILD_COMMIT_SHORT, } }, } diff --git a/frontend/vue.config.js b/frontend/vue.config.js index 9fffda28c..45903e9cf 100644 --- a/frontend/vue.config.js +++ b/frontend/vue.config.js @@ -1,5 +1,6 @@ const path = require('path') -const dotenv = require('dotenv-webpack') +const webpack = require('webpack') +const Dotenv = require('dotenv-webpack') // vue.config.js module.exports = { @@ -23,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.