Skip to content

Commit 8b32b6c

Browse files
committed
update app version & add secret with password
1 parent 2108663 commit 8b32b6c

5 files changed

Lines changed: 81 additions & 2 deletions

File tree

Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ apiVersion: v2
22
name: codex-docs
33
description: A Helm chart for CodeX Docs
44
type: application
5-
version: 0.0.4
6-
appVersion: "v0.1.2"
5+
version: 0.1.4
6+
appVersion: "v0.2.0"

templates/_helpers.tpl

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,50 @@ Create the name of the service account to use
6060
{{- default "default" .Values.serviceAccount.name }}
6161
{{- end }}
6262
{{- end }}
63+
64+
{{/*
65+
Returns the available value for certain key in an existing secret (if it exists),
66+
otherwise it generates a random value.
67+
*/}}
68+
{{- define "getValueFromSecret" }}
69+
{{- $len := (default 16 .Length) | int -}}
70+
{{- $obj := (lookup "v1" "Secret" .Namespace .Name).data -}}
71+
{{- if $obj }}
72+
{{- index $obj .Key | b64dec -}}
73+
{{- else -}}
74+
{{- randAlphaNum $len -}}
75+
{{- end -}}
76+
{{- end }}
77+
78+
{{/*
79+
Return codex.docs password
80+
*/}}
81+
{{- define "codexdocs.password" -}}
82+
{{- if empty .Values.auth.password -}}
83+
{{- include "getValueFromSecret" (dict "Namespace" .Release.Namespace "Name" (include "codexdocs.fullname" .) "Length" 20 "Key" "docs-password") -}}
84+
{{- else -}}
85+
{{- .Values.auth.password -}}
86+
{{- end -}}
87+
{{- end -}}
88+
89+
{{/*
90+
Get the password secret.
91+
*/}}
92+
{{- define "codexdocs.secretName" -}}
93+
{{- if .Values.auth.existingSecret -}}
94+
{{- printf "%s" .Values.auth.existingSecret -}}
95+
{{- else -}}
96+
{{- printf "%s" (include "codexdocs.fullname" .) -}}
97+
{{- end -}}
98+
{{- end -}}
99+
100+
{{/*
101+
Get the password key to be retrieved from secret.
102+
*/}}
103+
{{- define "codexdocs.secretPasswordKey" -}}
104+
{{- if and .Values.auth.existingSecret .Values.auth.existingSecretPasswordKey -}}
105+
{{- printf "%s" .Values.auth.existingSecretPasswordKey -}}
106+
{{- else -}}
107+
{{- printf "docs-password" -}}
108+
{{- end -}}
109+
{{- end -}}

templates/deployment.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ spec:
4343
{{- toYaml .Values.securityContext | nindent 12 }}
4444
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
4545
imagePullPolicy: {{ .Values.image.pullPolicy }}
46+
env:
47+
- name: PASSWORD
48+
valueFrom:
49+
secretKeyRef:
50+
name: {{ template "codexdocs.secretName" . }}
51+
key: {{ template "codexdocs.secretPasswordKey" . }}
4652
volumeMounts:
4753
- name: config
4854
mountPath: /usr/src/app/.codexdocsrc

templates/secret.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{{- if not .Values.auth.existingSecret -}}
2+
apiVersion: v1
3+
kind: Secret
4+
metadata:
5+
name: {{ include "codexdocs.fullname" . }}
6+
labels:
7+
{{- include "codexdocs.labels" . | nindent 4 }}
8+
type: Opaque
9+
data:
10+
docs-password: {{ include "codexdocs.password" . | b64enc | quote }}
11+
{{- end -}}

values.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@ configuration:
2424
"uploads": "/usr/src/app/public/uploads"
2525
"secret": "iamasecretstring"
2626

27+
# Authentication parameters
28+
auth:
29+
# Auth password
30+
# Defaults to a random 20-character alphanumeric string if not set
31+
#
32+
password: ""
33+
# The name of an existing secret with auth credentials
34+
# NOTE: When it's set, the previous `auth.password` parameter is ignored
35+
#
36+
existingSecret: ""
37+
# Password key to be retrieved from existing secret
38+
# NOTE: ignored unless `auth.existingSecret` parameter is set
39+
#
40+
existingSecretPasswordKey: ""
41+
2742
image:
2843
repository: ghcr.io/codex-team/codex.docs
2944
pullPolicy: Always

0 commit comments

Comments
 (0)