Skip to content

Commit

Permalink
make env-config.js a secret
Browse files Browse the repository at this point in the history
Signed-off-by: André Bauer <andre.bauer@staffbase.com>
  • Loading branch information
monotek committed Jun 27, 2024
1 parent 96f6732 commit 9c71428
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 23 deletions.
2 changes: 1 addition & 1 deletion charts/visual-regression-tracker/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ sources:
- https://github.com/Visual-Regression-Tracker/Visual-Regression-Tracker
- https://github.com/kokuwaio/helm-charts/tree/main/charts/visual-regression-tracker
type: application
version: 4.0.2
version: 4.1.0
appVersion: "5.0.4"
maintainers:
- name: monotek
Expand Down
5 changes: 5 additions & 0 deletions charts/visual-regression-tracker/files/env-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
window._env_ = {
REACT_APP_API_URL: "{{ .Values.vrtConfig.reactAppApi.protocol }}://{{ .Values.authProxy.basicAuth.username }}:{{ .Values.authProxy.basicAuth.password }}@{{ .Values.vrtConfig.reactAppApi.url }}",
PORT: "{{ .Values.vrtComponents.ui.service.port }}",
VRT_VERSION: "{{ .Chart.AppVersion }}",
}
12 changes: 11 additions & 1 deletion charts/visual-regression-tracker/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ vrt secret name
{{- end -}}
{{- end -}}


{{/*
vrt auth proxy secret name
*/}}
Expand All @@ -116,3 +115,14 @@ vrt auth proxy secret name
{{ template "visual-regression-tracker.fullname" . }}-{{ .Values.secrets.authProxy.secretName }}
{{- end -}}
{{- end -}}

{{/*
vrt env secret name
*/}}
{{- define "visual-regression-tracker.envSecretName" -}}
{{- if .Values.secrets.envConfig.useExisting -}}
{{ .Values.secrets.envConfig.secretName }}
{{- else -}}
{{ template "visual-regression-tracker.fullname" . }}-{{ .Values.secrets.envConfig.secretName }}
{{- end -}}
{{- end -}}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ spec:
- -c
- /tmp/htpass
- {{ .Values.authProxy.basicAuth.username }}
- $(AUTH_SECRET)
- $(BASIC_AUTH_SECRET)
env:
- name: AUTH_SECRET
- name: BASIC_AUTH_SECRET
valueFrom:
secretKeyRef:
name: {{ template "visual-regression-tracker.authProxySecretName" . }}
Expand Down
6 changes: 0 additions & 6 deletions charts/visual-regression-tracker/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,3 @@ data:
#!/bin/sh
# dummy file which replaces env-config.js creation to be able to use rofs
cat env-config.js
env-config.js: |
window._env_ = {
REACT_APP_API_URL: "{{ .Values.vrtConfig.reactAppApiUrl }}",
PORT: "{{ .Values.vrtComponents.ui.service.port }}",
VRT_VERSION: "{{ .Chart.AppVersion }}",
}
22 changes: 22 additions & 0 deletions charts/visual-regression-tracker/templates/secrets.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
---
apiVersion: v1
kind: Secret
metadata:
name: {{ template "visual-regression-tracker.envSecretName" . }}
labels:
{{- include "visual-regression-tracker.labels" . | nindent 4 }}
type: Opaque
data:
env-config.js: {{ tpl (.Files.Get "files/env-config.js") $ | b64enc }}
{{ if and .Values.vrtConfig.elasticsearch.pass (not .Values.secrets.elasticsearch.useExisting) }}
---
apiVersion: v1
Expand Down Expand Up @@ -46,3 +56,15 @@ type: Opaque
data:
{{ .Values.secrets.defaults.secretKey }}: {{ tpl (.Files.Get "files/seed.ts") $ | b64enc }}
{{ end }}
{{ if and (or .Values.authProxy.basicAuth.username .Values.authProxy.basicAuth.password) (not .Values.secrets.envConfig.useExisting) }}
---
apiVersion: v1
kind: Secret
metadata:
name: {{ template "visual-regression-tracker.envSecretName" . }}
labels:
{{- include "visual-regression-tracker.labels" . | nindent 4 }}
type: Opaque
data:
{{ .Values.secrets.envConfig.secretKey }}: {{ tpl (.Files.Get "files/env-config.js") $ | b64enc }}
{{ end }}
15 changes: 2 additions & 13 deletions charts/visual-regression-tracker/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,6 @@ spec:
- name: {{ template "visual-regression-tracker.fullname" . }}
mountPath: /imageUploads
- name: {{ .Chart.Name }}-ui
env:
- name: BASIC_AUTH_PASSWORD
valueFrom:
secretKeyRef:
name: {{ template "visual-regression-tracker.authProxySecretName" . }}
key: {{ .Values.secrets.authProxy.secretKey }}
- name: REACT_APP_API_URL
value: "{{ .Values.vrtConfig.reactAppApi.protocol }}://{{ .Values.authProxy.basicAuth.username }}:$(BASIC_AUTH_PASSWORD)@{{ .Values.vrtConfig.reactAppApi.url }}"
- name: VRT_VERSION
value: "{{ .Chart.AppVersion }}"
image: "{{ .Values.vrtComponents.ui.image.repository }}:{{ .Values.vrtComponents.ui.image.tag }}"
imagePullPolicy: {{ .Values.vrtComponents.ui.image.pullPolicy }}
ports:
Expand Down Expand Up @@ -180,9 +170,8 @@ spec:
{{- end }}
volumes:
- name: env-config
configMap:
name: {{ include "visual-regression-tracker.fullname" . }}-env-config
defaultMode: 0777
secret:
secretName: {{ include "visual-regression-tracker.fullname" . }}-env-config
- name: tmp
{{- toYaml .Values.vrtComponents.ui.tmpDirVolume | nindent 10 }}
- name: vrt
Expand Down
4 changes: 4 additions & 0 deletions charts/visual-regression-tracker/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ secrets:
useExisting: false
secretKey: seed.ts
secretName: vrt
envConfig:
useExisting: false
secretKey: env-config.js
secretName: env-config
elasticsearch:
useExisting: false
secretKey: es-pass
Expand Down

0 comments on commit 9c71428

Please sign in to comment.