Skip to content

Commit

Permalink
ci: run migrations via init container (#7663)
Browse files Browse the repository at this point in the history
* chore: split auth/dt/migration start

* chore: migrations via init container

* chore: no checks before migration

* chore: indicate celery start

* chore: additional log output
  • Loading branch information
jennifer-richards authored Jul 10, 2024
1 parent 3996137 commit 9c95689
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 6 deletions.
2 changes: 2 additions & 0 deletions dev/build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ RUN echo "deb http://deb.debian.org/debian bullseye-backports main" > /etc/apt/s
COPY . .
COPY ./dev/build/start.sh ./start.sh
COPY ./dev/build/datatracker-start.sh ./datatracker-start.sh
COPY ./dev/build/migration-start.sh ./migration-start.sh
COPY ./dev/build/celery-start.sh ./celery-start.sh
COPY ./dev/build/gunicorn.conf.py ./gunicorn.conf.py

Expand All @@ -27,6 +28,7 @@ RUN pip3 --disable-pip-version-check --no-cache-dir install -r requirements.txt

RUN chmod +x start.sh && \
chmod +x datatracker-start.sh && \
chmod +x migration-start.sh && \
chmod +x celery-start.sh && \
chmod +x docker/scripts/app-create-dirs.sh && \
sh ./docker/scripts/app-create-dirs.sh
Expand Down
5 changes: 4 additions & 1 deletion dev/build/celery-start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ echo "Running Datatracker checks..."
if ! ietf/manage.py migrate --skip-checks --check ; then
echo "Unapplied migrations found, waiting to start..."
sleep 5
while ! ietf/manage.py migrate --skip-checks --check ; do
while ! ietf/manage.py migrate --skip-checks --check ; do
echo "... still waiting for migrations..."
sleep 5
done
fi

echo "Starting Celery..."

cleanup () {
# Cleanly terminate the celery app by sending it a TERM, then waiting for it to exit.
if [[ -n "${celery_pid}" ]]; then
Expand Down
10 changes: 8 additions & 2 deletions dev/build/datatracker-start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
echo "Running Datatracker checks..."
./ietf/manage.py check

echo "Running Datatracker migrations..."
./ietf/manage.py migrate --skip-checks --settings=settings_local
if ! ietf/manage.py migrate --skip-checks --check ; then
echo "Unapplied migrations found, waiting to start..."
sleep 5
while ! ietf/manage.py migrate --skip-checks --check ; do
echo "... still waiting for migrations..."
sleep 5
done
fi

echo "Starting Datatracker..."

Expand Down
6 changes: 6 additions & 0 deletions dev/build/migration-start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

echo "Running Datatracker migrations..."
./ietf/manage.py migrate --skip-checks --settings=settings_local

echo "Done!"
12 changes: 9 additions & 3 deletions dev/build/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@
# CONTAINER_ROLE - datatracker, celery, or beat (defaults to datatracker)
#
case "${CONTAINER_ROLE:-datatracker}" in
datatracker)
auth)
exec ./datatracker-start.sh
;;
beat)
exec ./celery-start.sh --app=ietf beat
;;
celery)
exec ./celery-start.sh --app=ietf worker
;;
beat)
exec ./celery-start.sh --app=ietf beat
datatracker)
exec ./datatracker-start.sh
;;
migrations)
exec ./migration-start.sh
;;
*)
echo "Unknown role '${CONTAINER_ROLE}'"
Expand Down
29 changes: 29 additions & 0 deletions k8s/datatracker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,35 @@ spec:
readOnlyRootFilesystem: true
runAsUser: 1000
runAsGroup: 1000
initContainers:
- name: migration
image: "ghcr.io/ietf-tools/datatracker:$APP_IMAGE_TAG"
env:
- name: "CONTAINER_ROLE"
value: "migrations"
envFrom:
- configMapRef:
name: django-config
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
readOnlyRootFilesystem: true
runAsUser: 1000
runAsGroup: 1000
volumeMounts:
- name: dt-vol
mountPath: /a
- name: dt-tmp
mountPath: /tmp
- name: dt-home
mountPath: /home/datatracker
- name: dt-xml2rfc-cache
mountPath: /var/cache/xml2rfc
- name: dt-cfg
mountPath: /workspace/ietf/settings_local.py
subPath: settings_local.py
volumes:
# To be overriden with the actual shared volume
- name: dt-vol
Expand Down

0 comments on commit 9c95689

Please sign in to comment.