Skip to content

Commit

Permalink
support optional CODE environment/stage via new optional action inp…
Browse files Browse the repository at this point in the history
…ut `codeDomain`
  • Loading branch information
twrichards committed Feb 27, 2023
1 parent b1bd08d commit e816c1d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
10 changes: 9 additions & 1 deletion action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }
Expand Down Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion cdk/static-site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
12 changes: 12 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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 {
Expand Down

0 comments on commit e816c1d

Please sign in to comment.