Skip to content

Commit

Permalink
Merge pull request #528 from guardian/aa/remove-tags
Browse files Browse the repository at this point in the history
Pass build identifier as prop
  • Loading branch information
akash1810 authored Sep 19, 2024
2 parents 12382c4 + 98d9c89 commit 941594b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 36 deletions.
1 change: 1 addition & 0 deletions cdk/bin/cdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ import { CdkPlayground } from '../lib/cdk-playground';
const app = new GuRoot();
new CdkPlayground(app, 'CdkPlayground', {
cloudFormationStackName: 'playground-PROD-cdk-playground',
buildIdentifier: process.env.GITHUB_RUN_NUMBER ?? 'DEV',
});
3 changes: 0 additions & 3 deletions cdk/jest.setup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
jest.mock('@guardian/cdk/lib/constants/tracking-tag');

process.env.GITHUB_RUN_NUMBER = 'TEST';
process.env.GITHUB_SHA = 'TEST';
12 changes: 0 additions & 12 deletions cdk/lib/__snapshots__/cdk-playground.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
exports[`The Deploy stack matches the snapshot 1`] = `
Object {
"Metadata": Object {
"gu:build:number": "TEST",
"gu:build:sha": "TEST",
"gu:cdk:constructs": Array [
"GuVpcParameter",
"GuSubnetListParameter",
Expand Down Expand Up @@ -164,16 +162,6 @@ Object {
"PropagateAtLaunch": true,
"Value": "cdk-playground",
},
Object {
"Key": "gu:build:number",
"PropagateAtLaunch": true,
"Value": "TEST",
},
Object {
"Key": "gu:build:sha",
"PropagateAtLaunch": true,
"Value": "TEST",
},
Object {
"Key": "gu:cdk:version",
"PropagateAtLaunch": true,
Expand Down
4 changes: 3 additions & 1 deletion cdk/lib/cdk-playground.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { CdkPlayground } from './cdk-playground';
describe('The Deploy stack', () => {
it('matches the snapshot', () => {
const app = new App({ outdir: '/tmp/cdk.out' });
const stack = new CdkPlayground(app, 'CdkPlayground');
const stack = new CdkPlayground(app, 'CdkPlayground', {
buildIdentifier: 'TEST',
});
expect(Template.fromStack(stack).toJSON()).toMatchSnapshot();
});
});
38 changes: 18 additions & 20 deletions cdk/lib/cdk-playground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,44 @@ import { GuStack } from '@guardian/cdk/lib/constructs/core';
import { GuCname } from '@guardian/cdk/lib/constructs/dns';
import { GuEc2AppExperimental } from '@guardian/cdk/lib/experimental/patterns/ec2-app';
import type { App } from 'aws-cdk-lib';
import { Duration, Tags } from 'aws-cdk-lib';
import { Duration } from 'aws-cdk-lib';
import { InstanceClass, InstanceSize, InstanceType } from 'aws-cdk-lib/aws-ec2';
import { Runtime } from 'aws-cdk-lib/aws-lambda';

interface CdkPlaygroundProps extends Omit<GuStackProps, 'stack' | 'stage'> {
/**
* Which application build to run.
* This will typically match the build number provided by CI.
*
* @example
* process.env.GITHUB_RUN_NUMBER
*/
buildIdentifier: string;
}

export class CdkPlayground extends GuStack {
constructor(
scope: App,
id: string,
props?: Omit<GuStackProps, 'stack' | 'stage'>,
) {
constructor(scope: App, id: string, props: CdkPlaygroundProps) {
super(scope, id, {
...props,
stack: 'playground',
stage: 'PROD',
env: { region: 'eu-west-1' },
});

const { buildIdentifier } = props;

const ec2App = 'cdk-playground';
const ec2AppDomainName = 'cdk-playground.gutools.co.uk';

const buildNumber = process.env.GITHUB_RUN_NUMBER ?? 'DEV';

const { loadBalancer, autoScalingGroup } = new GuEc2AppExperimental(this, {
const { loadBalancer } = new GuEc2AppExperimental(this, {
applicationPort: 9000,
app: ec2App,
instanceType: InstanceType.of(InstanceClass.T4G, InstanceSize.MICRO),
access: { scope: AccessScope.PUBLIC },
userData: {
distributable: {
fileName: `${ec2App}-${buildNumber}.deb`,
executionStatement: `dpkg -i /${ec2App}/${ec2App}-${buildNumber}.deb`,
fileName: `${ec2App}-${buildIdentifier}.deb`,
executionStatement: `dpkg -i /${ec2App}/${ec2App}-${buildIdentifier}.deb`,
},
},
certificateProps: {
Expand Down Expand Up @@ -92,14 +99,5 @@ export class CdkPlayground extends GuStack {
domainName: lambdaDomainName,
resourceRecord: domain.domainNameAliasDomainName,
});

const { GITHUB_RUN_NUMBER = 'unknown', GITHUB_SHA = 'unknown' } =
process.env;

this.addMetadata('gu:build:number', GITHUB_RUN_NUMBER);
this.addMetadata('gu:build:sha', GITHUB_SHA);

Tags.of(autoScalingGroup).add('gu:build:number', GITHUB_RUN_NUMBER);
Tags.of(autoScalingGroup).add('gu:build:sha', GITHUB_SHA);
}
}

0 comments on commit 941594b

Please sign in to comment.