Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test cicd #703

Closed
wants to merge 81 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
f1fc212
init: file structure and ingress/service/deployment templates
maxmwang Dec 6, 2023
cead6a4
refactor: flatten charts file directory
maxmwang Dec 7, 2023
391c141
pull images from docker registry, running on local kube engine
maxmwang Jan 25, 2024
89b5eca
feat: nginx-controller routing to frontend
maxmwang Jan 27, 2024
e9badde
refactor: rename directory
maxmwang Jan 27, 2024
c1fb7db
feat: mongodb
maxmwang Jan 27, 2024
512ae28
feat: redis
maxmwang Jan 27, 2024
7d8bab8
refactor: move ingress-nginx to namespace bt-base
maxmwang Feb 1, 2024
1cafac6
add mongodb install command in init.sh
Chengming-Li Feb 11, 2024
11f9e34
add redis install command to init.sh
Chengming-Li Feb 12, 2024
6578411
modify backend env uri's to use redis and mongo pod services
Chengming-Li Feb 12, 2024
61a0fc2
fix: mongodb and redis urls in backend
maxmwang Feb 16, 2024
2822cb9
migrate to octoberkeleytime docker hub image repos
maxmwang Feb 18, 2024
ed0a056
remove old infra, rename new-infra directory
maxmwang Feb 18, 2024
3ee9350
remove old infra, rename new-infra directory (actually)
maxmwang Feb 18, 2024
1f8ddd3
remove helm build package
maxmwang Feb 18, 2024
ffc1e74
use --values values.yaml instead of inline --set
maxmwang Feb 18, 2024
e7546fa
add prod infra
kevinzwang Feb 20, 2024
c3b3581
reorder charts and change ingress to use issuer, not clusterissuer
kevinzwang Feb 20, 2024
125752c
Merge pull request #672 from asuc-octo/infra-kev
maxmwang Feb 22, 2024
1e7a73b
create cron job to spin up new pod
Chengming-Li Feb 22, 2024
afd0a58
finish updater.yaml
Chengming-Li Feb 22, 2024
a97989d
mongo bitnami chart
maxmwang Feb 23, 2024
8188637
fix implementation to allow for multiple commands
Chengming-Li Feb 23, 2024
ad2c0b3
add metallb and move base dependencies
kevinzwang Feb 23, 2024
2357342
fix default address range (oops used current bt ip)
kevinzwang Feb 23, 2024
cc21c20
move to letsencrypt prod
kevinzwang Feb 23, 2024
310904c
add common labels to metallb configs
kevinzwang Feb 23, 2024
6b990b8
formatting
maxmwang Feb 27, 2024
df994f7
use bitnami mongodb chart
maxmwang Feb 27, 2024
9b5e95d
use existingClaim as pvc name
maxmwang Feb 28, 2024
133a9ca
merge infra in
maxmwang Feb 28, 2024
a75e03f
Merge pull request #680 from asuc-octo/infra-mongo
maxmwang Feb 28, 2024
3fc2749
express trust proxy (nginx)
maxmwang Feb 29, 2024
55b9b96
disable mongo auth, update helm commands
maxmwang Feb 29, 2024
610d424
add CI/CD workflows
Chengming-Li Mar 25, 2024
1c1c6dd
test
Chengming-Li Mar 25, 2024
6fd9d99
test
Chengming-Li Apr 5, 2024
51766ca
test
Chengming-Li Apr 5, 2024
178510e
Update cd-branch.yml
Chengming-Li Apr 5, 2024
9e64e27
test
Chengming-Li Apr 5, 2024
7b7fa7c
Fix cd-branch.yml
Chengming-Li Apr 5, 2024
3c8ee6c
Update cd-branch.yml
Chengming-Li Apr 5, 2024
7021f99
Update cd-branch.yml
Chengming-Li Apr 5, 2024
663529a
Update cd-branch.yml
Chengming-Li Apr 5, 2024
c474f78
Update cd-branch.yml
Chengming-Li Apr 5, 2024
d27a928
Update cd-branch.yml
Chengming-Li Apr 5, 2024
6d87e91
Update cd-branch.yml
Chengming-Li Apr 5, 2024
03bcbe3
Update cd-branch.yml
Chengming-Li Apr 5, 2024
422a205
Update cd-branch.yml
Chengming-Li Apr 5, 2024
c6bb2d9
Update cd-branch.yml
Chengming-Li Apr 5, 2024
4b7922c
Update cd-branch.yml
Chengming-Li Apr 5, 2024
252bfe9
Update cd-branch.yml
Chengming-Li Apr 5, 2024
d238ae0
Update cd-branch.yml
Chengming-Li Apr 6, 2024
a9dc2a8
Update cd-branch.yml
Chengming-Li Apr 6, 2024
4d87203
Update cd-branch.yml
Chengming-Li Apr 6, 2024
0062e08
Update cd-branch.yml
Chengming-Li Apr 6, 2024
a039ff3
Update cd-branch.yml
Chengming-Li Apr 6, 2024
075e355
Update cd-branch.yml
Chengming-Li Apr 10, 2024
26d1dac
Update cd-branch.yml
Chengming-Li Apr 10, 2024
e6a5297
Create cd-build-backend.yml
Chengming-Li Apr 10, 2024
927209f
Create cd-build-frontend.yml
Chengming-Li Apr 10, 2024
1643702
Update cd-build-frontend.yml
Chengming-Li Apr 10, 2024
878a1c9
Update cd-build-backend.yml
Chengming-Li Apr 10, 2024
fac0f79
Update cd-master.yml
Chengming-Li Apr 12, 2024
9691cc6
Update cd-branch.yml
Chengming-Li Apr 12, 2024
d3856d5
Update cd-branch.yml
Chengming-Li Apr 12, 2024
65c22e3
Update cd-branch.yml
Chengming-Li Apr 17, 2024
fd8ef59
Update cd-branch.yml
Chengming-Li Apr 17, 2024
eda6dad
Update cd-branch.yml
Chengming-Li Apr 17, 2024
f86de06
Update and rename cd-master.yml to cd-prod.yml
Chengming-Li Apr 17, 2024
c6c37cc
Update cd-prod.yml
Chengming-Li Apr 17, 2024
15f27f4
Create cd-staging.yml
Chengming-Li Apr 17, 2024
701edd9
Update cd-prod.yml
Chengming-Li Apr 17, 2024
e1717bc
Update and rename cd-branch.yml to cd-dev.yml
Chengming-Li Apr 17, 2024
46a3bb1
Update update-catalog.ts
Chengming-Li Jun 24, 2024
c988a35
Update update-catalog.ts
Chengming-Li Jun 24, 2024
99263fd
Update update-catalog.ts
Chengming-Li Jun 24, 2024
c076b20
Update Dockerfile
Chengming-Li Jun 24, 2024
e06b759
Update Dockerfile
Chengming-Li Jun 24, 2024
1452389
Update cd-build-frontend.yml
Chengming-Li Jun 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/cd-build-backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name:
Build Backend

on:
pull_request:
types: [opened, synchronize, reopened]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Build Docker Image
run: docker build -t berkeleytime-backend ./backend/

- name: Save Docker Image as Tarball
run: docker save berkeleytime-backend:latest -o berkeleytime-backend.tar

- name: Upload Docker Image as Artifact
uses: actions/upload-artifact@v2
with:
name: backend
path: berkeleytime-backend.tar
32 changes: 32 additions & 0 deletions .github/workflows/cd-build-frontend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name:
Build Frontend

on:
pull_request:
types: [opened, synchronize, reopened]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: echo
run: pwd

- name: node
run: node -v

- name: Build Docker Image
run: docker build -t berkeleytime-frontend ./frontend/

- name: Save Docker Image as Tarball
run: docker save berkeleytime-frontend:latest -o berkeleytime-frontend.tar

- name: Upload Docker Image as Artifact
uses: actions/upload-artifact@v2
with:
name: frontend
path: berkeleytime-frontend.tar
45 changes: 45 additions & 0 deletions .github/workflows/cd-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name:
Deploy to Dev

on:
repository_dispatch:
types: [trigger-workflow]

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build Backend Image
run: docker build -t berkeleytime-backend ./backend/
- name: Tag Backend Image
run: docker tag berkeleytime-backend ${{ secrets.DOCKER_USERNAME }}/berkeleytime-backend:${{ github.sha }}
- name: Push Backend Image
run: docker push ${{ secrets.DOCKER_USERNAME }}/berkeleytime-backend:${{ github.sha }}
- name: Build Frontend Image
run: docker build -t berkeleytime-frontend ./frontend/
- name: Tag Frontend Image
run: docker tag berkeleytime-frontend ${{ secrets.DOCKER_USERNAME }}/berkeleytime-frontend:${{ github.sha }}
- name: Push Frontend Image
run: docker push ${{ secrets.DOCKER_USERNAME }}/berkeleytime-frontend:${{ github.sha }}
- name: executing remote ssh commands using ssh key
uses: appleboy/[email protected]
with:
host: hozer-51.ocf.berkeley.edu
username: root
key: ${{ secrets.SSH_KEY }}
port: 22
script: |
helm install bt-dev-app-${{ github.sha }} ./app --namespace=bt \
--set host=${{ github.event.client_payload.param1 }}.stanfurdtime.com \
--set mongoUri=mongodb://bt-dev-mongo-mongodb.bt.svc.cluster.local:27017/bt \
--set redisUri=redis://bt-dev-redis-master.bt.svc.cluster.local:6379 \
--set nodeEnv=development
helm release ttl bt-dev-app-${{ github.sha }} --set='${{ github.event.client_payload.param2 }}'
41 changes: 41 additions & 0 deletions .github/workflows/cd-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name:
Deploy to Prod

on:
repository_dispatch:
types: [trigger-workflow]

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build Backend Image
run: docker build -t berkeleytime-backend ./backend/
- name: Tag Backend Image
run: docker tag berkeleytime-backend ${{ secrets.DOCKER_USERNAME }}/berkeleytime-backend:prod
- name: Push Backend Image
run: docker push ${{ secrets.DOCKER_USERNAME }}/berkeleytime-backend:prod
- name: Build Frontend Image
run: docker build -t berkeleytime-frontend ./frontend/
- name: Tag Frontend Image
run: docker tag berkeleytime-frontend ${{ secrets.DOCKER_USERNAME }}/berkeleytime-frontend:prod
- name: Push Frontend Image
run: docker push ${{ secrets.DOCKER_USERNAME }}/berkeleytime-frontend:prod
- name: executing remote ssh commands using ssh key
uses: appleboy/[email protected]
with:
host: hozer-51.ocf.berkeley.edu
username: root
key: ${{ secrets.SSH_KEY }}
port: 22
script: |
kubectl rollout restart deployment bt-prod-app-backend
kubectl rollout restart deployment bt-prod-app-frontend
41 changes: 41 additions & 0 deletions .github/workflows/cd-staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name:
Deploy to Staging

on:
push:
branches: [ master ]

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build Backend Image
run: docker build -t berkeleytime-backend ./backend/
- name: Tag Backend Image
run: docker tag berkeleytime-backend ${{ secrets.DOCKER_USERNAME }}/berkeleytime-backend:staging
- name: Push Backend Image
run: docker push ${{ secrets.DOCKER_USERNAME }}/berkeleytime-backend:staging
- name: Build Frontend Image
run: docker build -t berkeleytime-frontend ./frontend/
- name: Tag Frontend Image
run: docker tag berkeleytime-frontend ${{ secrets.DOCKER_USERNAME }}/berkeleytime-frontend:staging
- name: Push Frontend Image
run: docker push ${{ secrets.DOCKER_USERNAME }}/berkeleytime-frontend:staging
- name: executing remote ssh commands using ssh key
uses: appleboy/[email protected]
with:
host: hozer-51.ocf.berkeley.edu
username: root
key: ${{ secrets.SSH_KEY }}
port: 22
script: |
kubectl rollout restart deployment bt-staging-app-backend
kubectl rollout restart deployment bt-staging-app-frontend
1 change: 1 addition & 0 deletions backend/src/bootstrap/loaders/passport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const SCOPE = ['profile', 'email']

export default async (app: Application) => {
// init
app.use('trust proxy')
app.use(session({
secret: config.SESSION_SECRET,
name: 'sessionId',
Expand Down
22 changes: 11 additions & 11 deletions backend/src/scripts/update-catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const SIS_SECTION_URL = 'https://gateway.api.berkeley.edu/sis/v1/classes/section

const semToTermId = (s: SemesterType) => {
// term-id is computed by dropping the century digit of the year, then adding the term code
const termMap: { [key: string] : number} = {'Fall': 8, 'Spring': 2, 'Summer': 5}
const termMap: { [key: string]: number } = { 'Fall': 8, 'Spring': 2, 'Summer': 5 }
return `${Math.floor(s.year / 1000)}${s.year % 100}${termMap[s.term]}`
}

Expand All @@ -31,21 +31,21 @@ const queryPages = async <T>(url: string, params: any, headers: any, field: stri
let resp: AxiosResponse<SISResponse<T>>;

try {
resp = await axios.get(url, { params: { 'page-number': page, ...params}, headers });
resp = await axios.get(url, { params: { 'page-number': page, ...params }, headers });
} catch (err) {
if (axios.isAxiosError(err) && err.response?.status === 404) {
break;
} else {
console.log(`Unexpected err querying SIS API. Error: ${err}.`)

if (retries > 0) {
retries--;
console.log(`Retrying...`)
continue;
} else {
console.log(`Too many errors querying SIS API for courses. Terminating update...`)
throw err;
}
}
}
}

Expand All @@ -71,7 +71,7 @@ const updateCourses = async () => {
const courses = await queryPages<CourseType>(SIS_COURSE_URL, params, headers, 'courses');

console.log("Updating database with new course data...")

const bulkOps = courses.map(c => ({
replaceOne: {
filter: { classDisplayName: c.classDisplayName },
Expand All @@ -80,7 +80,7 @@ const updateCourses = async () => {
}
}));

const options = { strict: 'throw' } as MongooseBulkWriteOptions;
const options = { } as MongooseBulkWriteOptions;

const res = await CourseModel.bulkWrite(bulkOps, options);

Expand All @@ -95,7 +95,7 @@ const updateClasses = async () => {

const activeSemesters = await SemesterModel.find({ active: true }).lean();
const classes: ClassType[] = [];

for (const s of activeSemesters) {
console.log(`Updating classses for ${s.term} ${s.year}...`)

Expand All @@ -117,7 +117,7 @@ const updateClasses = async () => {
}
}));

const options = { strict: 'throw' } as MongooseBulkWriteOptions;
const options = { } as MongooseBulkWriteOptions;

const res = await ClassModel.bulkWrite(bulkOps, options);

Expand All @@ -132,7 +132,7 @@ const updateSections = async () => {

const activeSemesters = await SemesterModel.find({ active: true }).lean();
const sections: SectionType[] = [];

for (const s of activeSemesters) {
console.log(`Updating sections for ${s.term} ${s.year}...`)

Expand All @@ -154,7 +154,7 @@ const updateSections = async () => {
}
}));

const options = { strict: 'throw' } as MongooseBulkWriteOptions;
const options = { } as MongooseBulkWriteOptions;

const res = await SectionModel.bulkWrite(bulkOps, options);

Expand All @@ -180,4 +180,4 @@ const updateSections = async () => {
}

process.exit(0);
})();
})();
1 change: 0 additions & 1 deletion docs
Submodule docs deleted from f4e81d
1 change: 1 addition & 0 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ ENTRYPOINT npm start

FROM dev AS prod
RUN npm install -g serve
RUN node -v
RUN npm run build
RUN rm -rf node_modules
ENTRYPOINT npm run prod
1 change: 1 addition & 0 deletions infra/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.tgz
23 changes: 23 additions & 0 deletions infra/app/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
24 changes: 24 additions & 0 deletions infra/app/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: bt-app
description: A Helm chart for the frontend and backend of the Berkeleytime application.

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "2.0.0-alpha"
37 changes: 37 additions & 0 deletions infra/app/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{{/*
Chart name and version
*/}}
{{- define "bt-app.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Labels applied to all resources.
*/}}
{{- define "bt-app.labels" -}}
helm.sh/chart: {{ include "bt-app.chart" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}

{{- define "bt-app.backendLabels" -}}
app.kubernetes.io/name: backend
{{ include "bt-app.labels" . }}
{{- end -}}

{{- define "bt-app.frontendLabels" -}}
app.kubernetes.io/name: frontend
{{ include "bt-app.labels" . }}
{{- end -}}

{{- define "bt-app.backendName" -}}
{{ .Release.Name }}-backend
{{- end -}}

{{- define "bt-app.frontendName" -}}
{{ .Release.Name }}-frontend
{{- end -}}

{{- define "bt-app.cronJobName" -}}
{{ .Release.Name }}-cronjob
{{- end -}}
Loading
Loading