Skip to content

Commit

Permalink
Merge branch 'staging' into fetch-all-usage-plan-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-chew authored Jun 26, 2019
2 parents 846992a + dbe928a commit 0396f0a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cloudformation/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Parameters:

StaticAssetRebuildMode:
Type: String
Description: By default, a static asset rebuild doesn't overwrite custom-content. Provide the value `overwrite_content` to replace the custom-content with your local version. Don't do this unless you know what you're doing -- all custom changes in your s3 bucket will be lost.
Description: By default, a static asset rebuild doesn't overwrite custom-content. Provide the value `overwrite-content` to replace the custom-content with your local version. Don't do this unless you know what you're doing -- all custom changes in your s3 bucket will be lost.
Default: ''

MarketplaceSubscriptionTopicProductCode:
Expand Down
3 changes: 3 additions & 0 deletions dev-portal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ module.exports = {

// Set this to overwrite-content if you want to reset your custom content back to the defaults. Defaults to ``
// staticAssetRebuildMode: `overwrite-content` // ONLY SET

// AWS SAM CLI profile option: optional specific profile from your AWS credential file. Not used by default
//awsSamCliProfile: "my-profile"
}
```
4. Run `npm run release`. This will build the static assets, deploy them, and generate the `dev-portal/public/config.js` file needed for local development. Take note of the bucket names you use
Expand Down
18 changes: 11 additions & 7 deletions dev-portal/scripts/deploy-stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@ const customersTableName = deployerConfig.customersTableName || 'DevPortalCustom
const cognitoDomainName = deployerConfig.cognitoDomainName || ''
const staticAssetRebuildMode = deployerConfig.staticAssetRebuildMode || ''

// AWS SAM CLI configuration
const awsSamCliProfile = deployerConfig.awsSamCliProfile;
const profileOption = awsSamCliProfile ? `--profile ${awsSamCliProfile}` : ''

function main() {
Promise.resolve()
.then(() => execute(`sam package --template-file ${samTemplate} --output-template-file ${packageConfig} --s3-bucket ${buildAssetsBucket}`, true))
.then(() => execute(`sam deploy --template-file ${packageConfig} --stack-name ${stackName} --capabilities CAPABILITY_NAMED_IAM --parameter-overrides StaticAssetRebuildToken="${Date.now()}" StaticAssetRebuildMode="${staticAssetRebuildMode}" DevPortalSiteS3BucketName="${siteAssetsBucket}" ArtifactsS3BucketName="${apiAssetsBucket}" DevPortalCustomersTableName="${customersTableName}" CognitoDomainNameOrPrefix="${cognitoDomainName}" --s3-bucket ${buildAssetsBucket}`, true))
.then(() => writeConfig(true))
.then(() => console.log('\n' + 'Process Complete! Run `npm run start` to launch run the dev portal locally.\n'.green()))
.catch(err => {
console.log(("" + err).red())
})
.then(() => execute(`sam package --template-file ${samTemplate} --output-template-file ${packageConfig} --s3-bucket ${buildAssetsBucket} ${profileOption}`, true))
.then(() => execute(`sam deploy --template-file ${packageConfig} --stack-name ${stackName} --capabilities CAPABILITY_NAMED_IAM --parameter-overrides StaticAssetRebuildToken="${Date.now()}" StaticAssetRebuildMode="${staticAssetRebuildMode}" DevPortalSiteS3BucketName="${siteAssetsBucket}" ArtifactsS3BucketName="${apiAssetsBucket}" DevPortalCustomersTableName="${customersTableName}" CognitoDomainNameOrPrefix="${cognitoDomainName}" --s3-bucket ${buildAssetsBucket} ${profileOption}`, true))
.then(() => writeConfig(true))
.then(() => console.log('\n' + 'Process Complete! Run `npm run start` to launch run the dev portal locally.\n'.green()))
.catch(err => {
console.log(("" + err).red())
})
}

if (samTemplate && packageConfig && stackName && buildAssetsBucket && siteAssetsBucket && apiAssetsBucket && customersTableName) {
Expand Down
18 changes: 11 additions & 7 deletions dev-portal/scripts/write-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@ const { execute, r } = require('./utils.js')
const buildConfig = require('../deployer.config.js')
const stackName = buildConfig.stackName

// AWS SAM CLI configuration
const awsSamCliProfile = buildConfig.awsSamCliProfile;
const profileOption = awsSamCliProfile ? `--profile ${awsSamCliProfile}` : ''

function writeConfig (swallowOutput) {
return execute(`aws cloudformation describe-stacks --stack-name ${stackName}`, swallowOutput)
.then((result) => {
return execute(`aws cloudformation describe-stacks --stack-name ${stackName} ${profileOption}`, swallowOutput)
.then((result) => {
const websiteUrl = (JSON.parse(result.stdout).Stacks[0].Outputs)
.find(output => output.OutputKey === "WebsiteURL").OutputValue
.find(output => output.OutputKey === "WebsiteURL").OutputValue

return fetch(`${websiteUrl}/config.js`).then(response => response.text())
})
.then(output => writeFile(r(`../public/config.js`), output))
.catch(console.error)
return fetch(`${websiteUrl}/config.js`).then(response => response.text())
})
.then(output => writeFile(r(`../public/config.js`), output))
.catch(console.error)
}

module.exports = writeConfig

0 comments on commit 0396f0a

Please sign in to comment.