-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'refs/remotes/origin/gql' into gql
- Loading branch information
Showing
10 changed files
with
117 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |