-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e678e1d
commit 08f5d01
Showing
3 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
__pycache__/ | ||
*.py[cod] | ||
|
||
.cache | ||
.coverage | ||
build | ||
dist | ||
specification | ||
*.egg-info | ||
tmp/ | ||
var/ | ||
.DS_Store | ||
*.swp | ||
.eggs | ||
*.gfs | ||
.venv | ||
.vscode | ||
|
||
tf/*/.terraform* | ||
tf/**/tfplan | ||
|
||
/.python-version | ||
.idea | ||
|
||
node_modules | ||
|
||
.editorconfig | ||
pyrightconfig.json | ||
tags | ||
__pycache__ | ||
.mypy_cache | ||
|
||
.env | ||
.env.test | ||
.db-data | ||
static | ||
|
||
docker-compose.override.yml | ||
.junitxml | ||
.envrc | ||
.env.staging | ||
.env.sandbox | ||
.env.production | ||
coverage.xml | ||
.secrets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const express = require('express') | ||
const tests = require('./tests') | ||
const {createLogger, transports, format} = require('winston') | ||
|
||
const logger = createLogger({ | ||
level: 'info', | ||
format: format.json(), | ||
defaultMeta: {service: 'status'}, | ||
transports: [new transports.Console()], | ||
}); | ||
|
||
const app = express() | ||
|
||
app.get('/', (req, res) => { | ||
Promise.all(tests.map(test => new Promise((resolve) => { | ||
test.check().then(result => { | ||
resolve([test.print, {status: result ? 'success' : 'failure', result}]) | ||
}).catch(error => { | ||
logger.error('error', { | ||
test: test.print, | ||
error, | ||
}); | ||
resolve([test.print, {status: 'failure', error: error.message}]) | ||
}) | ||
}))).then(checks => { | ||
if (checks.filter(([_, v]) => v.status === 'failure').length) res.statusCode = 500 | ||
|
||
logger.info(res.statusCode === 500 ? 'failure' : 'success', { | ||
results: Object.fromEntries(checks), | ||
}); | ||
res.json(Object.fromEntries(checks)); | ||
}) | ||
}) | ||
|
||
app.get('/health', (req, res) => { | ||
logger.info('healthcheck'); | ||
res.status(200).json({applicationHealth: 'ok'}) | ||
}) | ||
|
||
app.listen(process.env.PORT || 80, () => { | ||
logger.info(`Status application listening on port ${process.env.PORT || 80}`); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const {readFileSync} = require("fs"); | ||
const {join} = require("path"); | ||
const {Client} = require("pg"); | ||
const {S3, STS} = require("aws-sdk"); | ||
|
||
module.exports = [{ | ||
print: "DEPLOYMENT:TIME", | ||
check: async () => readFileSync(join(process.cwd(), 'DEPLOY_TIME'), 'utf-8').replace('\n', ''), | ||
}, { | ||
print: "DB:READ", | ||
check: async () => { | ||
const client = new Client({connectionString: process.env.READ_DATABASE_URL}); | ||
await client.connect(); | ||
await client.end(); | ||
return true; | ||
}, | ||
}, { | ||
print: "DB:WRITE", | ||
check: async () => { | ||
const client = new Client({connectionString: process.env.WRITE_DATABASE_URL}); | ||
await client.connect(); | ||
await client.end(); | ||
return true; | ||
}, | ||
}, { | ||
print: "BUCKET:READ", | ||
check: async () => { | ||
const client = new S3({region: 'eu-west-2'}); | ||
await client.getObject({Bucket: process.env.COLLECTION_DATA_BUCKET, Key: 'index.html'}).promise(); | ||
return true; | ||
}, | ||
}, { | ||
print: "ROLE:APPLICATION", | ||
check: async () => { | ||
const client = new STS({region: 'eu-west-2'}); | ||
const response = await client.getCallerIdentity({}).promise(); | ||
return response.Arn.indexOf('task-application-role') !== -1; | ||
}, | ||
}] |