diff --git a/.gitignore b/.gitignore index 74e5f63a..573cb1d5 100644 --- a/.gitignore +++ b/.gitignore @@ -32,6 +32,7 @@ MANIFEST # before PyInstaller builds the exe, so as to inject date/other infos into it. *.manifest *.spec +.aider* # Installer logs pip-log.txt diff --git a/Dockerfile b/Dockerfile index 1acc8b26..b3e3fa4b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,12 +22,13 @@ RUN apt-get update -y \ && poetry --version \ # Configure to use system instead of virtualenvs && poetry config virtualenvs.create false \ - && poetry install --no-root \ + && poetry install --no-root --no-cache --no-interaction \ # Clean-up && pip uninstall -y poetry virtualenv-clone virtualenv \ && apt-get remove -y gcc libc-dev libproj-dev \ && apt-get autoremove -y \ - && rm -rf /var/lib/apt/lists/* + && rm -rf /var/lib/apt/lists/* \ + && rm -rf /root/.cache/ COPY . /code/ diff --git a/deploy/run_web.sh b/deploy/run_web.sh index be28be5c..aba007c5 100755 --- a/deploy/run_web.sh +++ b/deploy/run_web.sh @@ -8,6 +8,5 @@ cd $ROOT_DIR wait-for-it $DB_HOST:$DB_PORT -./manage.py collectstatic --no-input & ./manage.py compilemessages --ignore ".venv" uwsgi --ini ./deploy/uwsgi.ini # Start uwsgi server diff --git a/helm/templates/argo-hooks/hook-job.yaml b/helm/templates/argo-hooks/hook-job.yaml new file mode 100644 index 00000000..904fe33f --- /dev/null +++ b/helm/templates/argo-hooks/hook-job.yaml @@ -0,0 +1,50 @@ +{{- range $hookName, $hook := .Values.argoHooks }} + +{{- if $hook.enabled }} + +--- +apiVersion: batch/v1 +kind: Job +metadata: + {{- if $hook.preservehistory }} + generateName: {{ template "ifrcgo-alert-hub.fullname" $ }}-{{ $hookName }}- + {{- else }} + name: {{ template "ifrcgo-alert-hub.fullname" $ }}-{{ $hookName }} + {{- end }} + annotations: + argocd.argoproj.io/hook: {{ $hook.hook }} +spec: + template: + spec: + restartPolicy: "Never" + containers: + - name: {{ $hookName }} + image: "{{ $.Values.image.name }}:{{ $.Values.image.tag }}" + command: + {{- range $hook.command }} + - "{{ . }}" + {{- end }} + resources: + requests: + cpu: {{ default $.Values.api.resources.requests.cpu $hook.requestsCpu }} + memory: {{ default $.Values.api.resources.requests.memory $hook.requestsMemory }} + limits: + cpu: {{ default $.Values.api.resources.limits.cpu $hook.limitsCpu }} + memory: {{ default $.Values.api.resources.limits.memory $hook.limitsMemory }} + env: + - name: DJANGO_APP_TYPE + value: hook + envFrom: + - secretRef: + name: {{ template "ifrcgo-alert-hub.secretname" $ }} + - configMapRef: + name: {{ template "ifrcgo-alert-hub.fullname" $ }}-api-configmap + + {{- with $.Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + +{{- end }} + +{{- end }} diff --git a/helm/values.yaml b/helm/values.yaml index e258e334..d94a2843 100644 --- a/helm/values.yaml +++ b/helm/values.yaml @@ -67,6 +67,17 @@ worker: cpu: "1" memory: 1Gi +argoHooks: + # NOTE: Make sure keys are lowercase + db-migrate: + enabled: true + hook: PostSync + preservehistory: true + command: ["./manage.py", "migrate"] + collect-static: + enabled: true + hook: PostSync + command: ["./manage.py", "collectstatic", "--noinput"] env: # DJANGO_APP_ENVIRONMENT: using .environment diff --git a/main/settings.py b/main/settings.py index 034db4b3..b9e14c92 100644 --- a/main/settings.py +++ b/main/settings.py @@ -26,7 +26,7 @@ DJANGO_DEBUG=(bool, False), DJANGO_SECRET_KEY=str, DJANGO_TIME_ZONE=(str, 'UTC'), - DJANGO_APP_TYPE=str, # web/worker + DJANGO_APP_TYPE=str, # web/worker/hook DJANGO_APP_ENVIRONMENT=str, # dev/prod # App Domain APP_RELEASE=(str, 'develop'), @@ -143,16 +143,16 @@ ] MIDDLEWARE = [ - 'django.middleware.security.SecurityMiddleware', - 'django.contrib.sessions.middleware.SessionMiddleware', - 'corsheaders.middleware.CorsMiddleware', - 'django.middleware.locale.LocaleMiddleware', - 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - 'django.middleware.clickjacking.XFrameOptionsMiddleware', - 'main.middlewares.SentryTransactionMiddleware', + "django.middleware.security.SecurityMiddleware", + "django.contrib.sessions.middleware.SessionMiddleware", + "corsheaders.middleware.CorsMiddleware", + "django.middleware.locale.LocaleMiddleware", + "django.middleware.common.CommonMiddleware", + "django.middleware.csrf.CsrfViewMiddleware", + "django.contrib.auth.middleware.AuthenticationMiddleware", + "django.contrib.messages.middleware.MessageMiddleware", + "django.middleware.clickjacking.XFrameOptionsMiddleware", + "main.middlewares.SentryTransactionMiddleware", ] AUTHENTICATION_BACKENDS = [ @@ -257,11 +257,9 @@ # TODO: Use custom config for static files STATICFILES_DIRS = (str(BASE_DIR.joinpath('static')),) - STATIC_URL = env("DJANGO_STATIC_URL") MEDIA_URL = env("DJANGO_MEDIA_URL") -# Django storage if env("USE_AZURE_STORAGE"):