Skip to content

Commit 1a648d6

Browse files
zephyringflooeydpgaspar
authored
merge from upstream (#7)
* Remove bucket for website backup * Remove DNS for various things Remove a bunch of DNS entries for stuff that was Cord-the-company related, but isn't necessary for the service, like the Cord website, Cord's hosted instance of Clack, etc. * Remove PR server The PR server isn't needed to run the service, and other customers wprobably want to have their own way of doing things rather than running our PR server exactly as it was run, so don't include it in the ops distribution. * Install pyOpenSSL before ec2instanceconnectcli * Create secrets for all .env secrets This makes the CloudFormation code create secret placeholders for all of the different secrets need to generate .env. The ones that are just random strings are initialized to random strings, while the ones that are external API keys are initialized to the string "INSERT API KEY HERE". * Fix names of secrets * Remove check for Cord's GitHub repo * Install Node 18 on build3 * Disable GitHub actions runner by default * Don't require running under GitHub actions in build-on-commit.sh * Don't attempt to push to getcord/monorepo on manual deploy * feat: add JSON log format (#8) * Disable stable host keys on zero by default * Add keyPair definition for radical-ec2-key * Don't customize app.cord.com bucket name * Update version of Postgres to 15 --------- Co-authored-by: Adam Vartanian <[email protected]> Co-authored-by: Daniel Vaz Gaspar <[email protected]>
1 parent 6be1226 commit 1a648d6

23 files changed

+351
-502
lines changed

ops/aws/src/radical-stack/Config.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ export const CORD_COM_DOMAINS = [
3939
// the base for all other domains (eg, api., app.)
4040
export const PRIMARY_DOMAIN_NAME = CORD_COM_DOMAINS[0];
4141

42-
// Web site domain name
43-
export const WEB_SITE_DOMAIN = 'cord.com';
44-
4542
// domains for which we set up gmail
4643
export const GMAIL_DOMAINS = ['cord.com', 'cord.so', 'getradical.co'];
4744

ops/aws/src/radical-stack/acm/dev.cord.com.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

ops/aws/src/radical-stack/ec2/autoScalingGroup.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { enableEc2InstanceConnect } from 'ops/aws/src/radical-stack/ec2/common.t
3838
import { fileUploadsBucket } from 'ops/aws/src/radical-stack/s3/fileUploads.ts';
3939
import { AWS_ACCOUNT, LOADTEST_TIER_ENABLED } from 'ops/aws/src/Config.ts';
4040
import { AWS_REGION } from 'ops/aws/src/radical-stack/Config.ts';
41+
import { ec2KeyPair } from 'ops/aws/src/radical-stack/ec2/keyPair.ts';
4142

4243
const userData = (service: 'server' | 'asyncWorker', tier: Tier) => {
4344
const script = EC2.UserData.forLinux();
@@ -94,7 +95,7 @@ function makeServerASG(tier: Tier) {
9495
securityGroup: securityGroups[tier](),
9596
userData: userData('server', tier),
9697
...Config.SERVER_AUTOSCALING_CAPACITY[tier],
97-
keyName: 'radical-ec2-key',
98+
keyName: ec2KeyPair().keyName,
9899
instanceMonitoring: autoScaling.Monitoring.DETAILED,
99100
healthCheck: autoScaling.HealthCheck.elb({ grace: Duration.minutes(5) }),
100101
notifications: [
@@ -181,7 +182,7 @@ function makeAsyncASG(tier: Tier) {
181182
userData: userData('asyncWorker', tier),
182183
minCapacity: 1,
183184
maxCapacity: 1,
184-
keyName: 'radical-ec2-key',
185+
keyName: ec2KeyPair().keyName,
185186
requireImdsv2: true,
186187
},
187188
);

ops/aws/src/radical-stack/ec2/build3.ts

Lines changed: 58 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@ import { opsNotificationTopic } from 'ops/aws/src/radical-stack/sns/topics.ts';
2525
import { privateSubnets } from 'ops/aws/src/radical-stack/ec2/privateSubnets.ts';
2626
import { basicAgentConfig } from 'ops/aws/config/cloudwatch-agent/config.ts';
2727
import { AWS_ACCOUNT } from 'ops/aws/src/Config.ts';
28+
import { ec2KeyPair } from 'ops/aws/src/radical-stack/ec2/keyPair.ts';
2829

2930
export const hostname = 'build3';
31+
// Whether to install the services on the machine that allow it to operate as a
32+
// runner for GitHub actions, local tests, etc.
33+
export const INCLUDE_GITHUB_RUNNER = false;
3034

3135
const availabilityZone = `${AWS_REGION}b`;
3236
const packages: string[] = [
@@ -77,6 +81,16 @@ export const build3Instance = define(() => {
7781
'mkdir -p /opt/aws/bin',
7882
'pip3 install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz',
7983
'ln -s /usr/local/bin/cfn-* /opt/aws/bin',
84+
85+
// Add NodeSource repo so we get Node 18.x, which is what we use in
86+
// production, instead of whatever Ubuntu's default is at this time.
87+
// https://github.com/nodesource/distributions#installation-instructions
88+
'apt-get install --no-install-recommends -y ca-certificates curl gnupg',
89+
'mkdir -p /etc/apt/keyrings',
90+
'curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg',
91+
'echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list',
92+
'apt-get update',
93+
'apt-get install -y nodejs',
8094
);
8195

8296
const instance = new EC2.Instance(
@@ -106,7 +120,7 @@ export const build3Instance = define(() => {
106120
],
107121
securityGroup: build3SecurityGroup(),
108122
vpcSubnets: { subnets: privateSubnets() },
109-
keyName: 'radical-ec2-key',
123+
keyName: ec2KeyPair().keyName,
110124
userData,
111125
userDataCausesReplacement: false,
112126
},
@@ -169,7 +183,7 @@ export const build3Instance = define(() => {
169183
'dockerCredHelper',
170184
'dockerPruneCronJob',
171185
'testDatabase',
172-
'githubActionsRunner',
186+
...(INCLUDE_GITHUB_RUNNER ? ['githubActionsRunner'] : []),
173187
],
174188
},
175189
configs: {
@@ -231,44 +245,48 @@ export const build3Instance = define(() => {
231245
},
232246
),
233247
]),
234-
githubActionsRunner: new EC2.InitConfig([
235-
EC2.InitFile.fromAsset(
236-
`/etc/docker/compose/github-actions-runner/docker-compose.yml`,
237-
`config/build3/github-actions-runner/docker-compose.yml`,
238-
),
239-
EC2.InitFile.fromString(
240-
'/lib/systemd/system/github-actions-runner.service',
241-
[
242-
'[Unit]\n',
243-
'Description=GitHub Actions Runner\n',
244-
'Requires=docker.service\n\n',
245-
'After=docker.service\n',
246-
'[Service]\n',
247-
'Type=oneshot\n',
248-
'RemainAfterExit=true\n',
249-
'TimeoutStartSec=5m\n',
250-
'WorkingDirectory=/etc/docker/compose/github-actions-runner\n',
251-
'ExecStart=/usr/bin/docker-compose up -d --remove-orphans --scale runner=6\n',
252-
'ExecStop=/usr/bin/docker-compose down\n',
253-
'Restart=on-failure\n',
254-
'RestartSec=5\n',
255-
'[Install]\n',
256-
'WantedBy=multi-user.target',
257-
].join(''),
258-
),
259-
EC2.InitFile.fromString(
260-
'/etc/cron.d/restart-github-actions-runner',
261-
'# Restart every morning at 7am UTC\n' +
262-
'0 7 * * * root ' +
263-
`docker pull ${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com/github-actions-runner:latest && ` +
264-
'systemctl restart github-actions-runner\n',
265-
),
266-
EC2.InitCommand.shellCommand(
267-
'systemctl daemon-reload && ' +
268-
'systemctl enable github-actions-runner && ' +
269-
'systemctl restart github-actions-runner',
270-
),
271-
]),
248+
...(INCLUDE_GITHUB_RUNNER
249+
? {
250+
githubActionsRunner: new EC2.InitConfig([
251+
EC2.InitFile.fromAsset(
252+
`/etc/docker/compose/github-actions-runner/docker-compose.yml`,
253+
`config/build3/github-actions-runner/docker-compose.yml`,
254+
),
255+
EC2.InitFile.fromString(
256+
'/lib/systemd/system/github-actions-runner.service',
257+
[
258+
'[Unit]\n',
259+
'Description=GitHub Actions Runner\n',
260+
'Requires=docker.service\n\n',
261+
'After=docker.service\n',
262+
'[Service]\n',
263+
'Type=oneshot\n',
264+
'RemainAfterExit=true\n',
265+
'TimeoutStartSec=5m\n',
266+
'WorkingDirectory=/etc/docker/compose/github-actions-runner\n',
267+
'ExecStart=/usr/bin/docker-compose up -d --remove-orphans --scale runner=6\n',
268+
'ExecStop=/usr/bin/docker-compose down\n',
269+
'Restart=on-failure\n',
270+
'RestartSec=5\n',
271+
'[Install]\n',
272+
'WantedBy=multi-user.target',
273+
].join(''),
274+
),
275+
EC2.InitFile.fromString(
276+
'/etc/cron.d/restart-github-actions-runner',
277+
'# Restart every morning at 7am UTC\n' +
278+
'0 7 * * * root ' +
279+
`docker pull ${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com/github-actions-runner:latest && ` +
280+
'systemctl restart github-actions-runner\n',
281+
),
282+
EC2.InitCommand.shellCommand(
283+
'systemctl daemon-reload && ' +
284+
'systemctl enable github-actions-runner && ' +
285+
'systemctl restart github-actions-runner',
286+
),
287+
]),
288+
}
289+
: {}),
272290
testDatabase: new EC2.InitConfig([
273291
EC2.InitFile.fromAsset(
274292
`/etc/docker/compose/test-db/docker-compose.yml`,

ops/aws/src/radical-stack/ec2/e2eTest.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ import { radicalStack } from 'ops/aws/src/radical-stack/stack.ts';
2525
import { vanta } from 'ops/aws/src/radical-stack/vanta.ts';
2626
import { basicAgentConfig } from 'ops/aws/config/cloudwatch-agent/config.ts';
2727
import { AWS_ACCOUNT } from 'ops/aws/src/Config.ts';
28-
import { AWS_REGION, S3_BUCKET_PREFIX } from 'ops/aws/src/radical-stack/Config.ts';
28+
import {
29+
AWS_REGION,
30+
S3_BUCKET_PREFIX,
31+
} from 'ops/aws/src/radical-stack/Config.ts';
32+
import { ec2KeyPair } from 'ops/aws/src/radical-stack/ec2/keyPair.ts';
2933

3034
const stack = define(() => new NestedStack(radicalStack(), 'stack-e2eTest'));
3135

@@ -94,7 +98,7 @@ const e2eTestInstance = define(() => {
9498
userData,
9599
userDataCausesReplacement: true,
96100
securityGroup: e2eTestSecurityGroup(),
97-
keyName: 'radical-ec2-key',
101+
keyName: ec2KeyPair().keyName,
98102
requireImdsv2: true,
99103
});
100104
vanta(instance, 'EC2 instance running automated e2e tests', {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { aws_ec2 as EC2 } from 'aws-cdk-lib';
2+
import { define } from 'ops/aws/src/common.ts';
3+
import { radicalStack } from 'ops/aws/src/radical-stack/stack.ts';
4+
5+
export const ec2KeyPair = define(() => {
6+
return new EC2.CfnKeyPair(radicalStack(), 'radical-ec2-key', {
7+
keyName: 'radical-ec2-key',
8+
});
9+
});

ops/aws/src/radical-stack/ec2/loadBalancers.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ import {
2828
PRIMARY_DOMAIN_NAME,
2929
} from 'ops/aws/src/radical-stack/Config.ts';
3030
import { LOADTEST_TIER_ENABLED } from 'ops/aws/src/Config.ts';
31-
import { prServerInstance } from 'ops/aws/src/radical-stack/ec2/prServer.ts';
32-
import { devCordComCertificate } from 'ops/aws/src/radical-stack/acm/dev.cord.com.ts';
3331

3432
export const loadBalancer = define(() => {
3533
const lb = new elbv2.ApplicationLoadBalancer(
@@ -90,7 +88,6 @@ export const loadBalancer = define(() => {
9088
cordComCertificate(),
9189
stagingCordComCertificate(),
9290
loadtestCordComCertificate(),
93-
devCordComCertificate(),
9491
],
9592
sslPolicy: elbv2.SslPolicy.RECOMMENDED_TLS,
9693
});
@@ -225,13 +222,6 @@ export const loadBalancer = define(() => {
225222
});
226223
}
227224

228-
addAction(
229-
'prServer',
230-
50,
231-
[`*.dev.${PRIMARY_DOMAIN_NAME}`],
232-
prServerTargetGroup(),
233-
);
234-
235225
lb.logAccessLogs(elbLogsBucket());
236226

237227
return lb;
@@ -259,17 +249,6 @@ export const oncallTargetGroup = define(
259249
}),
260250
);
261251

262-
export const prServerTargetGroup = define(
263-
() =>
264-
new elbv2.ApplicationTargetGroup(radicalStack(), 'prServerTargetGroup', {
265-
targetGroupName: 'prServer',
266-
protocol: elbv2.ApplicationProtocol.HTTP,
267-
port: 8081,
268-
targets: [new elbv2t.InstanceTarget(prServerInstance(), 8081)],
269-
vpc: defaultVpc(),
270-
}),
271-
);
272-
273252
export const serverAPITargetGroups = defineForEachTier(
274253
makeServerTargetGroup('API', 8161),
275254
);

ops/aws/src/radical-stack/ec2/monitoring.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
} from 'ops/aws/src/radical-stack/ec2/common.ts';
3131
import { AWS_ACCOUNT } from 'ops/aws/src/Config.ts';
3232
import { AWS_REGION } from 'ops/aws/src/radical-stack/Config.ts';
33+
import { ec2KeyPair } from 'ops/aws/src/radical-stack/ec2/keyPair.ts';
3334

3435
const availabilityZone = `${AWS_REGION}a`;
3536

@@ -80,7 +81,7 @@ export const monitoringInstance = define(() => {
8081
userData,
8182
userDataCausesReplacement: true,
8283
securityGroup: monitoringSecurityGroup(),
83-
keyName: 'radical-ec2-key',
84+
keyName: ec2KeyPair().keyName,
8485
requireImdsv2: true,
8586
});
8687
vanta(

0 commit comments

Comments
 (0)