Skip to content

Commit

Permalink
Switch to using an auto-generated riff-raff.yaml file
Browse files Browse the repository at this point in the history
  • Loading branch information
akash1810 committed Sep 19, 2024
1 parent 2938d17 commit 2f726a1
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ 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/cdk.out
Expand Down
23 changes: 20 additions & 3 deletions cdk/bin/cdk.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
#!/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,
cloudFormationStackName: '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,
Expand All @@ -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();
5 changes: 4 additions & 1 deletion cdk/lib/prism-access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
});

/*
Expand Down
4 changes: 2 additions & 2 deletions cdk/lib/prism-ec2-app.test.ts → cdk/lib/prism.test.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
20 changes: 9 additions & 11 deletions cdk/lib/prism-ec2-app.ts → cdk/lib/prism.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -23,33 +22,32 @@ import {
Peer,
} from 'aws-cdk-lib/aws-ec2';

interface PrismEc2AppProps extends Omit<GuStackProps, 'description' | 'stack'> {
interface PrismProps extends Omit<GuStackProps, 'description' | 'stack'> {
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: {
Expand Down
23 changes: 0 additions & 23 deletions riff-raff.yaml

This file was deleted.

0 comments on commit 2f726a1

Please sign in to comment.