diff --git a/charts/smartbirds-server/Chart.yaml b/charts/smartbirds-server/Chart.yaml index e556cab..d8476e0 100644 --- a/charts/smartbirds-server/Chart.yaml +++ b/charts/smartbirds-server/Chart.yaml @@ -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 diff --git a/charts/smartbirds-server/ci/ct-values.yaml b/charts/smartbirds-server/ci/ct-values.yaml index 32266bc..93bf926 100644 --- a/charts/smartbirds-server/ci/ct-values.yaml +++ b/charts/smartbirds-server/ci/ct-values.yaml @@ -1,2 +1,8 @@ persistence: accessMode: ReadWriteOnce + +cron: + enabled: false + +redis: + architecture: standalone diff --git a/charts/smartbirds-server/templates/_containers.tpl b/charts/smartbirds-server/templates/_containers.tpl new file mode 100644 index 0000000..9180dac --- /dev/null +++ b/charts/smartbirds-server/templates/_containers.tpl @@ -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 -}} diff --git a/charts/smartbirds-server/templates/_helpers.tpl b/charts/smartbirds-server/templates/_helpers.tpl index 7c27e9d..8fdf634 100644 --- a/charts/smartbirds-server/templates/_helpers.tpl +++ b/charts/smartbirds-server/templates/_helpers.tpl @@ -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. */}} diff --git a/charts/smartbirds-server/templates/_jobs.tpl b/charts/smartbirds-server/templates/_jobs.tpl new file mode 100644 index 0000000..a8c0ded --- /dev/null +++ b/charts/smartbirds-server/templates/_jobs.tpl @@ -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 -}} diff --git a/charts/smartbirds-server/templates/cronjobs.tpl b/charts/smartbirds-server/templates/cronjobs.tpl new file mode 100644 index 0000000..c517eaa --- /dev/null +++ b/charts/smartbirds-server/templates/cronjobs.tpl @@ -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 }} diff --git a/charts/smartbirds-server/templates/deployment.yaml b/charts/smartbirds-server/templates/deployment.yaml index 6c53309..c4aec35 100644 --- a/charts/smartbirds-server/templates/deployment.yaml +++ b/charts/smartbirds-server/templates/deployment.yaml @@ -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 }} @@ -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 @@ -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 }} diff --git a/charts/smartbirds-server/templates/jobs.tpl b/charts/smartbirds-server/templates/jobs.tpl new file mode 100644 index 0000000..5f1be23 --- /dev/null +++ b/charts/smartbirds-server/templates/jobs.tpl @@ -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 }} diff --git a/charts/smartbirds-server/templates/pvc-static.yaml b/charts/smartbirds-server/templates/pvc-static.yaml new file mode 100644 index 0000000..cc9a803 --- /dev/null +++ b/charts/smartbirds-server/templates/pvc-static.yaml @@ -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 }} diff --git a/charts/smartbirds-server/templates/pvc-uploads.yaml b/charts/smartbirds-server/templates/pvc-uploads.yaml new file mode 100644 index 0000000..a3bd7dd --- /dev/null +++ b/charts/smartbirds-server/templates/pvc-uploads.yaml @@ -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 }} diff --git a/charts/smartbirds-server/templates/pvc.yaml b/charts/smartbirds-server/templates/pvc.yaml deleted file mode 100644 index 09c2fd2..0000000 --- a/charts/smartbirds-server/templates/pvc.yaml +++ /dev/null @@ -1,21 +0,0 @@ -{{- if and .Values.persistence.enabled (not .Values.persistence.existingClaim) }} -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - name: {{ include "smartbirds-server.fullname" . }} - labels: - {{- include "smartbirds-server.labels" . | nindent 4 }} -spec: - accessModes: - - {{ .Values.persistence.accessMode | quote }} - resources: - requests: - storage: {{ .Values.persistence.size | quote }} -{{- if .Values.persistence.storageClass }} -{{- if (eq "-" .Values.persistence.storageClass) }} - storageClassName: "" -{{- else }} - storageClassName: "{{ .Values.persistence.storageClass }}" -{{- end }} -{{- end }} -{{- end }} diff --git a/charts/smartbirds-server/templates/tests/test-connection.yaml b/charts/smartbirds-server/templates/tests/test-connection.yaml index ed148de..774c011 100644 --- a/charts/smartbirds-server/templates/tests/test-connection.yaml +++ b/charts/smartbirds-server/templates/tests/test-connection.yaml @@ -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'] diff --git a/charts/smartbirds-server/templates/tests/test-statics.yaml b/charts/smartbirds-server/templates/tests/test-statics.yaml new file mode 100644 index 0000000..04c5de4 --- /dev/null +++ b/charts/smartbirds-server/templates/tests/test-statics.yaml @@ -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 diff --git a/charts/smartbirds-server/values.yaml b/charts/smartbirds-server/values.yaml index 3376d99..74c8ef1 100644 --- a/charts/smartbirds-server/values.yaml +++ b/charts/smartbirds-server/values.yaml @@ -14,11 +14,76 @@ imagePullSecrets: [] nameOverride: "" fullnameOverride: "" -persistence: +uploads: + name: "uploads" + persistence: + enabled: true + accessMode: ReadWriteMany + existingClaim: "" + size: 8Gi + +static: + name: "static" + persistence: + enabled: true + accessMode: ReadWriteMany + existingClaim: "" + size: 1Gi + +cron: enabled: true - accessMode: ReadWriteMany - existingClaim: "" - size: 8Gi + jobs: + - name: "organizations" + enabled: true + taskName: "organizations:export" + concurency: Forbid + schedule: "*/17 * * * *" + - name: "locations" + enabled: true + taskName: "autoLocation" + concurency: Forbid + schedule: "* * * * *" + - name: "visits" + enabled: true + taskName: "autoVisit" + concurency: Forbid + schedule: "* * * * *" + - name: "utmcode" + enabled: true + taskName: "forms_fill_bgatlas2008_utmcode" + concurency: Forbid + schedule: "* * * * *" + - name: "modreview" + enabled: true + taskName: "birdsNewSpeciesModeratorReview" + concurency: Forbid + schedule: "* * * * *" + - name: "stats" + enabled: true + taskName: "stats:generate" + concurency: Forbid + schedule: "43 * * * *" + - name: "refresh" + enabled: true + taskName: "bgatlas2008_refresh" + concurency: Forbid + schedule: "30 1 * * *" + - name: "banners" + enabled: true + taskName: "banner:generate" + concurency: Forbid + schedule: "25 3 * * *" + - name: "mailchimp" + enabled: false + taskName: "stats:mailchimp" + concurency: Forbid + schedule: "35 3 * * *" + - name: "bspborg" + enabled: true + taskName: "AtlasBspbStats" + concurency: Forbid + schedule: "45 3 * * *" + serviceAccount: # Specifies whether a service account should be created