Skip to content

Commit

Permalink
Feature/argo hook (#103)
Browse files Browse the repository at this point in the history
* Add argocd hooks for migraitons and collectstatic

* Fix argoCD hook issues

- Lower docker file size
  • Loading branch information
thenav56 authored Nov 27, 2024
1 parent 252a8f2 commit 83c5f70
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/
1 change: 0 additions & 1 deletion deploy/run_web.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
50 changes: 50 additions & 0 deletions helm/templates/argo-hooks/hook-job.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
11 changes: 11 additions & 0 deletions helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 11 additions & 13 deletions main/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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"):

Expand Down

0 comments on commit 83c5f70

Please sign in to comment.