-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
task 2.2: implement automated deployment
* 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
Showing
5 changed files
with
7,877 additions
and
257 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 |
---|---|---|
|
@@ -12,6 +12,7 @@ coverage | |
dist | ||
dist-ssr | ||
*.local | ||
.serverless | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
|
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,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; |
Oops, something went wrong.