Skip to content

Commit 752159f

Browse files
joyliu-qArmaanT
andauthored
Use Kittyhawk for Deployment Config (#88)
* 🎉 Initial set-up * 🎨 Remove env * 🎨 Update dockerfile * 🔥 Remove unnec files * 🔥 Untrack main.js and main.d.ts * 🔥 Remove Jest & test, update cdk8s.yaml * ⬆️ Upgrade kittyhawk to v1.1.0 * 🎨 Remove jest config from gitignore * Update * Update * Update Co-authored-by: Armaan Tobaccowalla <armaan@tobaccowalla.com>
1 parent c257c5b commit 752159f

12 files changed

Lines changed: 4565 additions & 54 deletions

File tree

.dockerignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ Dockerfile
1111
.git
1212
.gitignore
1313
.gitmodules
14-
**/*.md
14+
**/*.md
15+
16+
# kube
17+
k8s

.github/cdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"upgrade-cdk": "yarn upgrade cdkactions@latest cdkactions-cli@latest"
1414
},
1515
"dependencies": {
16-
"@pennlabs/kraken": "^0.5.0",
16+
"@pennlabs/kraken": "^0.8.0",
1717
"cdkactions": "^0.2.3",
1818
"constructs": "^3.2.109"
1919
},

.github/cdk/yarn.lock

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

44

5-
"@pennlabs/kraken@^0.5.0":
6-
version "0.5.0"
7-
resolved "https://registry.yarnpkg.com/@pennlabs/kraken/-/kraken-0.5.0.tgz#b79d24f3d34a1ef4aff7edc0e90e5bd9388c1897"
8-
integrity sha512-4QHJ7hPoxswsNpELdlDXX73GKecelCdPXKf7MEJYZ3Xe3UCZGEStVLYFoJUEev+KaxN0IxxTqYZ3kfPqabqEIQ==
5+
"@pennlabs/kraken@^0.8.0":
6+
version "0.8.0"
7+
resolved "https://registry.yarnpkg.com/@pennlabs/kraken/-/kraken-0.8.0.tgz#56692acc019b462effc842f97ec27cfd3eb913f1"
8+
integrity sha512-cS8InTtMoPyz3+05Drzv7xumDpDWJ6k0ijkX0oy2m6WAydSjyhOmB8jtcL6livkbFA4Bb84jKOXzQqsMHEsf9A==
99
dependencies:
1010
cdkactions "^0.2.0"
1111
constructs "^3.2.80"
12-
dedent-js "^1.0.1"
12+
ts-dedent "^2.2.0"
1313

1414
"@types/node@^14.14.22":
1515
version "14.14.22"
@@ -79,11 +79,6 @@ constructs@^3.2.109, constructs@^3.2.80:
7979
resolved "https://registry.yarnpkg.com/constructs/-/constructs-3.3.3.tgz#532d3b736d2a9f090fc5ded1e43d4a1b17819290"
8080
integrity sha512-tus97CfZU14VcAdM5Qhg5OGMj89IAyxOyomt7h2Gup5EpBiMz6yIkOsxV9GAh30xmUKWSAwX56AD8QjzZCjIEQ==
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"
@@ -163,6 +158,11 @@ ts-dedent@^2.0.0:
163158
resolved "https://registry.yarnpkg.com/ts-dedent/-/ts-dedent-2.0.0.tgz#47c5eb23d9096f3237cc413bc82d387d36dbe690"
164159
integrity sha512-DfxKjSFQfw9+uf7N9Cy8Ebx9fv5fquK4hZ6SD3Rzr+1jKP6AVA6H8+B5457ZpUs0JKsGpGqIevbpZ9DMQJDp1A==
165160

161+
ts-dedent@^2.2.0:
162+
version "2.2.0"
163+
resolved "https://registry.yarnpkg.com/ts-dedent/-/ts-dedent-2.2.0.tgz#39e4bd297cd036292ae2394eb3412be63f563bb5"
164+
integrity sha512-q5W7tVM71e2xjHZTlgfTDoPF/SmqKG5hddq9SzR49CH2hayqRKJtQ4mtRlSxKaJlR/+9rEM+mnBHf7I2/BQcpQ==
165+
166166
typescript@^4.1.3:
167167
version "4.1.3"
168168
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.1.3.tgz#519d582bd94cba0cf8934c7d8e8467e473f53bb7"

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

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,45 +30,38 @@ jobs:
3030
tags: pennlabs/penn-basics:latest,pennlabs/penn-basics:${{ github.sha }}
3131
deploy:
3232
runs-on: ubuntu-latest
33-
container:
34-
image: pennlabs/helm-tools:39b60af248944898fcbc58d1fe5b0f1995420aef
3533
if: github.ref == 'refs/heads/master'
3634
steps:
3735
- uses: actions/checkout@v2
38-
- name: Deploy
36+
- id: synth
37+
name: Synth cdk8s manifests
3938
run: |-
40-
aws eks --region us-east-1 update-kubeconfig --name production --role-arn arn:aws:iam::${AWS_ACCOUNT_ID}:role/kubectl
39+
cd k8s
40+
yarn install --frozen-lockfile
4141
4242
# get repo name (by removing owner/organization)
4343
RELEASE_NAME=${REPOSITORY#*/}
4444
45-
# this specifies what tag of icarus to pull down
46-
DEPLOY_TAG=$(yq r k8s/values.yaml deploy_version)
47-
if [ "$DEPLOY_TAG" = "null" ]; then
48-
echo "Could not find deploy tag"
49-
exit 1
50-
fi
45+
# Export RELEASE_NAME as an output
46+
echo "::set-output RELEASE_NAME=$RELEASE_NAME"
47+
48+
yarn build
49+
env:
50+
GIT_SHA: ${{ github.sha }}
51+
REPOSITORY: ${{ github.repository }}
52+
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
53+
- name: Deploy
54+
run: |-
55+
aws eks --region us-east-1 update-kubeconfig --name production --role-arn arn:aws:iam::${AWS_ACCOUNT_ID}:role/kubectl
5156
52-
helm repo add pennlabs https://helm.pennlabs.org/
53-
for i in {1..10}; do
54-
# This is bash soup, but it'll do.
55-
# 1. Attempt to install with helm
56-
# 2. If this succeeds, exit with a success status code
57-
# 3. If it fails, mark the command as succeeded so that '-e' doesn't kick us out
58-
# 4. Wait 10s and try again
59-
helm upgrade --install --atomic --set=image_tag=$IMAGE_TAG -f k8s/values.yaml --version "${DEPLOY_TAG}" $RELEASE_NAME pennlabs/icarus && exit 0 || true
60-
sleep 10s
61-
echo "Retrying deploy for $i times"
62-
done
57+
# get repo name from synth step
58+
RELEASE_NAME=${{ steps.synth.outputs.RELEASE_NAME }}
6359
64-
# If we get here, all helm installs failed so our command should fail
65-
exit 1
60+
# Deploy
61+
kubectl apply -f k8s/dist/ -l app.kubernetes.io/component=certificate
62+
kubectl apply -f k8s/dist/ --prune -l app.kubernetes.io/part-of=$RELEASE_NAME
6663
env:
67-
IMAGE_TAG: ${{ github.sha }}
6864
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
6965
AWS_ACCESS_KEY_ID: ${{ secrets.GH_AWS_ACCESS_KEY_ID }}
7066
AWS_SECRET_ACCESS_KEY: ${{ secrets.GH_AWS_SECRET_ACCESS_KEY }}
71-
DO_AUTH_TOKEN: ${{ secrets.DO_AUTH_TOKEN }}
72-
K8S_CLUSTER_ID: ${{ secrets.K8S_CLUSTER_ID }}
73-
REPOSITORY: ${{ github.repository }}
7467
needs: publish-publish

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM node:10-buster
22

3-
MAINTAINER Penn Labs
3+
LABEL maintainer="Penn Labs"
44

55
WORKDIR /app/
66

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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Construct } from 'constructs';
2+
import { PennLabsChart, ReactApplication } from '@pennlabs/kittyhawk';
3+
import { App } from 'cdk8s';
4+
5+
export class MyChart extends PennLabsChart {
6+
constructor(scope: Construct) {
7+
super(scope);
8+
9+
const image = 'pennlabs/penn-basics';
10+
const secret = 'penn-basics';
11+
const domain = 'pennbasics.com';
12+
13+
new ReactApplication(this, 'react', {
14+
deployment: {
15+
image,
16+
secret,
17+
},
18+
domain: { host: domain, paths: ['/'] },
19+
});
20+
}
21+
}
22+
23+
const app = new App();
24+
new MyChart(app);
25+
app.synth();

k8s/package.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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.1",
19+
"cdk8s": "^1.5.48",
20+
"cdk8s-plus-22": "^1.0.0-beta.153",
21+
"constructs": "^3.3.246"
22+
},
23+
"devDependencies": {
24+
"@types/jest": "^26.0.24",
25+
"@types/node": "^14.18.12",
26+
"cdk8s-cli": "^1.0.130",
27+
"jest": "^26.6.3",
28+
"ts-jest": "^26.5.6",
29+
"typescript": "^4.6.2"
30+
}
31+
}

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)