Skip to content

Commit 5c30809

Browse files
authored
Merge pull request #39 from icoretech/feat/nextjs-backcompat-env-maps
feat(nextjs): support configmap env + secret env maps (back-compat)
2 parents 63e2a77 + 99594d2 commit 5c30809

File tree

5 files changed

+65
-27
lines changed

5 files changed

+65
-27
lines changed

charts/nextjs/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ apiVersion: v2
22
name: nextjs
33
description: Generic Helm chart for Nextjs apps on Kubernetes
44
type: application
5-
version: 1.1.13
5+
version: 1.1.14
66
appVersion: '1.0.0'
77
icon: https://icoretech.github.io/helm/charts/nextjs/logo.png
88
keywords:
99
- nextjs
1010
maintainers:
11-
- name: Claudio Poli
11+
- name: masterkain
1212
email: claudio@icorete.ch
1313
url: https://github.com/masterkain
1414
home: https://github.com/icoretech/helm

charts/nextjs/Readme.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# nextjs
22

3-
![Version: 1.1.13](https://img.shields.io/badge/Version-1.1.13-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 1.0.0](https://img.shields.io/badge/AppVersion-1.0.0-informational?style=flat-square)
3+
![Version: 1.1.14](https://img.shields.io/badge/Version-1.1.14-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 1.0.0](https://img.shields.io/badge/AppVersion-1.0.0-informational?style=flat-square)
44

55
Generic Helm chart for Nextjs apps on Kubernetes
66

@@ -10,7 +10,7 @@ Generic Helm chart for Nextjs apps on Kubernetes
1010

1111
| Name | Email | Url |
1212
| ---- | ------ | --- |
13-
| Claudio Poli | <claudio@icorete.ch> | <https://github.com/masterkain> |
13+
| masterkain | <claudio@icorete.ch> | <https://github.com/masterkain> |
1414

1515
## Source Code
1616

@@ -39,6 +39,7 @@ Generic Helm chart for Nextjs apps on Kubernetes
3939
| web.dataVolume.size | string | `"1Gi"` | |
4040
| web.dataVolume.storageClass | string | `""` | |
4141
| web.dataVolume.volumeMode | string | `""` | |
42+
| web.env | object | `{}` | |
4243
| web.extraContainers | list | `[]` | |
4344
| web.extraEnvFrom | list | `[]` | |
4445
| web.extraEnvs | list | `[]` | |
@@ -81,6 +82,7 @@ Generic Helm chart for Nextjs apps on Kubernetes
8182
| web.replicaCount | int | `1` | |
8283
| web.resources | object | `{}` | |
8384
| web.runtimeClassName | string | `nil` | |
85+
| web.secretEnv | object | `{}` | |
8486
| web.service.annotations | object | `{}` | |
8587
| web.service.enabled | bool | `true` | |
8688
| web.service.nodePort | string | `nil` | |

charts/nextjs/templates/web-env-cm.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,12 @@ metadata:
55
labels:
66
{{- include "app.labels" . | nindent 4 }}
77
data:
8-
AWS_SDK_CONFIG_OPT_OUT: "true"
9-
NEXT_TELEMETRY_DISABLED: "1"
8+
{{- $defaults := dict "AWS_SDK_CONFIG_OPT_OUT" "true" "NEXT_TELEMETRY_DISABLED" "1" -}}
9+
{{- $userEnv := dict -}}
10+
{{- if kindIs "map" .Values.web.env -}}
11+
{{- $userEnv = .Values.web.env -}}
12+
{{- end -}}
13+
{{- $env := merge (deepCopy $defaults) $userEnv -}}
14+
{{- range $k, $v := $env }}
15+
{{ $k }}: {{ $v | toString | quote }}
16+
{{- end }}

charts/nextjs/templates/web-env-secret.yaml

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,25 @@ metadata:
55
labels:
66
{{- include "app.labels" . | nindent 4 }}
77
data:
8-
{{- if .Values.web.extraEnvs }}
9-
{{- range $index, $map := .Values.web.extraEnvs }}
10-
{{ $map.name | upper | replace "-" "_" }}: {{ $map.value | toString | b64enc | quote }}
11-
{{- end }}
8+
{{- $secretEnv := dict -}}
9+
10+
{{- /* Back-compat: extraEnvs is a list of {name,value}. */ -}}
11+
{{- if kindIs "slice" .Values.web.extraEnvs -}}
12+
{{- range $_, $item := .Values.web.extraEnvs -}}
13+
{{- $name := (default "" $item.name) | toString -}}
14+
{{- if $name -}}
15+
{{- $_ := set $secretEnv ($name | upper | replace "-" "_") (($item.value | toString)) -}}
16+
{{- end -}}
17+
{{- end -}}
18+
{{- end -}}
19+
20+
{{- /* New: secretEnv is a map of env var name => value. */ -}}
21+
{{- if kindIs "map" .Values.web.secretEnv -}}
22+
{{- range $k, $v := .Values.web.secretEnv -}}
23+
{{- $_ := set $secretEnv (($k | toString) | upper | replace "-" "_") ($v | toString) -}}
24+
{{- end -}}
25+
{{- end -}}
26+
27+
{{- range $k, $v := $secretEnv }}
28+
{{ $k }}: {{ $v | b64enc | quote }}
1229
{{- end }}

charts/nextjs/values.yaml

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ fullnameOverride: ''
33

44
web:
55
imagePullPolicy: IfNotPresent
6-
imagePullSecrets: '' # must be present in namespace
6+
imagePullSecrets: '' # must be present in namespace
77
image: ''
88
terminationGracePeriodSeconds: 0
99
replicaCount: 1
@@ -62,26 +62,26 @@ web:
6262
# not sure about the usefulness of this - we are trying to solve some caching issues with next.js
6363
# so this should be considered experimental.
6464
cachePersistentVolume:
65-
enabled: false # If set to true, a PersistentVolumeClaim (PVC) will be created for caching
66-
storageClass: '' # The storage class to use for the PVC. If not set, the default StorageClass will be used
67-
existingClaim: '' # If set, this existing PVC will be used instead of creating a new one
65+
enabled: false # If set to true, a PersistentVolumeClaim (PVC) will be created for caching
66+
storageClass: '' # The storage class to use for the PVC. If not set, the default StorageClass will be used
67+
existingClaim: '' # If set, this existing PVC will be used instead of creating a new one
6868
accessModes:
69-
- ReadWriteOnce # The access modes for the PVC. Can be ReadWriteOnce, ReadOnlyMany, or ReadWriteMany. If cachePersistentVolume is enabled and replicaCount is more than 1, this should be set to ReadWriteMany
70-
annotations: {} # Annotations to add to the PVC
71-
size: 1Gi # The requested storage size for the PVC
72-
volumeMode: '' # The volume mode for the PVC. Can be either "Filesystem" (default) or "Block"
73-
mountPath: /app/.next/cache # The path to mount the volume in the container
69+
- ReadWriteOnce # The access modes for the PVC. Can be ReadWriteOnce, ReadOnlyMany, or ReadWriteMany. If cachePersistentVolume is enabled and replicaCount is more than 1, this should be set to ReadWriteMany
70+
annotations: {} # Annotations to add to the PVC
71+
size: 1Gi # The requested storage size for the PVC
72+
volumeMode: '' # The volume mode for the PVC. Can be either "Filesystem" (default) or "Block"
73+
mountPath: /app/.next/cache # The path to mount the volume in the container
7474

7575
dataVolume:
76-
enabled: false # If set to true, a PersistentVolumeClaim (PVC) will be created
77-
storageClass: '' # The storage class to use for the PVC. If not set, the default StorageClass will be used
78-
existingClaim: '' # If set, this existing PVC will be used instead of creating a new one
76+
enabled: false # If set to true, a PersistentVolumeClaim (PVC) will be created
77+
storageClass: '' # The storage class to use for the PVC. If not set, the default StorageClass will be used
78+
existingClaim: '' # If set, this existing PVC will be used instead of creating a new one
7979
accessModes:
80-
- ReadWriteOnce # The access modes for the PVC. Can be ReadWriteOnce, ReadOnlyMany, or ReadWriteMany. If dataVolume is enabled and replicaCount is more than 1, this should be set to ReadWriteMany
81-
annotations: {} # Annotations to add to the PVC
82-
size: 1Gi # The requested storage size for the PVC
83-
volumeMode: '' # The volume mode for the PVC. Can be either "Filesystem" (default) or "Block"
84-
mountPath: /app/data # The path to mount the volume in the container
80+
- ReadWriteOnce # The access modes for the PVC. Can be ReadWriteOnce, ReadOnlyMany, or ReadWriteMany. If dataVolume is enabled and replicaCount is more than 1, this should be set to ReadWriteMany
81+
annotations: {} # Annotations to add to the PVC
82+
size: 1Gi # The requested storage size for the PVC
83+
volumeMode: '' # The volume mode for the PVC. Can be either "Filesystem" (default) or "Block"
84+
mountPath: /app/data # The path to mount the volume in the container
8585

8686
hpa:
8787
enabled: false
@@ -140,6 +140,18 @@ web:
140140
tolerations: []
141141
affinity: {}
142142

143+
# env -- Non-secret env vars stored in the chart-managed ConfigMap.
144+
# Merged on top of the default envs (AWS_SDK_CONFIG_OPT_OUT, NEXT_TELEMETRY_DISABLED).
145+
# web.env:
146+
# NEXT_PUBLIC_API_BASE: https://api.example.com
147+
env: {}
148+
149+
# secretEnv -- Secret env vars stored in the chart-managed Secret.
150+
# Keys are normalized to uppercase and '-' is replaced with '_' (same behavior as extraEnvs).
151+
# web.secretEnv:
152+
# NEXTAUTH_SECRET: xxxx
153+
secretEnv: {}
154+
143155
extraEnvs: []
144156
# extraEnvs:
145157
# - name: AIRBROKE_GITHUB_ID

0 commit comments

Comments
 (0)