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

Nightly Mongo Dev Updater #748

Merged
merged 25 commits into from
Feb 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
dfa7dcc
Create mongo-reset.yaml for nightly update workflow
klhftco Nov 21, 2024
2da7952
temp push
klhftco Nov 21, 2024
fa67fc3
Update mongo-reset.yaml after registering in actions tab
klhftco Nov 21, 2024
868b81b
check triggers
klhftco Nov 21, 2024
89ba0e8
push to register action again
klhftco Nov 21, 2024
3c0312c
pull cron while migrating to k8 cronjob
klhftco Nov 21, 2024
f1f09cd
Create mongo-reset.yaml cronjob in k8 infra
klhftco Nov 21, 2024
b615fab
Delete .github/workflows/mongo-reset.yaml
klhftco Nov 21, 2024
639baee
Create mongo-reset.yaml for manual triggering
klhftco Nov 22, 2024
d002192
add image version, latest tag doesn't exist for alpine/k8s
klhftco Dec 4, 2024
67426ad
add service account
maxmwang Dec 4, 2024
f99cae8
drop dev database
maxmwang Dec 4, 2024
270360b
polish cronjob
maxmwang Dec 4, 2024
2df85b6
update github action to log output (succeed on proper job execution),…
klhftco Dec 4, 2024
8d879f8
register github action first run
klhftco Dec 4, 2024
cccf8da
remove push trigger for github action, fix typo
klhftco Dec 4, 2024
083a867
rename files and k8s role
maxmwang Feb 1, 2025
1758d21
Merge branch 'gql' into gql-mongo-dev
maxmwang Feb 1, 2025
c44e100
forbid concurrency
maxmwang Feb 1, 2025
9c34fb7
add bt prefix to name
maxmwang Feb 1, 2025
6349d77
fix comment in helm chart
maxmwang Feb 1, 2025
9418f05
remove chart
maxmwang Feb 1, 2025
13edaf2
add labels to datapuller
maxmwang Feb 2, 2025
4f52d61
fix name
maxmwang Feb 2, 2025
8cb8631
fix pod query
maxmwang Feb 2, 2025
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
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/[email protected]
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 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/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