From 8e78331f716e2b6c43642c7c7f273780794cb4d6 Mon Sep 17 00:00:00 2001 From: Eunsoo Shin Date: Sun, 1 Sep 2024 11:42:21 -0400 Subject: [PATCH 1/2] landing api --- k8s/main.ts | 253 +++++++++++++++++++++++++++++----------------------- 1 file changed, 143 insertions(+), 110 deletions(-) diff --git a/k8s/main.ts b/k8s/main.ts index 8e203258..b6302b12 100644 --- a/k8s/main.ts +++ b/k8s/main.ts @@ -1,114 +1,147 @@ -import { Construct } from 'constructs'; -import { App } from 'cdk8s'; -import { CronJob, DjangoApplication, PennLabsChart, ReactApplication, RedisApplication } from '@pennlabs/kittyhawk'; - -const cronTime = require('cron-time-generator'); +import { Construct } from 'constructs' +import { App } from 'cdk8s' +import { + CronJob, + DjangoApplication, + PennLabsChart, + ReactApplication, + RedisApplication, +} from '@pennlabs/kittyhawk' + +const cronTime = require('cron-time-generator') export class MyChart extends PennLabsChart { - constructor(scope: Construct) { - super(scope); - - const backendImage = 'pennlabs/penn-courses-backend'; - const secret = 'penn-courses'; - const ingressProps = { - annotations: { - ['ingress.kubernetes.io/content-security-policy']: "frame-ancestors 'none';", - ["ingress.kubernetes.io/protocol"]: "https", - ["traefik.ingress.kubernetes.io/router.middlewares"]: "default-redirect-http@kubernetescrd" - } - } - - new RedisApplication(this, 'redis', { - persistData: true, - }); - - new DjangoApplication(this, 'celery', { - deployment: { - image: backendImage, - secret, - cmd: ['celery', '-A', 'PennCourses', 'worker', '-Q', 'alerts,celery', '-linfo'], - }, - djangoSettingsModule: 'PennCourses.settings.production', - }); - - new DjangoApplication(this, 'backend', { - deployment: { - image: backendImage, - secret, - replicas: 5, - }, - djangoSettingsModule: 'PennCourses.settings.production', - ingressProps, - domains: [{ host: 'penncourseplan.com', paths: ["/api", "/admin", "/accounts", "/assets"] }, - { host: 'penncoursealert.com', paths: ["/api", "/admin", "/accounts", "/assets", "/webhook"] }, - { host: 'penncoursereview.com', paths: ["/api", "/admin", "/accounts", "/assets"] }, - { host: 'penndegreeplan.com', paths: ["/api", "/admin", "/accounts", "/assets"] }] - }); - - new DjangoApplication(this, 'backend-asgi', { - deployment: { - image: backendImage, - cmd: ['/usr/local/bin/asgi-run'], - secret, - replicas: 1, - }, - djangoSettingsModule: 'PennCourses.settings.production', - ingressProps, - domains: [{ host: 'penncoursereview.com', paths: ["/api/ws"] }], - }); - - new ReactApplication(this, 'landing', { - deployment: { - image: 'pennlabs/pcx-landing', - }, - domain: { host: 'penncourses.org', paths: ['/'] }, - }); - - new ReactApplication(this, 'plan', { - deployment: { - image: 'pennlabs/pcp-frontend', - }, - domain: { host: 'penncourseplan.com', paths: ['/'] }, - }); - - new ReactApplication(this, 'alert', { - deployment: { - image: 'pennlabs/pca-frontend', - }, - domain: { host: 'penncoursealert.com', paths: ['/'] }, - }); - - new ReactApplication(this, 'review', { - deployment: { - image: 'pennlabs/pcr-frontend', - }, - domain: { host: 'penncoursereview.com', paths: ['/'] }, - }); - - new ReactApplication(this, 'degree', { - deployment: { - image: 'pennlabs/pdp-frontend', - }, - domain: { host: 'penndegreeplan.com', paths: ['/'] }, - }); - - new CronJob(this, 'load-courses', { - schedule: cronTime.everyDayAt(3), - image: backendImage, - secret, - cmd: ['python', 'manage.py', 'registrarimport'], - }); - - new CronJob(this, 'report-stats', { - schedule: cronTime.everyDayAt(20), - image: backendImage, - secret, - cmd: ['python', 'manage.py', 'alertstats', '1', '--slack'], - }); - - } + constructor(scope: Construct) { + super(scope) + + const backendImage = 'pennlabs/penn-courses-backend' + const secret = 'penn-courses' + const ingressProps = { + annotations: { + ['ingress.kubernetes.io/content-security-policy']: + "frame-ancestors 'none';", + ['ingress.kubernetes.io/protocol']: 'https', + ['traefik.ingress.kubernetes.io/router.middlewares']: + 'default-redirect-http@kubernetescrd', + }, + } + + new RedisApplication(this, 'redis', { + persistData: true, + }) + + new DjangoApplication(this, 'celery', { + deployment: { + image: backendImage, + secret, + cmd: [ + 'celery', + 'worker', + '-A', + 'PennCourses', + '-Q', + 'alerts,celery', + '-linfo', + ], + }, + djangoSettingsModule: 'PennCourses.settings.production', + }) + + new DjangoApplication(this, 'backend', { + deployment: { + image: backendImage, + secret, + replicas: 5, + }, + djangoSettingsModule: 'PennCourses.settings.production', + ingressProps, + domains: [ + { + host: 'penncourseplan.com', + paths: ['/api', '/admin', '/accounts', '/assets'], + }, + { + host: 'penncoursealert.com', + paths: ['/api', '/admin', '/accounts', '/assets', '/webhook'], + }, + { + host: 'penncoursereview.com', + paths: ['/api', '/admin', '/accounts', '/assets'], + }, + { + host: 'penndegreeplan.com', + paths: ['/api', '/admin', '/accounts', '/assets'], + }, + { + host: 'penncourses.org', + paths: ['/api', '/admin', '/accounts', '/assets'], + }, + ], + }) + + new DjangoApplication(this, 'backend-asgi', { + deployment: { + image: backendImage, + cmd: ['/usr/local/bin/asgi-run'], + secret, + replicas: 1, + }, + djangoSettingsModule: 'PennCourses.settings.production', + ingressProps, + domains: [{ host: 'penncoursereview.com', paths: ['/api/ws'] }], + }) + + new ReactApplication(this, 'landing', { + deployment: { + image: 'pennlabs/pcx-landing', + }, + domain: { host: 'penncourses.org', paths: ['/'] }, + }) + + new ReactApplication(this, 'plan', { + deployment: { + image: 'pennlabs/pcp-frontend', + }, + domain: { host: 'penncourseplan.com', paths: ['/'] }, + }) + + new ReactApplication(this, 'alert', { + deployment: { + image: 'pennlabs/pca-frontend', + }, + domain: { host: 'penncoursealert.com', paths: ['/'] }, + }) + + new ReactApplication(this, 'review', { + deployment: { + image: 'pennlabs/pcr-frontend', + }, + domain: { host: 'penncoursereview.com', paths: ['/'] }, + }) + + new ReactApplication(this, 'degree', { + deployment: { + image: 'pennlabs/pdp-frontend', + }, + domain: { host: 'penndegreeplan.com', paths: ['/'] }, + }) + + new CronJob(this, 'load-courses', { + schedule: cronTime.everyDayAt(3), + image: backendImage, + secret, + cmd: ['python', 'manage.py', 'registrarimport'], + }) + + new CronJob(this, 'report-stats', { + schedule: cronTime.everyDayAt(20), + image: backendImage, + secret, + cmd: ['python', 'manage.py', 'alertstats', '1', '--slack'], + }) + } } -const app = new App(); -new MyChart(app); -app.synth(); +const app = new App() +new MyChart(app) +app.synth() From 916d907f24ad214d84d3bf3d321a8ef6ea71946f Mon Sep 17 00:00:00 2001 From: Eunsoo Shin Date: Sun, 1 Sep 2024 11:42:34 -0400 Subject: [PATCH 2/2] style(k8s): add prettier config --- k8s/package.json | 57 +++++++++++++++++++++++++---------------------- k8s/tsconfig.json | 55 ++++++++++++++++++++------------------------- k8s/yarn.lock | 10 +++++++++ 3 files changed, 64 insertions(+), 58 deletions(-) diff --git a/k8s/package.json b/k8s/package.json index e783dcd5..f39d8b7d 100644 --- a/k8s/package.json +++ b/k8s/package.json @@ -1,29 +1,32 @@ { - "name": "k8s", - "version": "1.0.0", - "main": "main.js", - "types": "main.ts", - "license": "Apache-2.0", - "private": true, - "scripts": { - "import": "cdk8s import", - "synth": "cdk8s synth", - "compile": "tsc", - "watch": "tsc -w", - "build": "npm run compile && npm run synth", - "upgrade": "npm i cdk8s@latest cdk8s-cli@latest", - "upgrade:next": "npm i cdk8s@next cdk8s-cli@next" - }, - "dependencies": { - "@pennlabs/kittyhawk": "^1.1.9", - "cdk8s": "^2.2.63", - "constructs": "^10.0.119" - }, - "devDependencies": { - "@types/jest": "^26.0.24", - "@types/node": "^14.18.12", - "jest": "^26.6.3", - "ts-jest": "^26.5.6", - "typescript": "^4.6.3" - } + "name": "k8s", + "version": "1.0.0", + "main": "main.js", + "types": "main.ts", + "license": "Apache-2.0", + "private": true, + "prettier": "@esinx/prettier-config", + "scripts": { + "import": "cdk8s import", + "synth": "cdk8s synth", + "compile": "tsc", + "watch": "tsc -w", + "build": "npm run compile && npm run synth", + "upgrade": "npm i cdk8s@latest cdk8s-cli@latest", + "upgrade:next": "npm i cdk8s@next cdk8s-cli@next" + }, + "dependencies": { + "@pennlabs/kittyhawk": "^1.1.9", + "cdk8s": "^2.2.63", + "constructs": "^10.0.119" + }, + "devDependencies": { + "@esinx/prettier-config": "^1.0.0-3", + "@types/jest": "^26.0.24", + "@types/node": "^14.18.12", + "jest": "^26.6.3", + "prettier": "^3.3.3", + "ts-jest": "^26.5.6", + "typescript": "^4.6.3" + } } diff --git a/k8s/tsconfig.json b/k8s/tsconfig.json index 4289e5aa..7014510c 100644 --- a/k8s/tsconfig.json +++ b/k8s/tsconfig.json @@ -1,33 +1,26 @@ { - "compilerOptions": { - "alwaysStrict": true, - "charset": "utf8", - "declaration": true, - "experimentalDecorators": true, - "inlineSourceMap": true, - "inlineSources": true, - "lib": [ - "es2016" - ], - "module": "CommonJS", - "noEmitOnError": true, - "noFallthroughCasesInSwitch": true, - "noImplicitAny": true, - "noImplicitReturns": true, - "noImplicitThis": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "resolveJsonModule": true, - "strict": true, - "strictNullChecks": true, - "strictPropertyInitialization": true, - "stripInternal": true, - "target": "ES2017" - }, - "include": [ - "**/*.ts" - ], - "exclude": [ - "node_modules" - ] + "compilerOptions": { + "alwaysStrict": true, + "declaration": true, + "experimentalDecorators": true, + "inlineSourceMap": true, + "inlineSources": true, + "lib": ["es2016"], + "module": "CommonJS", + "noEmitOnError": true, + "noFallthroughCasesInSwitch": true, + "noImplicitAny": true, + "noImplicitReturns": true, + "noImplicitThis": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "resolveJsonModule": true, + "strict": true, + "strictNullChecks": true, + "strictPropertyInitialization": true, + "stripInternal": true, + "target": "ES2017" + }, + "include": ["**/*.ts"], + "exclude": ["node_modules"] } diff --git a/k8s/yarn.lock b/k8s/yarn.lock index e18e108e..bdc40943 100644 --- a/k8s/yarn.lock +++ b/k8s/yarn.lock @@ -359,6 +359,11 @@ exec-sh "^0.3.2" minimist "^1.2.0" +"@esinx/prettier-config@^1.0.0-3": + version "1.0.0-3" + resolved "https://registry.yarnpkg.com/@esinx/prettier-config/-/prettier-config-1.0.0-3.tgz#985bf542b3a914cba6e57d4907d6520b1423ae4d" + integrity sha512-Y/cI8Qia6piZca5DCRclsrjRXjIYNZ6GUBySRgvLlN5WliAPe0oiDFmaJJDdSoXtPQYijkPBstIUJR5gylU+wg== + "@istanbuljs/load-nyc-config@^1.0.0": version "1.1.0" resolved "https://registry.yarnpkg.com/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz#fd3db1d59ecf7cf121e80650bb86712f9b55eced" @@ -3577,6 +3582,11 @@ prelude-ls@~1.1.2: resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54" integrity sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ= +prettier@^3.3.3: + version "3.3.3" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.3.3.tgz#30c54fe0be0d8d12e6ae61dbb10109ea00d53105" + integrity sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew== + pretty-format@^26.0.0, pretty-format@^26.6.2: version "26.6.2" resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-26.6.2.tgz#e35c2705f14cb7fe2fe94fa078345b444120fc93"