briareus
Version:
Briareus assists with Feature Branch deploys to ECS
151 lines (142 loc) • 3.52 kB
JavaScript
'use strict';
const fs = require('fs');
const path = require('path');
const convict = require('convict');
let config = convict({
env: {
doc: 'The applicaton environment.',
format: ['production', 'development', 'test'],
default: 'development',
env: 'NODE_ENV'
},
ip: {
doc: 'The IP address to bind.',
format: 'ipaddress',
default: '127.0.0.1',
env: 'BIND'
},
port: {
doc: 'The port to bind.',
format: 'port',
env: 'PORT',
default: 4100
},
apiToken: {
doc: 'The lambda endpoint',
env: 'API_TOKEN',
format: 'String',
default: ''
},
ecsClusterArn: {
doc: 'The ECS Cluster do deploy feature branches too',
env: 'ECS_CLUSTER_ARN',
format: 'String',
default: ''
},
baseHostname: {
doc: 'The base hostname to run builds on',
env: 'BASE_HOSTNAME',
format: 'String',
default: ''
},
logging: {
level: {
doc: 'The logging level',
env: 'LOG_LEVEL',
default: 'info'
},
stderr: {
doc: 'Flag to enable logging to stderr',
env: 'LOG_STDERR',
format: 'Boolean',
default: false
},
stdout: {
doc: 'Flag to enable logging to stdout',
env: 'LOG_STDOUT',
format: 'Boolean',
default: true
}
},
aws: {
region: {
doc: 'AWS Region',
env: 'AWS_REGION',
format: 'String',
default: 'us-east-1'
},
dynamodb: {
apiVersion: {
doc: 'The AWS Dynamodb API version to use',
default: '2012-08-10'
},
},
},
dynamodb: {
table: {
doc: 'Dynamodb table to store data in',
env: 'DYNAMODB_TABLE',
format: 'String',
default: 'briareus'
}
},
hostedZoneId: {
doc: 'Route53 DNS Hosted Zone Id where dns records associated with briarieus resources should be created',
env: 'HOSTED_ZONE_ID',
format: 'String',
default: ''
},
albArn: {
doc: 'The Load Balancer to serve requests from',
env: 'ALB_ARN',
format: 'String',
default: ''
},
kmsKeyArn: {
doc: 'The KMS Key to encrypt secrets with',
env: 'KMS_KEY_ARN',
format: 'String',
default: ''
},
variantsLogGroup: {
doc: 'The log group to set in ECS Task Definitions',
env: 'VARIANTS_LOG_GROUP',
format: 'String',
default: ''
},
taskExecutionRoleArn: {
doc: 'IAM Role to assigned as the ECS Task Execution role in Task Definitions',
env: 'TASK_EXECUTION_ROLE_ARN',
format: 'String',
default: ''
},
awsApiPollingTimeout: {
doc: 'Duration of time in milliseconds to wait between polling of the aws api',
env: 'AWS_API_POLLING_INTERVAL',
format: 'Number',
default: 5000
}
});
var envPath = path.resolve(__dirname + '/config/' + config.get('env') + '.json');
if (fs.existsSync(envPath)) config.loadFile(envPath);
config.validate();
// Enforce the setting on specific envs
const requiredSettings = [
'apiToken',
'ecsClusterArn',
'baseHostname',
'hostedZoneId',
'albArn',
'kmsKeyArn',
'variantsLogGroup',
'taskExecutionRoleArn'
]
requiredSettings.forEach((setting) => {
if (!config.get(setting)) throw new Error(`Missing configration for "${setting}"`);
});
// Set this one manually because 'aws.dynamodb.endpoint' should not be set at all in
// production, where as convict will set it as an empty string if this env is not set
if (process.env.DYNAMODB_ENDPOINT) {
config.set('aws.dynamodb.endpoint', process.env.DYNAMODB_ENDPOINT);
}
module.exports = config;