Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to using an auto-generated riff-raff.yaml file #947

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
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();
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -1054,6 +1058,10 @@ exports[`The PrismEc2App stack matches the snapshot 1`] = `
},
],
"Tags": [
{
"Key": "App",
"Value": "prism",
},
{
"Key": "gu:cdk:version",
"Value": "TEST",
Expand Down
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',
},
Comment on lines +23 to +25
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

riff-raff.yaml generation requires each stack to have the region explicitly set.

});

/*
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 {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The riff-raff.yaml generator uses the class name for the app property of the cloud-formation deployment type. Rename PrismEc2App to Prism as the app tag is prism not prism-ec2-app.

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.