Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions lib/deployer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const minimist = require('minimist');
const parseYaml = require('./utils/parseYaml');
const ServerlessV1 = require('./providers/serverless');
const HardCoded = require('./providers/hardcoded');
const environmentService = require('./service/environmentService');

class Deployer {
constructor() {
Expand All @@ -23,14 +25,23 @@ class Deployer {
}

async deploy() {
let provider
if(this.component.provider === 'serverless-framework') {
const provider = new ServerlessV1(this.component);
await provider.deploy();
provider = new ServerlessV1(this.component);
} else if(this.component.provider === 'hardcoded') {
provider = new HardCoded(this.component);
} else {
console.error(`The provider ${this.component.provider} is not implemented!`);
}

const deployResp = await provider.deploy();

// Store the component in the environment service with it's outputs
if(deployResp.outputs) {
await deployResp.outputs.forEach(output => {
environmentService.putComponentOutput(this.component.env, this.component.name, output.key, output.value)
});
}
}

async destroy() {
Expand Down
22 changes: 22 additions & 0 deletions lib/providers/hardcoded.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict'

class HardCoded {
constructor(config) {
this.stage = config.env;
this.input = config.input;
}

async deploy() {
return {
outputs: Object.entries(this.input).map(([key, value]) => {
console.log(key, value);
return {
key: key,
value: value
}
})
}
}
}

module.exports = HardCoded;
15 changes: 15 additions & 0 deletions lib/providers/serverless.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ class ServerlessV1 {
const sls = new serverless({});
await sls.init();
await sls.run();
const outputs = await this.getStackOutput(sls);

return {
outputs: outputs
}
}

writeConfigFile() {
Expand All @@ -42,6 +47,16 @@ class ServerlessV1 {
fs.writeFileSync(path.join(process.cwd(), '.deployer', 'serverless.config.yaml'), output, 'utf-8');
}
}

async getStackOutput(serverless) {
const stackName = serverless.providers.aws.naming.getStackName();
const stackOutputs = serverless.providers.aws
.request('CloudFormation', 'describeStacks', { StackName: stackName })
.then(result => {
return result.Stacks[0].Outputs
});
return stackOutputs.map(output => {return {key: output.OutputKey, value: output.OutputValue}});
}
}

module.exports = ServerlessV1;
16 changes: 16 additions & 0 deletions lib/service/environmentService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const got = require('got');

const apiUrl = "https://environments.daysmart.net/output"

module.exports = {
async putComponentOutput(environment, component, key, value) {
await got.post(apiUrl, {
json: {
componentName: `${environment}.${component}`,
outputName: key,
value: value
}
});
}
}

Loading