Skip to content

Commit

Permalink
chore(cleanup): conforming braze content proxy to the patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
bassrock committed Aug 23, 2024
1 parent 3b7e474 commit b36de1e
Show file tree
Hide file tree
Showing 13 changed files with 1,746 additions and 3,550 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/braze-content-proxy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: V3 Proxy API
on:
pull_request:
paths:
- 'infrastructure/braze-content-proxy/**'
- 'packages/**'
- 'servers/braze-content-proxy/**'
- 'pnpm-lock.yaml'
- 'Dockerfile'
- '.github/actions/**'
- '.github/workflows/braze-content-proxy.yml'
- '.github/workflows/reuse-*.yml'
push:
branches:
- main
- dev
paths:
- 'infrastructure/braze-content-proxy/**'
- 'packages/**'
- 'servers/braze-content-proxy/**'
- 'pnpm-lock.yaml'
- 'Dockerfile'
- '.github/actions/**'
- '.github/workflows/braze-content-proxy.yml'
- '.github/workflows/reuse-*.yml'
jobs:
test-integrations:
if: github.event_name == 'pull_request'
uses: ./.github/workflows/reuse-test-integrations.yml
with:
scope: braze-content-proxy
secrets: inherit

infrastructure:
uses: ./.github/workflows/reuse-infrastructure.yml
with:
scope: braze-content-proxy-cdk
stack-output-path: infrastructure/braze-content-proxy/cdktf.out/stacks/braze-content-proxy
secrets: inherit

api:
uses: ./.github/workflows/reuse-build-and-push-image.yml
needs: [infrastructure]
with:
scope: braze-content-proxy
app-path: servers/braze-content-proxy
app-port: 4500
sentry-project: braze-content-proxy
docker-repo-name-pattern: brazecontentproxy-{0}-app
terraform-output: ${{needs.infrastructure.outputs.terraform-output}}
secrets: inherit

sentry:
if: github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/main'
uses: ./.github/workflows/reuse-sentry-release.yml
needs: [api]
with:
sentry-project: braze-content-proxy
sentry-environment: ${{ github.ref == 'refs/heads/main' && 'production' || 'development' }}
secrets: inherit
3 changes: 3 additions & 0 deletions infrastructure/braze-content-proxy/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import cdktf from '@pocket-tools/eslint-config/cdktf';
import tseslint from 'typescript-eslint';
export default tseslint.config(...cdktf);
5 changes: 3 additions & 2 deletions infrastructure/braze-content-proxy/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "braze-content-proxy-cdk",
"version": "1.0.0",
"private": true,
"license": "MPL-2.0",
"main": "dist/main.js",
"types": "dist/main.ts",
"license": "MPL-2.0",
"private": true,
"scripts": {
"build": "rm -rf dist && tsc",
"compile": "tsc --pretty",
Expand All @@ -17,6 +17,7 @@
"@cdktf/provider-aws": "19.31.0",
"@cdktf/provider-local": "10.1.0",
"@cdktf/provider-null": "10.0.0",
"@cdktf/provider-pagerduty": "13.11.4",
"@pocket-tools/terraform-modules": "workspace:*",
"cdktf": "0.20.8",
"cdktf-cli": "0.20.8",
Expand Down
9 changes: 0 additions & 9 deletions infrastructure/braze-content-proxy/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ const environment = isDev ? 'Dev' : 'Prod';
const domain = isDev
? `${domainPrefix}.getpocket.dev`
: `${domainPrefix}.getpocket.com`;
const githubConnectionArn = isDev
? 'arn:aws:codestar-connections:us-east-1:410318598490:connection/7426c139-1aa0-49e2-aabc-5aef11092032'
: 'arn:aws:codestar-connections:us-east-1:996905175585:connection/5fa5aa2b-a2d2-43e3-ab5a-72ececfc1870';
const branch = isDev ? 'dev' : 'main';

export const config = {
name,
Expand All @@ -18,11 +14,6 @@ export const config = {
shortName: 'BCP',
environment,
domain,
codePipeline: {
githubConnectionArn,
repository: 'pocket/braze-content-proxy',
branch,
},
healthCheck: {
command: [
'CMD-SHELL',
Expand Down
80 changes: 38 additions & 42 deletions infrastructure/braze-content-proxy/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,62 +1,72 @@
import { Construct } from 'constructs';
import {
App,
Aspects,
DataTerraformRemoteState,
MigrateIds,
S3Backend,
TerraformStack,
} from 'cdktf';
import { AwsProvider } from '@cdktf/provider-aws/lib/provider';
import { DataAwsCallerIdentity } from '@cdktf/provider-aws/lib/data-aws-caller-identity';
import { DataAwsRegion } from '@cdktf/provider-aws/lib/data-aws-region';
import { DataAwsSnsTopic } from '@cdktf/provider-aws/lib/data-aws-sns-topic';
import { DataAwsKmsAlias } from '@cdktf/provider-aws/lib/data-aws-kms-alias';
import {
provider as awsProvider,
dataAwsCallerIdentity,
dataAwsRegion,
dataAwsKmsAlias,
dataAwsSnsTopic,
} from '@cdktf/provider-aws';
import { config } from './config';
import {
PocketALBApplication,
PocketECSCodePipeline,
PocketPagerDuty,
} from '@pocket-tools/terraform-modules';
import { LocalProvider } from '@cdktf/provider-local/lib/provider';
import { NullProvider } from '@cdktf/provider-null/lib/provider';
import { PagerdutyProvider } from '@cdktf/provider-pagerduty/lib/provider';
import { provider as localProvider } from '@cdktf/provider-local';
import { provider as nullProvider } from '@cdktf/provider-null';
import { provider as pagerDutyProvider } from '@cdktf/provider-pagerduty';
import * as fs from 'fs';

class BrazeContentProxy extends TerraformStack {
constructor(scope: Construct, name: string) {
super(scope, name);

new AwsProvider(this, 'aws', { region: 'us-east-1' });
new PagerdutyProvider(this, 'pagerduty_provider', { token: undefined });
new LocalProvider(this, 'local_provider');
new NullProvider(this, 'null_provider');
new awsProvider.AwsProvider(this, 'aws', { region: 'us-east-1' });
new pagerDutyProvider.PagerdutyProvider(this, 'pagerduty_provider', {
token: undefined,
});
new localProvider.LocalProvider(this, 'local_provider');
new nullProvider.NullProvider(this, 'null_provider');

new S3Backend(this, {
bucket: `mozilla-content-team-${config.environment.toLowerCase()}-terraform-state`,
dynamodbTable: `mozilla-content-team-${config.environment.toLowerCase()}-terraform-state`,
bucket: `mozilla-pocket-team-${config.environment.toLowerCase()}-terraform-state`,
dynamodbTable: `mozilla-pocket-team-${config.environment.toLowerCase()}-terraform-state`,
key: config.name,
region: 'us-east-1',
});

const region = new DataAwsRegion(this, 'region');
const caller = new DataAwsCallerIdentity(this, 'caller');
const region = new dataAwsRegion.DataAwsRegion(this, 'region');
const caller = new dataAwsCallerIdentity.DataAwsCallerIdentity(
this,
'caller',
);

const pocketApp = this.createPocketAlbApplication({
this.createPocketAlbApplication({
pagerDuty: this.createPagerDuty(),
secretsManagerKmsAlias: this.getSecretsManagerKmsAlias(),
snsTopic: this.getCodeDeploySnsTopic(),
region,
caller,
});

this.createApplicationCodePipeline(pocketApp);
// Pre cdktf 0.17 ids were generated differently so we need to apply a migration aspect
// https://developer.hashicorp.com/terraform/cdktf/concepts/aspects
Aspects.of(this).add(new MigrateIds());
}

/**
* Get the sns topic for code deploy
* @private
*/
private getCodeDeploySnsTopic() {
return new DataAwsSnsTopic(this, 'backend_notifications', {
return new dataAwsSnsTopic.DataAwsSnsTopic(this, 'backend_notifications', {
name: `Backend-${config.environment}-ChatBot`,
});
}
Expand All @@ -66,27 +76,11 @@ class BrazeContentProxy extends TerraformStack {
* @private
*/
private getSecretsManagerKmsAlias() {
return new DataAwsKmsAlias(this, 'kms_alias', {
return new dataAwsKmsAlias.DataAwsKmsAlias(this, 'kms_alias', {
name: 'alias/aws/secretsmanager',
});
}

/**
* Create CodePipeline to build and deploy terraform and ecs
* @param app
* @private
*/
private createApplicationCodePipeline(app: PocketALBApplication) {
new PocketECSCodePipeline(this, 'code-pipeline', {
prefix: config.prefix,
source: {
codeStarConnectionArn: config.codePipeline.githubConnectionArn,
repository: config.codePipeline.repository,
branchName: config.codePipeline.branch,
},
});
}

/**
* Create PagerDuty service for alerts
* @private
Expand Down Expand Up @@ -124,10 +118,10 @@ class BrazeContentProxy extends TerraformStack {

private createPocketAlbApplication(dependencies: {
pagerDuty: PocketPagerDuty;
region: DataAwsRegion;
caller: DataAwsCallerIdentity;
secretsManagerKmsAlias: DataAwsKmsAlias;
snsTopic: DataAwsSnsTopic;
region: dataAwsRegion.DataAwsRegion;
caller: dataAwsCallerIdentity.DataAwsCallerIdentity;
secretsManagerKmsAlias: dataAwsKmsAlias.DataAwsKmsAlias;
snsTopic: dataAwsSnsTopic.DataAwsSnsTopic;
}): PocketALBApplication {
const { pagerDuty, region, caller, secretsManagerKmsAlias, snsTopic } =
dependencies;
Expand Down Expand Up @@ -185,7 +179,9 @@ class BrazeContentProxy extends TerraformStack {
],
codeDeploy: {
useCodeDeploy: true,
useCodePipeline: true,
useCodePipeline: false,
useTerraformBasedCodeDeploy: false,
generateAppSpec: false,
snsNotificationTopicArn: snsTopic.arn,
notifications: {
notifyOnFailed: true,
Expand Down
Loading

0 comments on commit b36de1e

Please sign in to comment.