From 2cec938eedf98d68b62172f0a1db01a5e85c00e5 Mon Sep 17 00:00:00 2001 From: "victor.hery" Date: Fri, 3 Jan 2020 12:06:14 +0100 Subject: [PATCH] WIP: Add an initContainer to avoid the default entrypoint that take age to chown data directory if IO are slow (triggering ReadinessProbe in k8s) --- scripts/peertube-init.sh | 16 ++++++++++++++++ templates/deployment.yaml | 30 +++++++++++++++++++++++++++--- templates/peertube-init.yml | 6 ++++++ 3 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 scripts/peertube-init.sh create mode 100644 templates/peertube-init.yml diff --git a/scripts/peertube-init.sh b/scripts/peertube-init.sh new file mode 100644 index 0000000..064ea5f --- /dev/null +++ b/scripts/peertube-init.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +# Populate config directory +if [ -z "$(ls -A /config)" ]; then + cp /app/support/docker/production/config/* /config +fi + +# Always copy default and custom env configuration file, in cases new keys were added +cp /app/config/default.yaml /config +cp /app/support/docker/production/config/custom-environment-variables.yaml /config +find /config ! -user peertube -exec chown peertube:peertube {} \; + +# Ensure user is ok for data files +find /data ! -user peertube -exec chown peertube:peertube {} \; + +exit 0 \ No newline at end of file diff --git a/templates/deployment.yaml b/templates/deployment.yaml index 57da871..dc7bf23 100644 --- a/templates/deployment.yaml +++ b/templates/deployment.yaml @@ -19,6 +19,21 @@ spec: app: {{ template "peertube.name" . }} release: {{ .Release.Name }} spec: + initContainers: + - name: initPeertube + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + volumeMounts: + - name: data + mountPath: /data + - name: config + mountPath: /config + - mountPath: /init + name: peertube-init + readOnly: true + command: + - sh + - /init/peertube-init.sh containers: - name: {{ .Chart.Name }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" @@ -31,12 +46,17 @@ spec: httpGet: path: / port: http - initialDelaySeconds: 300 + initialDelaySeconds: 60 readinessProbe: httpGet: path: / port: http - initialDelaySeconds: 300 + initialDelaySeconds: 90 + command: + - gosu + - peertube + - npm + - start env: - name: PEERTUBE_WEBSERVER_HOSTNAME value: {{ .Values.environment.hostname }} @@ -109,4 +129,8 @@ spec: {{- else }} - name: config emptyDir: {} -{{- end }} \ No newline at end of file +{{- end }} + - configMap: + defaultMode: 420 + name: peertube-init + name: peertube-init diff --git a/templates/peertube-init.yml b/templates/peertube-init.yml new file mode 100644 index 0000000..56aae31 --- /dev/null +++ b/templates/peertube-init.yml @@ -0,0 +1,6 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: peertube-init +data: + {{ (.Files.Glob "scripts/peertube-init.sh").AsConfig | indent 2 }} \ No newline at end of file