Skip to content

Commit

Permalink
Add basic apps to test
Browse files Browse the repository at this point in the history
  • Loading branch information
ernest-tpximpact committed Dec 1, 2023
1 parent e678e1d commit 08f5d01
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 0 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/.gitignore
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
42 changes: 42 additions & 0 deletions server.js
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}`);
})
39 changes: 39 additions & 0 deletions tests.js
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;
},
}]

0 comments on commit 08f5d01

Please sign in to comment.