Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/gql' into gql
Browse files Browse the repository at this point in the history
  • Loading branch information
mathhulk committed Feb 4, 2025
2 parents 06d4ff0 + d8fa184 commit 20c68a4
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 9 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/runbook-reset-dev-mongo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Reset Dev Mongo

on:
workflow_dispatch:

jobs:
reset-mongo:
name: SSH and Reset Dev MongoDB State
runs-on: ubuntu-latest
steps:
- name: SSH and Reset MongoDB
uses: appleboy/ssh-action@v1.2.0
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
script: |
set -e # Exit immediately if a command fails
# Create Mongo job from mongo-reset
kubectl create job --from=cronjob/bt-base-reset-dev-mongo bt-base-reset-dev-mongo-ga-manual
echo "MongoDB reset scheduled."
# Wait for job_pod log output
job_pod=$(kubectl get pods -o custom-columns=NAME:.metadata.name --no-headers -n bt | grep 'bt-base-reset-dev-mongo-ga-manual')
kubectl wait --for=condition=ready pod/$job_pod -n bt --timeout=30s
kubectl logs -f $job_pod -n bt
2 changes: 1 addition & 1 deletion apps/backend/src/bootstrap/loaders/apollo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default async (redis: RedisClientType) => {
}),
responseCachePlugin(),
],
// TODO(production): Disable introspection in production
// TODO(prod): introspection: config.isDev,
introspection: true,
cache: new RedisCache(redis),
});
Expand Down
8 changes: 8 additions & 0 deletions apps/datapuller/src/pullers/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import setup from "../shared";
import { Config } from "../shared/config";
import updateClasses from "./classes";
import updateCourses from "./courses";
import updateEnrollmentHistories from "./enrollment";
import updateGradeDistributions from "./grade-distributions";
import updateSections from "./sections";

const testDatabaseWrite = async (config: Config) => {
Expand Down Expand Up @@ -51,6 +53,12 @@ const main = async () => {
config.log.info("\n=== UPDATE CLASSES ===");
await updateClasses(config);

config.log.info("\n=== UPDATE ENROLLMENTS ===");
await updateEnrollmentHistories(config);

config.log.info("\n=== UPDATE GRADES ===");
await updateGradeDistributions(config);

config.log.info("\n=== DATA PULLING COMPLETED ===");
} catch (error) {
config.log.error(error);
Expand Down
18 changes: 18 additions & 0 deletions docs/src/getting-started/local-development.md
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
# Local Development

## Seeding Local Database

A seeded database is required for some pages on the frontend.

```sh
# ./berkeleytime

# Ensure the MongoDB instance is already running.
docker compose up -d

# Download the data
curl -O https://storage.googleapis.com/berkeleytime/public/stage_backup.gz

# Copy the data and restore
docker cp ./stage_backup.gz berkeleytime-mongodb-1:/tmp/stage_backup.gz
docker exec berkeleytime-mongodb-1 mongorestore --drop --gzip --archive=/tmp/stage_backup.gz
```
2 changes: 1 addition & 1 deletion infra/app/templates/cleanup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ metadata:
spec:
template:
spec:
serviceAccountName: bt-app-cleanup
serviceAccountName: bt-k8s-role
containers:
- name: cleanup
image: alpine/helm
Expand Down
2 changes: 2 additions & 0 deletions infra/app/templates/datapuller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ spec:
spec:
template:
spec:
labels:
{{- include "bt-app.datapullerLabels" $root | nindent 12 }}
containers:
- name: datapuller-{{ $jobName }}
image: {{ printf "%s/%s:%s" $jobConfig.image.registry $jobConfig.image.repository ( toString $jobConfig.image.tag ) }}
Expand Down
2 changes: 1 addition & 1 deletion infra/app/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ttl: 24 # in hours
host: berkeleytime.com
port: 80

mongoUri: mongodb://bt-prod-mongo-mongodb.bt.svc.cluster.local:27017/bt # TODO(core): change to replicaset
mongoUri: mongodb://bt-prod-mongo-mongodb-0.bt-prod-mongo-mongodb-headless.bt.svc.cluster.local:27017/bt
redisUri: redis://bt-prod-redis-master.bt.svc.cluster.local:6379
nodeEnv: production

Expand Down
2 changes: 1 addition & 1 deletion infra/base/templates/issuer.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{ /* https://cert-manager.io/docs/configuration/acme/dns01/cloudflare/#api-tokens */ }}
{{- /* https://cert-manager.io/docs/configuration/acme/dns01/cloudflare/#api-tokens */ -}}
apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: bt-app-cleanup
name: bt-k8s-role

---

apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: bt-app-cleanup
name: bt-k8s-role
rules:
- apiGroups: ["*"]
resources: ["*"]
Expand All @@ -19,12 +19,12 @@ rules:
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: bt-app-cleanup
name: bt-k8s-role
subjects:
- kind: ServiceAccount
name: bt-app-cleanup
name: bt-k8s-role
apiGroup: ""
roleRef:
kind: Role
name: bt-app-cleanup
name: bt-k8s-role
apiGroup: "rbac.authorization.k8s.io"
53 changes: 53 additions & 0 deletions infra/base/templates/reset-dev-mongo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
apiVersion: batch/v1
kind: CronJob
metadata:
name: {{ .Release.Name }}-reset-dev-mongo
namespace: bt
spec:
schedule: "0 5 * * *" # Daily at 5 AM, after datapuller
timeZone: America/Los_Angeles
concurrencyPolicy: Forbid
suspend: false
jobTemplate:
spec:
ttlSecondsAfterFinished: 180
template:
spec:
serviceAccountName: bt-k8s-role
containers:
- name: reset-dev-mongo
image: alpine/k8s:1.29.11
command:
- sh
- -c
- |
set -e # Exit immediately if a command fails
# Find stage and dev MongoDB pods
stage_pod=$(kubectl get pods -o custom-columns=NAME:.metadata.name --no-headers -n bt | grep 'bt-stage-mongo')
dev_pod=$(kubectl get pods -o custom-columns=NAME:.metadata.name --no-headers -n bt | grep 'bt-dev-mongo')
# Dump staging MongoDB state
echo "Dumping staging MongoDB state..."
kubectl exec --namespace=bt \
"$stage_pod" -- mongodump --archive=/tmp/stage_backup.gz --gzip
kubectl cp --namespace=bt \
"$stage_pod:/tmp/stage_backup.gz" /tmp/stage_backup.gz
kubectl exec --namespace=bt \
"$stage_pod" -- rm /tmp/stage_backup.gz
# Restore dump into dev MongoDB
echo "Restoring dump into dev MongoDB..."
kubectl cp --namespace=bt \
/tmp/stage_backup.gz "$dev_pod:/tmp/stage_backup.gz"
kubectl exec --namespace=bt \
"$dev_pod" -- mongosh bt --eval "db.dropDatabase()"
kubectl exec --namespace=bt \
"$dev_pod" -- mongorestore --archive=/tmp/stage_backup.gz --gzip --drop
kubectl exec --namespace=bt \
"$dev_pod" -- rm /tmp/stage_backup.gz
# Cleanup local files
rm /tmp/stage_backup.gz
echo "MongoDB reset completed successfully!"
restartPolicy: Never

0 comments on commit 20c68a4

Please sign in to comment.