From 57d9b8ccbf4ad8dc70d2b5b6db8c7b8a2e682112 Mon Sep 17 00:00:00 2001 From: akash1810 Date: Thu, 19 Sep 2024 15:31:33 +0100 Subject: [PATCH] Switch to using an auto-generated `riff-raff.yaml` file --- .github/workflows/ci.yml | 4 ++-- cdk/bin/cdk.ts | 23 ++++++++++++++++--- ...c2-app.test.ts.snap => prism.test.ts.snap} | 8 +++++++ cdk/lib/prism-access.ts | 5 +++- .../{prism-ec2-app.test.ts => prism.test.ts} | 4 ++-- cdk/lib/{prism-ec2-app.ts => prism.ts} | 20 ++++++++-------- riff-raff.yaml | 23 ------------------- 7 files changed, 45 insertions(+), 42 deletions(-) rename cdk/lib/__snapshots__/{prism-ec2-app.test.ts.snap => prism.test.ts.snap} (99%) rename cdk/lib/{prism-ec2-app.test.ts => prism.test.ts} (78%) rename cdk/lib/{prism-ec2-app.ts => prism.ts} (85%) delete mode 100644 riff-raff.yaml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a94eda56..51e4a6e1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,9 +39,9 @@ jobs: projectName: devx::prism githubToken: ${{ secrets.GITHUB_TOKEN }} roleArn: ${{ secrets.GU_RIFF_RAFF_ROLE_ARN }} - configPath: riff-raff.yaml # TODO switch to auto-generating this file + configPath: cdk/cdk.out/riff-raff.yaml contentDirectories: | - cloudformation: + cdk.out: - cdk/cdk.out prism: - target/prism.deb diff --git a/cdk/bin/cdk.ts b/cdk/bin/cdk.ts index 7a757897..dfa875cb 100644 --- a/cdk/bin/cdk.ts +++ b/cdk/bin/cdk.ts @@ -1,12 +1,13 @@ #!/usr/bin/env node import 'source-map-support/register'; +import { RiffRaffYamlFile } from '@guardian/cdk/lib/riff-raff-yaml-file'; import { App } from 'aws-cdk-lib'; +import { Prism } from '../lib/prism'; import { PrismAccess } from '../lib/prism-access'; -import { PrismEc2App } from '../lib/prism-ec2-app'; const app = new App(); -new PrismEc2App(app, 'Prism-CODE', { +new Prism(app, 'Prism-CODE', { stage: 'CODE', domainName: 'prism.code.dev-gutools.co.uk', minimumInstances: 1, @@ -14,7 +15,7 @@ new PrismEc2App(app, 'Prism-CODE', { env: { region: 'eu-west-1' }, }); -new PrismEc2App(app, 'Prism-PROD', { +new Prism(app, 'Prism-PROD', { stage: 'PROD', domainName: 'prism.gutools.co.uk', minimumInstances: 2, @@ -23,3 +24,19 @@ new PrismEc2App(app, 'Prism-PROD', { }); new PrismAccess(app, 'PrismAccessStackSet'); + +const riffRaff = new RiffRaffYamlFile(app); +const { deployments, allowedStages } = riffRaff.riffRaffYaml; + +const stackSetDeploymentName = 'cfn-eu-west-1-deploy-prism-access'; +if (!deployments.get(stackSetDeploymentName)) { + throw new Error( + 'Failed to remove CloudFormation deployment of the stack set from riff-raff.yaml', + ); +} +// Riff-Raff cannot deploy stack sets. Remove it from the riff-raff.yaml file. +deployments.delete(stackSetDeploymentName); +// The stack set uses the `INFRA` stage. The application stack (`Prism`) does not. Remove that too. +allowedStages.delete('INFRA'); + +riffRaff.synth(); diff --git a/cdk/lib/__snapshots__/prism-ec2-app.test.ts.snap b/cdk/lib/__snapshots__/prism.test.ts.snap similarity index 99% rename from cdk/lib/__snapshots__/prism-ec2-app.test.ts.snap rename to cdk/lib/__snapshots__/prism.test.ts.snap index 26a0246f..1a870e97 100644 --- a/cdk/lib/__snapshots__/prism-ec2-app.test.ts.snap +++ b/cdk/lib/__snapshots__/prism.test.ts.snap @@ -1012,6 +1012,10 @@ exports[`The PrismEc2App stack matches the snapshot 1`] = ` "Period": 60, "Statistic": "Maximum", "Tags": [ + { + "Key": "App", + "Value": "prism", + }, { "Key": "gu:cdk:version", "Value": "TEST", @@ -1054,6 +1058,10 @@ exports[`The PrismEc2App stack matches the snapshot 1`] = ` }, ], "Tags": [ + { + "Key": "App", + "Value": "prism", + }, { "Key": "gu:cdk:version", "Value": "TEST", diff --git a/cdk/lib/prism-access.ts b/cdk/lib/prism-access.ts index 12cf11eb..79fc00c8 100644 --- a/cdk/lib/prism-access.ts +++ b/cdk/lib/prism-access.ts @@ -19,7 +19,10 @@ export class PrismAccess extends GuStack { super(scope, id, { description: 'CloudFormation template to create the prism role.', stack: 'deploy', - stage: 'INFRA', // singleton stack + stage: 'INFRA', // singleton stack, + env: { + region: 'eu-west-1', + }, }); /* diff --git a/cdk/lib/prism-ec2-app.test.ts b/cdk/lib/prism.test.ts similarity index 78% rename from cdk/lib/prism-ec2-app.test.ts rename to cdk/lib/prism.test.ts index 2600bbaf..3f56f1bc 100644 --- a/cdk/lib/prism-ec2-app.test.ts +++ b/cdk/lib/prism.test.ts @@ -1,11 +1,11 @@ import { App } from 'aws-cdk-lib'; import { Template } from 'aws-cdk-lib/assertions'; -import { PrismEc2App } from './prism-ec2-app'; +import { Prism } from './prism'; describe('The PrismEc2App stack', () => { it('matches the snapshot', () => { const app = new App(); - const stack = new PrismEc2App(app, 'prism', { + const stack = new Prism(app, 'prism', { stage: 'PROD', domainName: 'prism.gutools.co.uk', minimumInstances: 2, diff --git a/cdk/lib/prism-ec2-app.ts b/cdk/lib/prism.ts similarity index 85% rename from cdk/lib/prism-ec2-app.ts rename to cdk/lib/prism.ts index ab038ff9..32310671 100644 --- a/cdk/lib/prism-ec2-app.ts +++ b/cdk/lib/prism.ts @@ -1,6 +1,5 @@ import { GuPlayApp } from '@guardian/cdk'; import { AccessScope } from '@guardian/cdk/lib/constants'; -import type { AppIdentity } from '@guardian/cdk/lib/constructs/core/identity'; import type { GuStackProps } from '@guardian/cdk/lib/constructs/core/stack'; import { GuStack } from '@guardian/cdk/lib/constructs/core/stack'; import { @@ -23,33 +22,32 @@ import { Peer, } from 'aws-cdk-lib/aws-ec2'; -interface PrismEc2AppProps extends Omit { +interface PrismProps extends Omit { domainName: string; minimumInstances: number; } -export class PrismEc2App extends GuStack { - private static app: AppIdentity = { - app: 'prism', - }; - - constructor(scope: App, id: string, props: PrismEc2AppProps) { +export class Prism extends GuStack { + constructor(scope: App, id: string, props: PrismProps) { + const app = 'prism'; super(scope, id, { ...props, description: 'Prism - service discovery', stack: 'deploy', + app, }); const pattern = new GuPlayApp(this, { - ...PrismEc2App.app, + app, applicationLogging: { enabled: true, }, + imageRecipe: 'arm64-focal-java11-deploy-infrastructure', instanceType: InstanceType.of(InstanceClass.T4G, InstanceSize.MEDIUM), userData: { distributable: { - fileName: 'prism.deb', - executionStatement: `dpkg -i /${PrismEc2App.app.app}/prism.deb`, + fileName: `${app}.deb`, + executionStatement: `dpkg -i /${app}/${app}.deb`, }, }, certificateProps: { diff --git a/riff-raff.yaml b/riff-raff.yaml deleted file mode 100644 index f85c7ecf..00000000 --- a/riff-raff.yaml +++ /dev/null @@ -1,23 +0,0 @@ -regions: [eu-west-1] -stacks: [deploy] -allowedStages: - - CODE - - PROD -deployments: - cloudformation: - type: cloud-formation - app: prism - parameters: - templateStagePaths: - CODE: Prism-CODE.template.json - PROD: Prism-PROD.template.json - amiParameter: AMIPrism - amiEncrypted: true - amiTags: - Recipe: arm64-focal-java11-deploy-infrastructure - AmigoStage: PROD - BuiltBy: amigo - prism: - type: autoscaling - dependencies: - - cloudformation