A better URL for checking the deployed version (#2366)
This commit is contained in:
Родитель
5e6d3293f5
Коммит
fd669beb91
25
README.md
25
README.md
|
@ -242,6 +242,31 @@ Example: Building and running a production instance of the admin app:
|
|||
NODE_APP_INSTANCE=admin NODE_ENV=production npm run build && npm run start
|
||||
```
|
||||
|
||||
## What version is deployed?
|
||||
|
||||
You can check to see what commit of `addons-frontend` is deployed by
|
||||
making a request like this:
|
||||
|
||||
````
|
||||
curl https://addons-dev.allizom.org/__frontend_version__
|
||||
{
|
||||
"build" : "https://circleci.com/gh/mozilla/addons-server/6550",
|
||||
"commit" : "87f49a40ee7a5e87d9b9efde8e91b9019e8b13d1",
|
||||
"source" : "https://github.com/mozilla/addons-server",
|
||||
"version" : ""
|
||||
}
|
||||
````
|
||||
|
||||
This will return a 415 response if a `version.json` file doesn't exist
|
||||
in the root directory. This file is typically generated by the deploy process.
|
||||
|
||||
For consistency with monitoring scripts, the same data can be retrieved
|
||||
at this URL:
|
||||
|
||||
````
|
||||
curl https://addons-dev.allizom.org/__version__
|
||||
````
|
||||
|
||||
## Overview and rationale
|
||||
|
||||
This project will hold distinct front-ends e.g:
|
||||
|
|
|
@ -46,6 +46,7 @@ module.exports = {
|
|||
'blocklist',
|
||||
'static',
|
||||
'user-media',
|
||||
'__frontend_version__',
|
||||
'__version__',
|
||||
],
|
||||
|
||||
|
@ -76,6 +77,7 @@ module.exports = {
|
|||
'sunbird',
|
||||
'static',
|
||||
'user-media',
|
||||
'__frontend_version__',
|
||||
'__version__',
|
||||
],
|
||||
// These URLs are exceptions to our trailing slash URL redirects; if we
|
||||
|
|
|
@ -37,6 +37,7 @@ import WebpackIsomorphicToolsConfig from './webpack-isomorphic-tools-config';
|
|||
|
||||
|
||||
const env = config.util.getEnv('NODE_ENV');
|
||||
// This is a magic file that gets written by deployment scripts.
|
||||
const version = path.join(config.get('basePath'), 'version.json');
|
||||
const isDeployed = config.get('isDeployed');
|
||||
const isDevelopment = config.get('isDevelopment');
|
||||
|
@ -185,17 +186,23 @@ function baseServer(routes, createStore, { appInstanceName = appName } = {}) {
|
|||
app.use(Express.static(path.join(config.get('basePath'), 'dist')));
|
||||
}
|
||||
|
||||
// Return version information as json
|
||||
app.get('/__version__', (req, res) => {
|
||||
fs.stat(version, (err) => {
|
||||
if (err) {
|
||||
// Show version/commit information as JSON.
|
||||
function viewVersion(req, res) {
|
||||
fs.stat(version, (error) => {
|
||||
if (error) {
|
||||
log.error(`Could not stat version file ${version}: ${error}`);
|
||||
res.sendStatus(415);
|
||||
} else {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
fs.createReadStream(version).pipe(res);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Following the ops monitoring convention, return version info at this URL.
|
||||
app.get('/__version__', viewVersion);
|
||||
// For AMO, this helps differentiate from /__version__ served by addons-server.
|
||||
app.get('/__frontend_version__', viewVersion);
|
||||
|
||||
// Return 200 for csp reports - this will need to be overridden when deployed.
|
||||
app.post('/__cspreport__', (req, res) => res.status(200).end('ok'));
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
import { assert } from 'chai';
|
||||
import config from 'config';
|
||||
import request from 'supertest-as-promised';
|
||||
|
||||
import { checkSRI, parseCSP, runTestServer } from '../helpers';
|
||||
|
@ -62,4 +66,45 @@ describe('AMO GET Requests', () => {
|
|||
assert.equal(res.header.location,
|
||||
'/en-US/firefox/search/');
|
||||
}));
|
||||
|
||||
describe('application version views', () => {
|
||||
const versionFile = path.join(config.basePath, 'version.json');
|
||||
|
||||
const versionData = {
|
||||
build: 'https://circleci.com/gh/mozilla/addons-server/6550',
|
||||
source: 'https://github.com/mozilla/addons-server',
|
||||
// This is typically blank for some reason.
|
||||
version: '',
|
||||
commit: '87f49a40ee7a5e87d9b9efde8e91b9019e8b13d1',
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
// Simulate how ops writes a version file in our project root.
|
||||
fs.writeFileSync(versionFile, JSON.stringify(versionData));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fs.unlinkSync(versionFile);
|
||||
});
|
||||
|
||||
it('should respond to __version__ with version info', () => {
|
||||
return request(app)
|
||||
.get('/__version__')
|
||||
.set('Accept', 'application/json')
|
||||
.expect(200)
|
||||
.then((res) => {
|
||||
assert.deepEqual(res.body, versionData);
|
||||
});
|
||||
});
|
||||
|
||||
it('should respond to __frontend_version__ with version info', () => {
|
||||
return request(app)
|
||||
.get('/__frontend_version__')
|
||||
.set('Accept', 'application/json')
|
||||
.expect(200)
|
||||
.then((res) => {
|
||||
assert.deepEqual(res.body, versionData);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче