From e816c1dc44e647a01173c61b60a9d9618cf25b2b Mon Sep 17 00:00:00 2001 From: Tom Richards Date: Mon, 27 Feb 2023 09:22:17 +0000 Subject: [PATCH] support optional `CODE` environment/stage via new optional action input `codeDomain` --- action.yaml | 10 +++++++++- cdk/static-site.ts | 1 - index.js | 12 ++++++++++++ index.ts | 14 ++++++++++++++ 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/action.yaml b/action.yaml index 5dd3d3e..f3f8a9c 100644 --- a/action.yaml +++ b/action.yaml @@ -7,6 +7,9 @@ inputs: domain: description: A Guardian-owned domain. [name].gutools.co.uk is recommended. required: true + codeDomain: + description: OPTIONAL Guardian-owned domain for CODE environment. [name].code.dev-gutools.co.uk is recommended. + required: false artifact: description: 'Name of artifact containing the static site. Should be uploaded in an earlier workflow step.' required: false @@ -31,6 +34,7 @@ runs: env: INPUT_APP: ${{ inputs.app }} INPUT_DOMAIN: ${{ inputs.domain }} + INPUT_CODE_DOMAIN: ${{ inputs.codeDomain }} INPUT_ARTIFACT: ${{ inputs.artifact }} INPUT_DRYRUN: ${{ inputs.dryRun}} INPUT_ACTIONS_RUNTIME_TOKEN: ${ github.token } @@ -64,12 +68,16 @@ runs: - eu-west-1 allowedStages: - PROD + ${{ inputs.codeDomain && '- CODE' || '' }} deployments: cfn: type: cloud-formation app: ${{ inputs.app }} parameters: - templatePath: cfn.json + templatePath: + templateStagePaths: + PROD: cfn.json + ${{ inputs.codeDomain && 'CODE: cfn-CODE.json' || '' }} static-site-assets: type: aws-s3 app: ${{ inputs.domain }} # A hack to prefix uploads with the domain. diff --git a/cdk/static-site.ts b/cdk/static-site.ts index e154189..c0ce3dc 100644 --- a/cdk/static-site.ts +++ b/cdk/static-site.ts @@ -8,7 +8,6 @@ import { import { GuCname } from "@guardian/cdk/lib/constructs/dns/"; import type { App} from "aws-cdk-lib"; import { Duration } from "aws-cdk-lib"; -import { Certificate } from "aws-cdk-lib/aws-certificatemanager"; import { CfnListenerCertificate, } from "aws-cdk-lib/aws-elasticloadbalancingv2"; diff --git a/index.js b/index.js index a710561..8c21964 100644 --- a/index.js +++ b/index.js @@ -908983,6 +908983,7 @@ var StaticSite = class extends import_core.GuStack { var main = () => { const app = core.getInput("app", { required: true }); const domain = core.getInput("domain", { required: true }); + const codeDomain = core.getInput("codeDomain", { required: false }); const stack = "deploy"; core.info("Inputs are: " + JSON.stringify({ app, stack, domain })); const cdkApp = new import_aws_cdk_lib2.App(); @@ -908994,6 +908995,17 @@ var main = () => { }); const cfn = import_assertions.Template.fromStack(cdkStack).toJSON(); fs.writeFileSync("cfn.json", JSON.stringify(cfn, void 0, 2)); + if (codeDomain) { + const cdkAppCODE = new import_aws_cdk_lib2.App(); + const cdkStackCODE = new StaticSite(cdkAppCODE, "static-site-code", { + app, + stack, + stage: "CODE", + domainName: codeDomain + }); + const cfnCODE = import_assertions.Template.fromStack(cdkStackCODE).toJSON(); + fs.writeFileSync("cfn-CODE.json", JSON.stringify(cfnCODE, void 0, 2)); + } }; try { if (require.main === module) diff --git a/index.ts b/index.ts index eaefb37..6616f95 100644 --- a/index.ts +++ b/index.ts @@ -7,6 +7,7 @@ import { StaticSite } from "./cdk/static-site"; export const main = (): void => { const app = core.getInput("app", { required: true }); const domain = core.getInput("domain", { required: true }); + const codeDomain = core.getInput("codeDomain", { required: false }); const stack = "deploy"; @@ -25,6 +26,19 @@ export const main = (): void => { const cfn = Template.fromStack(cdkStack).toJSON(); fs.writeFileSync("cfn.json", JSON.stringify(cfn, undefined, 2)); + + if(codeDomain) { + const cdkAppCODE = new App(); + const cdkStackCODE = new StaticSite(cdkAppCODE, "static-site-code", { + app, + stack, + stage: "CODE", + domainName: codeDomain, + }); + + const cfnCODE = Template.fromStack(cdkStackCODE).toJSON(); + fs.writeFileSync("cfn-CODE.json", JSON.stringify(cfnCODE, undefined, 2)); + } }; try {