Skip to content

Commit b19d5fc

Browse files
committed
chore(charts): add migrate job
1 parent cc6f2b5 commit b19d5fc

7 files changed

Lines changed: 109 additions & 16 deletions

File tree

charts/passport/templates/_helpers.tpl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ rbac.authorization.k8s.io/v1
1414
{{/* Generate passport deployment envs */}}
1515
{{- define "passport.envs" }}
1616
env:
17-
- name: "TZ"
17+
- name: TZ
1818
value: {{ .Values.time_zone | default "UTC" | quote }}
19+
- name: VERSION
20+
value: {{ .Chart.AppVersion }}
1921
- name: ADMIN_USERNAME
2022
value: {{ .Values.adminUsername | default "admin" | quote }}
2123
- name: ADMIN_PASSWORD

charts/passport/templates/passport-deployment.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ spec:
3737
- -u
3838
- $(DRYCC_DATABASE_URL),$(DRYCC_DATABASE_REPLICA_URL)
3939
{{- include "passport.envs" . | indent 8 }}
40+
- name: drycc-passport-waitting
41+
image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/passport:{{.Values.imageTag}}
42+
imagePullPolicy: {{.Values.imagePullPolicy}}
43+
args:
44+
- /usr/bin/env
45+
- bash
46+
- -ec
47+
- |
48+
python -u /workspace/manage.py cluster_lock waitting
49+
{{- include "passport.limits" . | indent 8 }}
50+
{{- include "passport.envs" . | indent 8 }}
51+
{{- include "passport.volumeMounts" . | indent 8 }}
4052
containers:
4153
- name: drycc-passport
4254
image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/passport:{{.Values.imageTag}}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
apiVersion: batch/v1
2+
kind: Job
3+
metadata:
4+
name: drycc-passport-job-upgrade-{{ now | date "20060102150405" }}
5+
labels:
6+
heritage: drycc
7+
annotations:
8+
component.drycc.cc/version: {{ .Values.imageTag }}
9+
spec:
10+
template:
11+
metadata:
12+
labels: {{- include "common.labels.standard" . | nindent 8 }}
13+
app: drycc-passport-job-upgrade
14+
spec:
15+
initContainers:
16+
- name: drycc-passport-init
17+
image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/python-dev:latest
18+
imagePullPolicy: {{.Values.imagePullPolicy}}
19+
args:
20+
- netcat
21+
- -v
22+
- -u
23+
- $(DRYCC_DATABASE_URL),$(DRYCC_DATABASE_REPLICA_URL)
24+
{{- include "passport.envs" . | indent 8 }}
25+
containers:
26+
- name: drycc-passport-job-upgrade
27+
image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/passport:{{.Values.imageTag}}
28+
imagePullPolicy: {{.Values.imagePullPolicy}}
29+
{{- if .Values.diagnosticMode.enabled }}
30+
command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 8 }}
31+
args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 8 }}
32+
{{- else }}
33+
args:
34+
- /usr/bin/env
35+
- bash
36+
- -ec
37+
- |
38+
python -u /workspace/manage.py cluster_lock lock
39+
python -u /workspace/manage.py migrate --noinput
40+
python -u /workspace/manage.py cluster_lock unlock
41+
{{- end }}
42+
{{- include "passport.limits" . | indent 8 }}
43+
{{- include "passport.envs" . | indent 8 }}
44+
{{- include "passport.volumeMounts" . | indent 8 }}
45+
{{- include "passport.volumes" . | indent 6 }}
46+
restartPolicy: Never
47+
backoffLimit: 0
48+
ttlSecondsAfterFinished: 3600
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import time
2+
from django.core.management.base import BaseCommand
3+
from django.core.cache import cache
4+
from django.conf import settings
5+
6+
lock_key = "drycc:passport:version"
7+
waitting_init_msg = "version inconsistency %s!=%s, waiting for initialization to complete..."
8+
9+
10+
class Command(BaseCommand):
11+
12+
def add_arguments(self, parser):
13+
parser.add_argument(
14+
"args",
15+
metavar="action",
16+
nargs="+",
17+
choices=["lock", "unlock", "waitting"],
18+
help="an action that needs to be executed.",
19+
)
20+
21+
def lock(self):
22+
cache.delete(lock_key)
23+
print("lock completed!")
24+
25+
def unlock(self):
26+
cache.set(lock_key, settings.VERSION, timeout=None)
27+
print("unlock completed!")
28+
29+
def waitting(self):
30+
while True:
31+
version = cache.get(lock_key, None)
32+
if version != settings.VERSION:
33+
print(waitting_init_msg % (version, settings.VERSION))
34+
else:
35+
break
36+
time.sleep(10)
37+
print("waiting completed!")
38+
39+
def handle(self, *args, **options):
40+
action = args[0]
41+
getattr(self, action)()

rootfs/api/management/commands/cluster_migrate.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

rootfs/api/settings/production.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@
66
For the full list of settings and their values, see
77
https://docs.djangoproject.com/en/2.2/ref/settings/
88
"""
9+
import uuid
910
import os.path
1011
import ldap
1112
import dj_database_url
1213
from django_auth_ldap.config import LDAPSearch, GroupOfNamesType
1314

1415
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
16+
17+
# drycc passport app version.
18+
VERSION = os.environ.get('VERSION', uuid.uuid1().hex[:8])
19+
1520
# SECURITY WARNING: don't run with debug turned on in production!
1621
DEBUG = os.environ.get('DRYCC_DEBUG', 'false').lower() == "true"
1722

rootfs/bin/boot

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ echo ""
2222
echo "Health Checks:"
2323
python /workspace/manage.py healthchecks
2424

25-
echo ""
26-
echo "Database Migrations:"
27-
python /workspace/manage.py cluster_migrate --noinput
28-
2925
echo ""
3026
echo "Collect static files in a single location:"
3127
python manage.py collectstatic --noinput

0 commit comments

Comments
 (0)