Skip to content

Commit 8545148

Browse files
authored
Use Kittyhawk for Deployment Config (#128)
* 🎉 Set-up * 🐛 Rename DOMAIN -> DOMAINS * ⬆️ Bump * 🔥 Bye Jest
1 parent d8e876d commit 8545148

File tree

12 files changed

+4672
-127
lines changed

12 files changed

+4672
-127
lines changed

.github/cdk/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
"upgrade-cdk": "yarn upgrade cdkactions@latest cdkactions-cli@latest"
1414
},
1515
"dependencies": {
16-
"@pennlabs/kraken": "^0.6.3",
16+
"@pennlabs/kraken": "^0.8.6",
1717
"cdkactions": "^0.2.3",
18-
"constructs": "^3.3.147"
18+
"constructs": "^3.2.109"
1919
},
2020
"devDependencies": {
21-
"@types/node": "^16.9.2",
21+
"@types/node": "^17.0.23",
2222
"cdkactions-cli": "^0.2.3",
23-
"typescript": "^4.4.3"
23+
"typescript": "^4.6.3"
2424
}
2525
}

.github/cdk/yarn.lock

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
# yarn lockfile v1
33

44

5-
"@pennlabs/kraken@^0.6.3":
6-
version "0.6.3"
7-
resolved "https://registry.yarnpkg.com/@pennlabs/kraken/-/kraken-0.6.3.tgz#d346daa36146ee969544939175352e7f7e8a630b"
8-
integrity sha512-7xPn5hIPVsyCQO0DjAMAkotrz9+m6qIBoto/zs7zzuWCj/UlirPn2OphG2GNUnqiDEbQMIXoIPEt1wASUSvSgg==
5+
"@pennlabs/kraken@^0.8.6":
6+
version "0.8.6"
7+
resolved "https://registry.yarnpkg.com/@pennlabs/kraken/-/kraken-0.8.6.tgz#79a9d10bed36b699c526556cd69b6d81341847d1"
8+
integrity sha512-aBblQa/661DJ2GP3Dq1KEzCZ72ZV/Jw7z4HNZoWPxGWn+tSPwvaPkSNDpK7tT+nJmu427giGU8DLyciU79hKbA==
99
dependencies:
10-
cdkactions "^0.2.0"
10+
cdkactions "^0.2.3"
1111
constructs "^3.2.80"
12-
dedent-js "^1.0.1"
12+
ts-dedent "^2.2.0"
1313

14-
"@types/node@^16.9.2":
15-
version "16.9.2"
16-
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.9.2.tgz#81f5a039d6ed1941f8cc57506c74e7c2b8fc64b9"
17-
integrity sha512-ZHty/hKoOLZvSz6BtP1g7tc7nUeJhoCf3flLjh8ZEv1vFKBWHXcnMbJMyN/pftSljNyy0kNW/UqI3DccnBnZ8w==
14+
"@types/node@^17.0.23":
15+
version "17.0.23"
16+
resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.23.tgz#3b41a6e643589ac6442bdbd7a4a3ded62f33f7da"
17+
integrity sha512-UxDxWn7dl97rKVeVS61vErvw086aCYhDLyvRQZ5Rk65rZKepaFdm53GeqXaKBuOhED4e9uWq34IC3TdSdJJ2Gw==
1818

1919
ansi-regex@^5.0.0:
2020
version "5.0.1"
@@ -45,7 +45,7 @@ cdkactions-cli@^0.2.3:
4545
yaml "^1.10.0"
4646
yargs "^16.2.0"
4747

48-
cdkactions@^0.2.0, cdkactions@^0.2.3:
48+
cdkactions@^0.2.3:
4949
version "0.2.3"
5050
resolved "https://registry.yarnpkg.com/cdkactions/-/cdkactions-0.2.3.tgz#aa27bf720962376d54f8ef95cdfb0ab46458b966"
5151
integrity sha512-/DYQ2qsT6fzgZB+cmQjtPqR4aAWCqAytWbFpJK+iJLQ4jQrl6l4uMf01TLiWY3mAILS0YGlwPcoBbGvq9Jnz5g==
@@ -74,16 +74,11 @@ color-name@~1.1.4:
7474
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2"
7575
integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==
7676

77-
constructs@^3.2.109, constructs@^3.2.80, constructs@^3.3.147:
77+
constructs@^3.2.109, constructs@^3.2.80:
7878
version "3.3.147"
7979
resolved "https://registry.yarnpkg.com/constructs/-/constructs-3.3.147.tgz#0616cb1aeb7a916665a74ceae0a1b34b38386937"
8080
integrity sha512-xTSA87W5hscsHdFC2NcbJWALeMt8QWoCvVXRHPIuoBDDXdvBuNoqL2a5kY1yEWSMLQvBPnrDyinfz3twTX6dAw==
8181

82-
dedent-js@^1.0.1:
83-
version "1.0.1"
84-
resolved "https://registry.yarnpkg.com/dedent-js/-/dedent-js-1.0.1.tgz#bee5fb7c9e727d85dffa24590d10ec1ab1255305"
85-
integrity sha1-vuX7fJ5yfYXf+iRZDRDsGrElUwU=
86-
8782
emoji-regex@^8.0.0:
8883
version "8.0.0"
8984
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37"
@@ -158,15 +153,15 @@ strip-ansi@^6.0.0:
158153
dependencies:
159154
ansi-regex "^5.0.0"
160155

161-
ts-dedent@^2.0.0:
156+
ts-dedent@^2.0.0, ts-dedent@^2.2.0:
162157
version "2.2.0"
163158
resolved "https://registry.yarnpkg.com/ts-dedent/-/ts-dedent-2.2.0.tgz#39e4bd297cd036292ae2394eb3412be63f563bb5"
164159
integrity sha512-q5W7tVM71e2xjHZTlgfTDoPF/SmqKG5hddq9SzR49CH2hayqRKJtQ4mtRlSxKaJlR/+9rEM+mnBHf7I2/BQcpQ==
165160

166-
typescript@^4.4.3:
167-
version "4.4.3"
168-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.3.tgz#bdc5407caa2b109efd4f82fe130656f977a29324"
169-
integrity sha512-4xfscpisVgqqDfPaJo5vkd+Qd/ItkoagnHpufr+i2QCHBsNYp+G7UAoyFl8aPtx879u38wPV65rZ8qbGZijalA==
161+
typescript@^4.6.3:
162+
version "4.6.3"
163+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.6.3.tgz#eefeafa6afdd31d725584c67a0eaba80f6fc6c6c"
164+
integrity sha512-yNIatDa5iaofVozS/uQJEl3JRWLKKGJKh6Yaiv0GLGSuhpFJe7P3SbHZ8/yjAHRQwKRoA6YZqlfjXWmVzoVSMw==
170165

171166
universalify@^0.1.0:
172167
version "0.1.2"

.github/workflows/cdkactions_build-and-deploy.yaml

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -157,46 +157,40 @@ jobs:
157157
needs: react-check
158158
deploy:
159159
runs-on: ubuntu-latest
160-
container:
161-
image: pennlabs/helm-tools:39b60af248944898fcbc58d1fe5b0f1995420aef
162160
if: github.ref == 'refs/heads/master'
163161
steps:
164162
- uses: actions/checkout@v2
165-
- name: Deploy
163+
- id: synth
164+
name: Synth cdk8s manifests
166165
run: |-
167-
aws eks --region us-east-1 update-kubeconfig --name production --role-arn arn:aws:iam::${AWS_ACCOUNT_ID}:role/kubectl
166+
cd k8s
167+
yarn install --frozen-lockfile
168168
169169
# get repo name (by removing owner/organization)
170-
RELEASE_NAME=${REPOSITORY#*/}
170+
export RELEASE_NAME=${REPOSITORY#*/}
171+
172+
# Export RELEASE_NAME as an output
173+
echo "::set-output name=RELEASE_NAME::$RELEASE_NAME"
171174
172-
# this specifies what tag of icarus to pull down
173-
DEPLOY_TAG=$(yq r k8s/values.yaml deploy_version)
174-
if [ "$DEPLOY_TAG" = "null" ]; then
175-
echo "Could not find deploy tag"
176-
exit 1
177-
fi
175+
yarn build
176+
env:
177+
GIT_SHA: ${{ github.sha }}
178+
REPOSITORY: ${{ github.repository }}
179+
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
180+
- name: Deploy
181+
run: |-
182+
aws eks --region us-east-1 update-kubeconfig --name production --role-arn arn:aws:iam::${AWS_ACCOUNT_ID}:role/kubectl
178183
179-
helm repo add pennlabs https://helm.pennlabs.org/
180-
for i in {1..10}; do
181-
# This is bash soup, but it'll do.
182-
# 1. Attempt to install with helm
183-
# 2. If this succeeds, exit with a success status code
184-
# 3. If it fails, mark the command as succeeded so that '-e' doesn't kick us out
185-
# 4. Wait 10s and try again
186-
helm upgrade --install --atomic --set=image_tag=$IMAGE_TAG -f k8s/values.yaml --version "${DEPLOY_TAG}" $RELEASE_NAME pennlabs/icarus && exit 0 || true
187-
sleep 10s
188-
echo "Retrying deploy for $i times"
189-
done
184+
# get repo name from synth step
185+
RELEASE_NAME=${{ steps.synth.outputs.RELEASE_NAME }}
190186
191-
# If we get here, all helm installs failed so our command should fail
192-
exit 1
187+
# Deploy
188+
kubectl apply -f k8s/dist/ -l app.kubernetes.io/component=certificate
189+
kubectl apply -f k8s/dist/ --prune -l app.kubernetes.io/part-of=$RELEASE_NAME
193190
env:
194-
IMAGE_TAG: ${{ github.sha }}
195191
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
196192
AWS_ACCESS_KEY_ID: ${{ secrets.GH_AWS_ACCESS_KEY_ID }}
197193
AWS_SECRET_ACCESS_KEY: ${{ secrets.GH_AWS_SECRET_ACCESS_KEY }}
198-
DO_AUTH_TOKEN: ${{ secrets.DO_AUTH_TOKEN }}
199-
REPOSITORY: ${{ github.repository }}
200194
needs:
201195
- publish-backend
202196
- publish-frontend

backend/Platform/settings/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import dj_database_url
1616

1717

18-
DOMAIN = os.environ.get("DOMAIN", "example.com")
18+
DOMAINS = os.environ.get("DOMAINS", "example.com").split(",")
1919

2020
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
2121
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

backend/Platform/settings/production.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from sentry_sdk.integrations.django import DjangoIntegration
66

77
from Platform.settings.base import * # noqa
8-
from Platform.settings.base import DOMAIN
8+
from Platform.settings.base import DOMAINS
99

1010

1111
DEBUG = False
@@ -14,7 +14,7 @@
1414
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
1515

1616
# Allow production host headers
17-
ALLOWED_HOSTS = [DOMAIN]
17+
ALLOWED_HOSTS = DOMAINS
1818

1919
# Make sure SECRET_KEY is set to a secret in production
2020
SECRET_KEY = os.environ.get("SECRET_KEY", None)

k8s/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.d.ts
2+
*.js
3+
node_modules
4+
dist/

k8s/cdk8s.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
language: typescript
2+
app: node main.js

k8s/main.ts

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import { Construct } from 'constructs';
2+
import { App } from 'cdk8s';
3+
import { CronJob, DjangoApplication, PennLabsChart, ReactApplication } from '@pennlabs/kittyhawk';
4+
5+
const cronTime = require('cron-time-generator');
6+
7+
export class MyChart extends PennLabsChart {
8+
constructor(scope: Construct) {
9+
super(scope);
10+
11+
const domain = "platform.pennlabs.org"
12+
const devDomain = "platform-dev.pennlabs.org"
13+
14+
const frontendImage = "pennlabs/platform-frontend"
15+
const backendImage = "pennlabs/platform-backend"
16+
const devImage = "pennlabs/platform-dev"
17+
18+
const secret = "platform"
19+
const devSecret = "platform-dev"
20+
21+
new DjangoApplication(this, 'django', {
22+
port: 443,
23+
deployment: {
24+
image: backendImage,
25+
secret,
26+
secretMounts: [
27+
{
28+
name: "platform",
29+
subPath: "SHIBBOLETH_CERT",
30+
mountPath: "/etc/shibboleth/sp-cert.pem",
31+
},
32+
{
33+
name: "platform",
34+
subPath: "SHIBBOLETH_KEY",
35+
mountPath: "/etc/shibboleth/sp-key.pem",
36+
}
37+
]
38+
},
39+
domains: [{
40+
host: domain,
41+
paths: [
42+
"/admin",
43+
"/accounts",
44+
"/assets",
45+
"/identity",
46+
"/s",
47+
"/options",
48+
"/openapi",
49+
"/documentation",
50+
"/Shibboleth.sso",
51+
],
52+
isSubdomain: true,
53+
}],
54+
ingressProps: {
55+
annotations: {
56+
["ingress.kubernetes.io/protocol"]: "http"
57+
},
58+
},
59+
djangoSettingsModule: 'Platform.settings.production',
60+
});
61+
62+
new ReactApplication(this, 'react', {
63+
deployment: {
64+
image: frontendImage,
65+
replicas: 2,
66+
},
67+
domain: {
68+
host: domain,
69+
paths: ["/"]
70+
},
71+
})
72+
73+
new DjangoApplication(this, 'dev', {
74+
port: 8080,
75+
deployment: {
76+
image: devImage,
77+
secret: devSecret,
78+
env: [{
79+
name: "DEV_LOGIN",
80+
value: "true"
81+
}]
82+
},
83+
domains: [{
84+
host: devDomain,
85+
paths: ["/"],
86+
isSubdomain: true,
87+
}],
88+
djangoSettingsModule: 'Platform.settings.production',
89+
});
90+
91+
new CronJob(this, 'clear-expired-tokens', {
92+
schedule: cronTime.everySundayAt(5),
93+
image: backendImage,
94+
secret,
95+
cmd: ["python3", "manage.py", "cleartokens"],
96+
});
97+
}
98+
}
99+
100+
const app = new App();
101+
new MyChart(app);
102+
app.synth();

k8s/package.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "k8s",
3+
"version": "1.0.0",
4+
"main": "main.js",
5+
"types": "main.ts",
6+
"license": "Apache-2.0",
7+
"private": true,
8+
"scripts": {
9+
"import": "cdk8s import",
10+
"synth": "cdk8s synth",
11+
"compile": "tsc",
12+
"watch": "tsc -w",
13+
"build": "npm run compile && npm run synth",
14+
"upgrade": "npm i cdk8s@latest cdk8s-cli@latest",
15+
"upgrade:next": "npm i cdk8s@next cdk8s-cli@next"
16+
},
17+
"dependencies": {
18+
"@pennlabs/kittyhawk": "^1.1.4",
19+
"cdk8s": "^2.2.63",
20+
"constructs": "^10.0.119"
21+
},
22+
"devDependencies": {
23+
"@types/jest": "^26.0.24",
24+
"@types/node": "^14.18.12",
25+
"jest": "^26.6.3",
26+
"ts-jest": "^26.5.6",
27+
"typescript": "^4.6.3"
28+
}
29+
}

k8s/tsconfig.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"compilerOptions": {
3+
"alwaysStrict": true,
4+
"charset": "utf8",
5+
"declaration": true,
6+
"experimentalDecorators": true,
7+
"inlineSourceMap": true,
8+
"inlineSources": true,
9+
"lib": [
10+
"es2016"
11+
],
12+
"module": "CommonJS",
13+
"noEmitOnError": true,
14+
"noFallthroughCasesInSwitch": true,
15+
"noImplicitAny": true,
16+
"noImplicitReturns": true,
17+
"noImplicitThis": true,
18+
"noUnusedLocals": true,
19+
"noUnusedParameters": true,
20+
"resolveJsonModule": true,
21+
"strict": true,
22+
"strictNullChecks": true,
23+
"strictPropertyInitialization": true,
24+
"stripInternal": true,
25+
"target": "ES2017"
26+
},
27+
"include": [
28+
"**/*.ts"
29+
],
30+
"exclude": [
31+
"node_modules"
32+
]
33+
}

0 commit comments

Comments
 (0)