Merge pull request #794 from gradido/frontend_commit_hash

add commit hash with link to github into frontend
This commit is contained in:
einhornimmond 2021-09-20 13:54:16 +02:00 committed by GitHub
commit ec1b01d5d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 66 additions and 15 deletions

1
.env.local.dist Normal file
View File

@ -0,0 +1 @@
// for local .env entries

1
.env.shell Normal file
View File

@ -0,0 +1 @@
BUILD_COMMIT="$(git rev-parse HEAD)"

1
.gitignore vendored
View File

@ -5,3 +5,4 @@ messages.pot
.skeema .skeema
nbproject nbproject
.metadata .metadata
/.env

View File

@ -2,7 +2,10 @@
# For that to work, node v12.19.0 needs to be installed with nvm for root # 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 # 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 NPM_BIN=/root/.nvm/versions/node/v12.19.0/bin/npm

View File

@ -13,7 +13,6 @@ services:
environment: environment:
- NODE_ENV="development" - NODE_ENV="development"
# - DEBUG=true # - DEBUG=true
- NUXT_BUILD=/tmp/nuxt # avoid file permission issues when `rm -rf .nuxt/`
volumes: volumes:
# This makes sure the docker container has its own node modules. # 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 # Therefore it is possible to have a different node version on the host machine

View File

@ -22,13 +22,12 @@ services:
# Envs used in Dockerfile # Envs used in Dockerfile
# - DOCKER_WORKDIR="/app" # - DOCKER_WORKDIR="/app"
# - PORT=3000 # - PORT=3000
- BUILD_DATE # - BUILD_DATE="1970-01-01T00:00:00.00Z"
- BUILD_VERSION # - BUILD_VERSION="0.0.0.0"
- BUILD_COMMIT # - BUILD_COMMIT="0000000"
- NODE_ENV="production" - NODE_ENV="production"
# Application only envs # env_file:
#- HOST=0.0.0.0 # This is nuxt specific, alternative value is HOST=webapp # - ./.env
#env_file:
# - ./frontend/.env # - ./frontend/.env
######################################################### #########################################################

View File

@ -2,3 +2,4 @@ LOGIN_API_URL=http://localhost/login_api/
COMMUNITY_API_URL=http://localhost/api/ COMMUNITY_API_URL=http://localhost/api/
ALLOW_REGISTER=true ALLOW_REGISTER=true
GRAPHQL_URI=http://localhost:4000/graphql GRAPHQL_URI=http://localhost:4000/graphql
//BUILD_COMMIT=0000000

View File

@ -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 // Load Package Details for some default values
const pkg = require('../../package') 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 = { const environment = {
NODE_ENV: process.env.NODE_ENV, NODE_ENV: process.env.NODE_ENV,
DEBUG: process.env.NODE_ENV !== 'production' || false, DEBUG: process.env.NODE_ENV !== 'production' || false,
PRODUCTION: process.env.NODE_ENV === 'production' || false, PRODUCTION: process.env.NODE_ENV === 'production' || false,
ALLOW_REGISTER: process.env.ALLOW_REGISTER !== 'false',
} }
const server = { const server = {
@ -16,10 +23,15 @@ const server = {
GRAPHQL_URI: process.env.GRAPHQL_URI || 'http://localhost:4000/graphql', GRAPHQL_URI: process.env.GRAPHQL_URI || 'http://localhost:4000/graphql',
} }
const options = {
ALLOW_REGISTER: process.env.ALLOW_REGISTER !== 'false',
}
const CONFIG = { const CONFIG = {
...version,
...environment, ...environment,
...server, ...server,
APP_VERSION: pkg.version, ...options,
} }
export default CONFIG export default CONFIG

View File

@ -59,6 +59,21 @@ describe('ContentFooter', () => {
'https://github.com/gradido/gradido/releases/latest', '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', () => { describe('links to gradido.net', () => {

View File

@ -15,6 +15,13 @@
<a href="https://github.com/gradido/gradido/releases/latest" target="_blank"> <a href="https://github.com/gradido/gradido/releases/latest" target="_blank">
App version {{ version }} App version {{ version }}
</a> </a>
<a
v-if="hash"
:href="'https://github.com/gradido/gradido/commit/' + hash"
target="_blank"
>
({{ shortHash }})
</a>
</div> </div>
</b-col> </b-col>
</b-row> </b-row>
@ -59,6 +66,8 @@ export default {
return { return {
year: new Date().getFullYear(), year: new Date().getFullYear(),
version: CONFIG.APP_VERSION, version: CONFIG.APP_VERSION,
hash: CONFIG.BUILD_COMMIT,
shortHash: CONFIG.BUILD_COMMIT_SHORT,
} }
}, },
} }

View File

@ -1,5 +1,6 @@
const path = require('path') const path = require('path')
const dotenv = require('dotenv-webpack') const webpack = require('webpack')
const Dotenv = require('dotenv-webpack')
// vue.config.js // vue.config.js
module.exports = { module.exports = {
@ -23,8 +24,17 @@ module.exports = {
assets: path.join(__dirname, 'src/assets'), assets: path.join(__dirname, 'src/assets'),
}, },
}, },
// eslint-disable-next-line new-cap plugins: [
plugins: [new dotenv()], 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: { css: {
// Enable CSS source maps. // Enable CSS source maps.