Commit 140dc847 authored by Matija Obreza's avatar Matija Obreza
Browse files

Record git revision

- as window.softwareCommit
- /COMMITHASH asset
parent 551c813b
......@@ -17,6 +17,8 @@ stages:
- npm install
# Needs to be uncommented if node:version us updated
- npm rebuild node-sass
# Add git
- apk add --no-cache git
artifacts:
name: "${CI_PROJECT_NAME}-${CI_COMMIT_REF_NAME}"
expire_in: 1 day
......
......@@ -7,6 +7,8 @@ const HtmlWebpackExcludeAssetsPlugin = require('html-webpack-exclude-assets-plug
const WebpackChunkHash = require("webpack-chunk-hash");
const ManifestPlugin = require('webpack-manifest-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const GitRevisionPlugin = require('git-revision-webpack-plugin');
var gitRevisionPlugin = new GitRevisionPlugin();
// devserver configuration
const HOST = process.env.HOST || 'localhost';
......@@ -213,6 +215,9 @@ module.exports = {
minChunks: Infinity
}),*/
// Git revision
new GitRevisionPlugin(),
// MD5 chunkhash
new WebpackChunkHash(),
......@@ -231,7 +236,9 @@ module.exports = {
template: './entrypoints/index.html',
chunksSortMode: sortedChunks(['vendor', 'common', 'catalog']),
chunks: ['vendor', 'common', 'catalog'],
favicon: 'favicon.ico'
favicon: 'favicon.ico',
version: gitRevisionPlugin.version(),
commithash: gitRevisionPlugin.commithash(),
}),
new HtmlWebpackPlugin({
title: 'Genesys', // The title to use for the generated HTML document
......@@ -241,7 +248,7 @@ module.exports = {
chunks: [],
template: './server/ssr-error.html',
favicon: 'favicon.ico'
}),
}),
// Defer/Async scripts
new ScriptExtHtmlWebpackPlugin({
......@@ -259,7 +266,9 @@ module.exports = {
template: './server/ssr-template.html',
chunksSortMode: sortedChunks(['vendor', 'common', 'catalog']),
chunks: ['vendor', 'common', 'catalog'],
favicon: 'favicon.ico'
favicon: 'favicon.ico',
version: gitRevisionPlugin.version(),
commithash: gitRevisionPlugin.commithash(),
}),
......
......@@ -7,6 +7,8 @@ var postcssNext = require('postcss-cssnext');
const GOOGLE_CLIENT_ID = process.env.GOOGLE_CLIENT_ID;
const commonConfig = require('./webpack-base.config.js');
const GitRevisionPlugin = require('git-revision-webpack-plugin');
var gitRevisionPlugin = new GitRevisionPlugin();
module.exports = webpackMerge(commonConfig, {
......@@ -32,7 +34,9 @@ module.exports = webpackMerge(commonConfig, {
}),
new webpack.DefinePlugin({
'process.env': {
GOOGLE_CLIENT_ID: JSON.stringify(GOOGLE_CLIENT_ID)
GOOGLE_CLIENT_ID: JSON.stringify(GOOGLE_CLIENT_ID),
PROJECT_VERSION: JSON.stringify(gitRevisionPlugin.version()),
PROJECT_COMMITHASH: JSON.stringify(gitRevisionPlugin.commithash()),
}
}),
// hot module replacement for webpack-dev-server
......
......@@ -5,6 +5,8 @@ const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const HtmlWebpackExcludeAssetsPlugin = require('html-webpack-exclude-assets-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const GitRevisionPlugin = require('git-revision-webpack-plugin');
var gitRevisionPlugin = new GitRevisionPlugin();
const commonConfig = require('./webpack-base.config.js');
......@@ -27,7 +29,9 @@ module.exports = webpackMerge(commonConfig, {
// https://facebook.github.io/react/docs/optimizing-performance.html#use-the-production-build
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
NODE_ENV: JSON.stringify('production'),
PROJECT_VERSION: JSON.stringify(gitRevisionPlugin.version()),
PROJECT_COMMITHASH: JSON.stringify(gitRevisionPlugin.commithash()),
}
}),
......
......@@ -19,6 +19,8 @@
__PRELOADED_STATE__ = undefined;
window.initialLanguage = undefined;
window.initialI18nStore = undefined;
window.softwareVersion = <%= JSON.stringify(htmlWebpackPlugin.options.version) %>;
window.softwareCommit = <%= JSON.stringify(htmlWebpackPlugin.options.commithash) %>;
</script>
</body>
......
......@@ -6080,6 +6080,12 @@
}
}
},
"git-revision-webpack-plugin": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/git-revision-webpack-plugin/-/git-revision-webpack-plugin-3.0.3.tgz",
"integrity": "sha512-B2ixM0fY7VgR61ZRSXYrh0R57Er7RY+CZb+fja5OFe21Y5o9GgzQanMgdlcBwWZ+LoOVqxBogbDutTTYMXQDWw==",
"dev": true
},
"glob": {
"version": "7.1.2",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz",
......
......@@ -50,6 +50,18 @@ app.use(compression());
app.get('/robots.txt', robots);
// Proxy all requests starting with /proxy
app.use('/proxy', httpProxy);
// Prevent access to manifest.json
app.use(/^\/manifest.json$/, (req, res) => {
res.status(403).set('Content-Type', 'text/plain').send('Access denied.');
});
// Serve Git commithash
app.use(/^\/COMMITHASH$/, express.static(path.join('../assets'), {
etag: true,
maxAge: '0',
index: false,
redirect: false,
immutable: true,
}));
// Serve static resources (this should be the only thing publicly accessible)
app.use(express.static(path.join('../assets'), {
etag: true,
......
......@@ -22,6 +22,8 @@
__PRELOADED_STATE__ = SERVER_RENDERED_STATE;
window.initialLanguage = SERVER_RENDERED_LANG;
window.initialI18nStore = SERVER_RENDERED_I18NSTORE;
window.softwareVersion = <%= JSON.stringify(htmlWebpackPlugin.options.version) %>;
window.softwareCommit = <%= JSON.stringify(htmlWebpackPlugin.options.commithash) %>;
</script>
</body>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment