Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smartbirds server static pvc and cronjobs #11

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion charts/smartbirds-server/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.5
version: 0.2.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
6 changes: 6 additions & 0 deletions charts/smartbirds-server/ci/ct-values.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
persistence:
accessMode: ReadWriteOnce

cron:
enabled: false

redis:
architecture: standalone
37 changes: 37 additions & 0 deletions charts/smartbirds-server/templates/_containers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{{/*
Define container image and pull policy
Usage:
{{ include "smartbirds-server.container.image" (dict "values" .Values.image "ctx" $) }}
*/}}
{{- define "smartbirds-server.container.image" -}}
{{- $values := default .values .ctx.Values.image -}}
image: "{{ $values.repository }}:{{ $values.tag | default .ctx.Chart.AppVersion }}"
imagePullPolicy: {{ $values.pullPolicy }}
{{- end -}}

{{/*
Define common container environment
Usage:
{{ include "smartbirds-server.container.common-env" $ }}
*/}}
{{- define "smartbirds-server.container.common-env" -}}
- name: NODE_ENV
value: production
- name: DATABASE_URL
value: "postgres://{{ $.Values.postgresql.postgresqlUsername }}:{{ $.Values.postgresql.postgresqlPassword }}@{{ $.Release.Name }}-postgresql:{{ $.Values.postgresql.containerPorts.postgresql }}/{{ $.Values.postgresql.postgresqlDatabase }}"
- name: REDIS_HOST
value: "{{ $.Release.Name }}-redis-master"
- name: REDIS_PASS
valueFrom:
secretKeyRef:
name: "{{ $.Release.Name }}-redis"
key: "redis-password"
{{- if $.Values.smartbirds.serverToken }}
- name: SERVER_TOKEN
value: {{ $.Values.smartbirds.serverToken | quote }}
{{- end }}
{{- if $.Values.smartbirds.sentry.enabled }}
- name: SENTRY_DSN
value: {{ $.Values.smartbirds.sentry.dsn | quote }}
{{- end }}
{{- end -}}
24 changes: 24 additions & 0 deletions charts/smartbirds-server/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,30 @@ If release name contains chart name it will be used as a full name.
{{- end }}
{{- end }}

{{/*
Create a default fully qualified static name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
*/}}
{{- define "smartbirds-server.static.fullname" -}}
{{- if .Values.static.fullnameOverride -}}
{{- .Values.static.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" (include "smartbirds-server.fullname" .) .Values.static.name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}

{{/*
Create a default fully qualified uploads name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
*/}}
{{- define "smartbirds-server.uploads.fullname" -}}
{{- if .Values.uploads.fullnameOverride -}}
{{- .Values.uploads.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" (include "smartbirds-server.fullname" .) .Values.uploads.name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
Expand Down
37 changes: 37 additions & 0 deletions charts/smartbirds-server/templates/_jobs.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{{/*
Create a job definition to enqueue task
Usage:
{{ include "smartbirds-server.job.enqueue" ("values" (dict "name" "job-name" "taskName" "task-name" "taskArgs" (dict "opt1" "val1)) "ctx" $) }}
*/}}
{{- define "smartbirds-server.job.enqueue" -}}
metadata:
labels:
{{- include "smartbirds-server.labels" .ctx | nindent 4 }}
app.kubernetes.io/component: enqueue-{{ .values.name }}
spec:
{{- with .ctx.Values.imagePullSecrets }}
imagePullSecrets: {{- toYaml . | nindent 4 }}
{{- end }}
restartPolicy: {{ .values.restartPolicy | default "OnFailure" }}
serviceAccountName: {{ include "smartbirds-server.serviceAccountName" .ctx }}
securityContext: {{- toYaml .ctx.Values.podSecurityContext | nindent 4 }}
containers:
- name: {{ .ctx.Chart.Name }}-enqueue-{{ .values.name }}
securityContext: {{- toYaml (default .values.securityContext .ctx.Values.securityContext) | nindent 8 }}
{{- include "smartbirds-server.container.image" (dict "ctx" .ctx) | nindent 6 }}
command:
- /usr/local/bin/npm
- run
- ah
- --
- task
- enqueue
- --name={{ .values.taskName }}
{{- if .values.taskArgs }}
- --args={{ toJson .values.taskArgs }}
{{- end }}
env: {{- include "smartbirds-server.container.common-env" .ctx | nindent 8 }}
{{- if .values.resources }}
resources: {{- toYaml .values.resources | nindent 8 }}
{{- end }}
{{- end -}}
20 changes: 20 additions & 0 deletions charts/smartbirds-server/templates/cronjobs.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{- if .Values.cron.enabled }}
{{- range .Values.cron.jobs }}
{{- if .enabled }}
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: {{ include "smartbirds-server.fullname" $ }}-{{ .name }}
labels:
{{- include "smartbirds-server.labels" $ | nindent 4 }}
spec:
concurrencyPolicy: {{ .concurency }}
schedule: {{ .schedule | quote }}
successfulJobsHistoryLimit: {{ .historyLimit | default 1 }}
jobTemplate:
spec:
template: {{- include "smartbirds-server.job.enqueue" (dict "values" . "ctx" $) | nindent 8 }}
{{- end }}
{{- end }}
{{- end }}
41 changes: 15 additions & 26 deletions charts/smartbirds-server/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,18 @@ spec:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
securityContext: {{- toYaml .Values.securityContext | nindent 12 }}
{{- include "smartbirds-server.container.image" (dict "ctx" $) | nindent 10 }}
ports:
- name: http
containerPort: 5000
protocol: TCP
env:
- name: NODE_ENV
value: production
{{- include "smartbirds-server.container.common-env" $ | nindent 12 }}
- name: PORT
value: "5000"
- name: DATABASE_URL
value: "postgres://{{ .Values.postgresql.postgresqlUsername }}:{{ .Values.postgresql.postgresqlPassword }}@{{ .Release.Name }}-postgresql:{{ .Values.postgresql.containerPorts.postgresql }}/{{ .Values.postgresql.postgresqlDatabase }}"
- name: REDIS_HOST
value: "{{ .Release.Name }}-redis-master"
- name: REDIS_PASS
valueFrom:
secretKeyRef:
name: "{{ .Release.Name }}-redis"
key: "redis-password"
- name: ORPHAN_OWNER
value: {{ .Values.smartbirds.orphanOwner | quote }}
{{- if .Values.smartbirds.serverToken }}
- name: SERVER_TOKEN
value: {{ .Values.smartbirds.serverToken | quote }}
{{- end }}
{{- if .Values.smartbirds.session.duration }}
- name: SESSION_DURATION
value: {{ .Values.smartbirds.session.duration | quote }}
Expand Down Expand Up @@ -87,10 +71,6 @@ spec:
- name: MAILCHIMP_LIST_ID
value: {{ .Values.smartbirds.mailchimp.listId | quote }}
{{- end }}
{{- if .Values.smartbirds.sentry.enabled }}
- name: SENTRY_DSN
value: {{ .Values.smartbirds.sentry.dsn | quote }}
{{- end }}
livenessProbe:
httpGet:
path: /api/status
Expand All @@ -102,16 +82,25 @@ spec:
volumeMounts:
- mountPath: /app/uploads/files
name: uploads
- mountPath: /app/public
name: static
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumes:
- name: uploads
{{- if .Values.persistence.enabled }}
{{- if .Values.uploads.persistence.enabled }}
persistentVolumeClaim:
claimName: {{ .Values.uploads.persistence.existingClaim | default (include "smartbirds-server.uploads.fullname" .) }}
{{- else }}
emptyDir: {}
{{- end }}
- name: static
{{- if .Values.static.persistence.enabled }}
persistentVolumeClaim:
claimName: {{ .Values.persistence.existingClaim | default (include "smartbirds-server.fullname" .) }}
claimName: {{ .Values.static.persistence.existingClaim | default (include "smartbirds-server.static.fullname" .) }}
{{- else }}
emptyDir: {}
{{- end -}}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
Expand Down
17 changes: 17 additions & 0 deletions charts/smartbirds-server/templates/jobs.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{- range .Values.cron.jobs }}
{{- if .enabled }}
---
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "smartbirds-server.fullname" $ }}-{{ .name }}
labels:
{{- include "smartbirds-server.labels" $ | nindent 4 }}
annotations:
"helm.sh/hook": post-install,post-upgrade
"helm.sh/hook-weight": "0"
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
spec:
template: {{- include "smartbirds-server.job.enqueue" (dict "values" . "ctx" $) | nindent 4 }}
{{- end }}
{{- end }}
21 changes: 21 additions & 0 deletions charts/smartbirds-server/templates/pvc-static.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{{- if and .Values.static.persistence.enabled (not .Values.static.persistence.existingClaim) }}
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ include "smartbirds-server.static.fullname" . }}
labels:
{{- include "smartbirds-server.labels" . | nindent 4 }}
spec:
accessModes:
- {{ .Values.static.persistence.accessMode | quote }}
resources:
requests:
storage: {{ .Values.static.persistence.size | quote }}
{{- if .Values.static.persistence.storageClass }}
{{- if (eq "-" .Values.static.persistence.storageClass) }}
storageClassName: ""
{{- else }}
storageClassName: "{{ .Values.static.persistence.storageClass }}"
{{- end }}
{{- end }}
{{- end }}
21 changes: 21 additions & 0 deletions charts/smartbirds-server/templates/pvc-uploads.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{{- if and .Values.uploads.persistence.enabled (not .Values.uploads.persistence.existingClaim) }}
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ include "smartbirds-server.uploads.fullname" . }}
labels:
{{- include "smartbirds-server.labels" . | nindent 4 }}
spec:
accessModes:
- {{ .Values.uploads.persistence.accessMode | quote }}
resources:
requests:
storage: {{ .Values.uploads.persistence.size | quote }}
{{- if .Values.uploads.persistence.storageClass }}
{{- if (eq "-" .Values.uploads.persistence.storageClass) }}
storageClassName: ""
{{- else }}
storageClassName: "{{ .Values.uploads.persistence.storageClass }}"
{{- end }}
{{- end }}
{{- end }}
21 changes: 0 additions & 21 deletions charts/smartbirds-server/templates/pvc.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ metadata:
"helm.sh/hook": test
spec:
containers:
- name: wget
- name: api-status
image: busybox
command: ['wget']
args: ['{{ include "smartbirds-server.fullname" . }}:{{ .Values.service.port }}/api/status']
Expand Down
38 changes: 38 additions & 0 deletions charts/smartbirds-server/templates/tests/test-statics.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{{- $files := list -}}
{{- $files = append $files "atlas_bspb_summer_species" -}}
{{- $files = append $files "atlas_bspb_winter_species" -}}
{{- $files = append $files "bgatlas2008_global_stats" -}}
{{- $files = append $files "birds_stats" -}}
{{- $files = append $files "birds_top_stats" -}}
{{- $files = append $files "campaign_stats" -}}
{{- $files = append $files "cbm_stats" -}}
{{- $files = append $files "ciconia_stats" -}}
{{- $files = append $files "herptiles_stats" -}}
{{- $files = append $files "herptiles_top_stats" -}}
{{- $files = append $files "invertebrates_stats" -}}
{{- $files = append $files "invertebrates_top_stats" -}}
{{- $files = append $files "mammals_stats" -}}
{{- $files = append $files "mammals_top_stats" -}}
{{- $files = append $files "organizations" -}}
{{- $files = append $files "plants_stats" -}}
{{- $files = append $files "plants_top_stats" -}}
{{- $files = append $files "threats_stats" -}}
{{- $files = append $files "total_user_records_stats" -}}
{{- $files = append $files "user_rank_stats" -}}
apiVersion: v1
kind: Pod
metadata:
name: "{{ include "smartbirds-server.fullname" . }}-test-statics"
labels:
{{- include "smartbirds-server.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": test
spec:
containers:
{{- range $name := $files }}
- name: {{ regexReplaceAll "_" $name "-" }}
image: busybox
command: ['wget']
args: ['{{ include "smartbirds-server.fullname" $ }}:{{ $.Values.service.port }}/{{ $name }}.json']
{{- end }}
restartPolicy: Never
Loading