Skip to content

Commit

Permalink
Add Argo hooks Implementation (#2320)
Browse files Browse the repository at this point in the history
* Add argocd hooks implementation and annotation in celery chart

* Add pullpolicy set to IfNotPresent

* fix Elastic search host issue on configmap
Add github workflow_dispatch

* Disable argoHooks by default

- Ignore values-local.yaml

---------

Co-authored-by: thenav56 <[email protected]>
  • Loading branch information
susilnem and thenav56 authored Feb 7, 2025
1 parent ea31843 commit c1d6cfb
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/build-publish-docker-helm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Builds and pushes Docker Images and Helm charts to Github Registry
on:
# Build and push Docker image and Helm charts on every push to develop branch
# and on every tag push
workflow_dispatch:
push:
branches:
- develop
Expand Down
1 change: 1 addition & 0 deletions deploy/helm/ifrcgo-helm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
values-local.yaml
1 change: 1 addition & 0 deletions deploy/helm/ifrcgo-helm/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
values-local.yaml
44 changes: 44 additions & 0 deletions deploy/helm/ifrcgo-helm/templates/argo-hooks/hook-job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{{- if .Values.argoHooksEnabled }} # FIXME: Remove this after go-api is moved to argoCD pipeline

{{- range $hookName, $hook := .Values.argoHooks }}

{{- if $hook.enabled }}

---
apiVersion: batch/v1
kind: Job
metadata:
{{- if $hook.preserveHistory }}
generateName: {{ template "ifrcgo-helm.fullname" $ }}-{{ $hookName }}-
{{- else }}
name: {{ template "ifrcgo-helm.fullname" $ }}-{{ $hookName }}
{{- end }}
annotations:
argocd.argoproj.io/hook: {{ $hook.hook }}

spec:
template:
spec:
restartPolicy: "Never"
containers:
- name: {{ $hookName }}
image: "{{ $.Values.api.image.name }}:{{ $.Values.api.image.tag }}"
imagePullPolicy: {{ $.Values.api.image.pullPolicy }}
command: {{ toYaml $hook.command | trim | nindent 12 }}
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 }}
envFrom:
- secretRef:
name: {{ template "ifrcgo-helm.fullname" $ }}-api-secret
- configMapRef:
name: {{ template "ifrcgo-helm.fullname" $ }}-api-configmap

{{- end }}

{{- end }}
{{- end }}
3 changes: 3 additions & 0 deletions deploy/helm/ifrcgo-helm/templates/celery/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ spec:
run: {{ .Release.Name }}-celery
template:
metadata:
annotations:
checksum/secret: {{ include (print .Template.BasePath "/config/secret.yaml") . | sha256sum }}
checksum/configmap: {{ include (print .Template.BasePath "/config/configmap.yaml") . | sha256sum }}
labels:
app: {{ template "ifrcgo-helm.name" . }}
release: {{ .Release.Name }}
Expand Down
2 changes: 1 addition & 1 deletion deploy/helm/ifrcgo-helm/templates/config/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ data:
CACHE_REDIS_URL: "redis://{{ template "ifrcgo-helm.fullname" . }}-redis:6379/1"
CACHE_MIDDLEWARE_SECONDS: {{ .Values.env.CACHE_MIDDLEWARE_SECONDS | quote }}
DJANGO_DEBUG: {{ .Values.env.DJANGO_DEBUG | quote }}
ELASTIC_SEARCH_HOST: "elasticsearch://{{ template "ifrcgo-helm.fullname" . }}-elasticsearch:9200" #FIXME: double check format
ELASTIC_SEARCH_HOST: {{ default (printf "elasticsearch://%s-elasticsearch:9200" (include "ifrcgo-helm.fullname" .)) .Values.env.ELASTIC_SEARCH_HOST | quote }}
ELASTIC_SEARCH_INDEX: {{ .Values.env.ELASTIC_SEARCH_INDEX | quote }}
DOCKER_HOST_IP: {{ .Values.env.DOCKER_HOST_IP | quote }}
DJANGO_ADDITIONAL_ALLOWED_HOSTS: {{ .Values.env.DJANGO_ADDITIONAL_ALLOWED_HOSTS | quote }}
Expand Down
14 changes: 14 additions & 0 deletions deploy/helm/ifrcgo-helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ api:
image:
name: 'SET-BY-CHARTPRESS'
tag: 'set-by-chartpress'
pullPolicy: 'IfNotPresent'
resources:
requests:
cpu: "2"
Expand Down Expand Up @@ -123,6 +124,19 @@ celery:
cpu: "2"
memory: 4Gi

argoHooksEnabled: false # FIXME: Remove this after go-api is moved to argoCD pipeline
argoHooks:
# NOTE: Make sure keys are lowercase
database-migration:
enabled: true
hook: PostSync
preserveHistory: true
command: ["./manage.py", "migrate"]
collect-static:
enabled: true
hook: PostSync
command: ["./manage.py", "collectstatic", "--noinput"]

cronjobs:
- command: 'index_and_notify'
schedule: '*/5 * * * *'
Expand Down

0 comments on commit c1d6cfb

Please sign in to comment.