Skip to content

Commit

Permalink
task 2.2: implement automated deployment
Browse files Browse the repository at this point in the history
* add serverless framework to manage deployment
* define needed resources: bucket, distribution, policies
* define plugin to sync FE build to s3 bucket
* define plugin to invalidate cloudfront distribution after deploy
* add custom plugin to output distribution url after deploy
* add corresponded npm scripts
  • Loading branch information
Guria committed Sep 30, 2022
1 parent 1dbe390 commit 73c8d13
Show file tree
Hide file tree
Showing 5 changed files with 7,877 additions and 257 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ coverage
dist
dist-ssr
*.local
.serverless

# Editor directories and files
.vscode/*
Expand Down
51 changes: 51 additions & 0 deletions .serverless_plugins/log-output-values.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Serverless plugin that outputs value from outputs based on templates in custom config
class LogOutputValues {
constructor(serverless, options) {
this.serverless = serverless;
this.options = options;

this.hooks = {
"after:deploy:deploy": this.logOutputValues.bind(this),
};
}

async logOutputValues() {
const result = await this.getResults();
const outputsList = this.serverless.service.custom["log-output-values"];

const replacements = {};
outputsList.forEach(({ template }) => {
const outputValue = template.replace(/{(\w+)}/g, (token, outputName) => {
if (!replacements[outputName]) {
replacements[outputName] = this.getOutputValue(result, outputName);
}

return replacements[outputName] || token;
});

this.serverless.cli.log(outputValue);
});
}

async getResults() {
const provider = this.serverless.getProvider("aws");
const stackName = provider.naming.getStackName(this.options.stage);

return await provider.request(
"CloudFormation",
"describeStacks",
{ StackName: stackName },
this.options.stage,
this.options.region
);
}

getOutputValue(result, outputKey) {
const output = result.Stacks[0].Outputs.find(
(o) => o.OutputKey === outputKey
);
return output.OutputValue;
}
}

module.exports = LogOutputValues;
Loading

0 comments on commit 73c8d13

Please sign in to comment.