Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/plenty-donuts-attack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"dextinity-site": minor
---

Add an optional copy assets job that runs as a `pre-install` and `pre-upgrade` hook. Enable it with `copyAssets.enabled` and set the command to run in `copyAssets.command`. The job uses the site image and gets the same environment, secrets and image pull secret as the deployment. Its secrets and config map are deleted once the hook has finished, whether it succeeded or failed.
101 changes: 101 additions & 0 deletions templates/copy-assets-job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{{- if .Values.copyAssets.enabled }}
{{- if .Values.image.pullSecret }}
apiVersion: v1
kind: Secret
metadata:
name: {{ include "dextinity-site.fullname" . }}-copy-assets-image-pull-secret
labels:
{{- include "dextinity-site.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": pre-install, pre-upgrade # Execute this hook before install and upgrade so the copy assets job can authenticate to the registry
"helm.sh/hook-weight": "-3" # Ensure this hook runs first by giving it a high priority (lower weight runs earlier)
"helm.sh/hook-delete-policy": hook-succeeded, hook-failed # Remove it once the hook has finished, no matter if it succeeded or failed
data:
.dockerconfigjson: {{ required "Missing image.pullSecret" .Values.image.pullSecret }}
type: kubernetes.io/dockerconfigjson
{{- end }}
---
{{- if .Values.secrets }}
apiVersion: v1
kind: Secret
metadata:
name: {{ include "dextinity-site.fullname" . }}-copy-assets
labels:
{{- include "dextinity-site.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": pre-install, pre-upgrade # Execute this hook before install and upgrade so the copy assets job can access the secrets
"helm.sh/hook-weight": "-2" # Ensure this hook runs first by giving it a high priority (lower weight runs earlier)
"helm.sh/hook-delete-policy": hook-succeeded, hook-failed # Remove it once the hook has finished, no matter if it succeeded or failed
type: Opaque
stringData:
{{- range $key, $val := .Values.secrets }}
{{ $key }}: {{ $val | quote }}
{{- end }}
{{- end }}
---
{{- if .Values.env }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "dextinity-site.fullname" . }}-copy-assets
labels:
{{- include "dextinity-site.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": pre-install, pre-upgrade # Execute this hook before install and upgrade so the copy assets job can access the configmap
"helm.sh/hook-weight": "-1" # Ensure this hook runs first by giving it a high priority (lower weight runs earlier)
"helm.sh/hook-delete-policy": hook-succeeded, hook-failed # Remove it once the hook has finished, no matter if it succeeded or failed
data:
HELM_RELEASE: "{{ .Release.Name }}"
{{- range $key, $val := .Values.env }}
{{ $key }}: {{ $val | quote }}
{{- end }}
{{- end }}
---
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "dextinity-site.fullname" . }}-copy-assets
annotations:
"helm.sh/hook": pre-install, pre-upgrade # Copy the assets before install and upgrade
"helm.sh/hook-weight": "0" # Default weight
"helm.sh/hook-delete-policy": before-hook-creation # Delete previous job before creating a new one
spec:
backoffLimit: 0 # Do not retry on failure
template:
spec:
restartPolicy: Never # Do not restart the job on failure
{{- if .Values.image.pullSecret }}
imagePullSecrets:
- name: {{ include "dextinity-site.fullname" . }}-copy-assets-image-pull-secret
{{- end }}
containers:
- name: {{ .Chart.Name }}-copy-assets
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
{{- if .Values.image.tag }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
{{- else }}
image: "{{ .Values.image.repository }}@{{ .Values.image.hash }}"
{{- end }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
command: ["bash", "-c", {{ .Values.copyAssets.command }}]
envFrom:
{{- if .Values.env }}
- configMapRef:
name: {{ include "dextinity-site.fullname" . }}-copy-assets
{{- end }}
{{- range $key, $val := .Values.additionalConfigMapNames }}
- configMapRef:
name: {{ $val }}
{{- end }}
{{- if .Values.secrets }}
- secretRef:
name: {{ include "dextinity-site.fullname" . }}-copy-assets
{{- end }}
{{- range $key, $val := .Values.additionalSecretNames }}
- secretRef:
name: {{ $val }}
{{- end }}
resources:
{{- toYaml .Values.copyAssets.resources | nindent 12 }}
{{- end}}
11 changes: 11 additions & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ initContainer:
cpu: 50m
memory: 512Mi

copyAssets:
enabled: false
command: ""
resources:
limits:
memory: 128Mi
cpu: 2
requests:
cpu: 50m
memory: 128Mi

builder:
enabled: false
instanceNameOverride: ""
Expand Down
Loading