Skip to content

Commit ff05189

Browse files
authored
Merge pull request #2 from bryopsida/dotenv-secret
Fix helm test with redis + bull
2 parents 9a9e2cd + c7b17d4 commit ff05189

File tree

7 files changed

+45
-10
lines changed

7 files changed

+45
-10
lines changed

charts/patchwork/Chart.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ apiVersion: v2
22
name: patchwork
33
description: A Helm chart for Kubernetes
44
type: application
5-
version: 0.2.0
5+
version: 0.2.1
66
appVersion: '0.1.0'
77
dependencies:
88
- name: redis
99
repository: https://groundhog2k.github.io/helm-charts/
1010
version: 0.6.12
11+
maintainers:
12+
- name: bryopsida

charts/patchwork/templates/_helpers.tpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,7 @@ Create the name of the service account to use
6060
{{- default "default" .Values.serviceAccount.name }}
6161
{{- end }}
6262
{{- end }}
63+
64+
{{- define "patchwork.dotenv-secret-name" -}}
65+
{{- default (printf "%s-dotenv" .Release.Name) .Values.dotenvSecretName }}
66+
{{- end }}

charts/patchwork/templates/deployment.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ spec:
4747
port: http
4848
resources:
4949
{{- toYaml .Values.resources | nindent 12 }}
50+
volumeMounts:
51+
- name: dotenv
52+
mountPath: /usr/src/app/.env
53+
subPath: .env
54+
volumes:
55+
- name: dotenv
56+
secret:
57+
secretName: {{ include "patchwork.dotenv-secret-name" . }}
5058
{{- with .Values.nodeSelector }}
5159
nodeSelector:
5260
{{- toYaml . | nindent 8 }}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{{- if not .Values.dotenvSecretName }}
2+
apiVersion: v1
3+
kind: Secret
4+
metadata:
5+
name: {{ include "patchwork.dotenv-secret-name" . }}
6+
type: Opaque
7+
stringData:
8+
.env: |-
9+
PATCHWORK_REDIS_HOST={{ default (printf "%s-redis.%s.svc" .Release.Name .Release.Namespace) .Values.redis.host }}
10+
PATCHWORK_REDIS_PORT={{ default "6379" .Values.redis.port | int }}
11+
12+
{{- end }}

charts/patchwork/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
replicaCount: 1
66

77
image:
8-
repository: ghcr.io/bryopsida/nestjs-starter
8+
repository: ghcr.io/bryopsida/patchwork
99
pullPolicy: Always
1010
tag: 'main'
1111

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"minikube:start": "minikube start --memory=4192m --disk-size=8g --cpus=2 --addons=[ingress,storage-provisioner,default-storageclass,metrics-server]",
1313
"minikube:stop": "minikube stop",
1414
"minikube:delete": "minikube delete",
15-
"minikube:copyImage": "minikube image load ghcr.io/bryopsida/patchwork:local",
15+
"minikube:copyImage": "minikube image load ghcr.io/bryopsida/patchwork:local --overwrite=true",
1616
"helm:template": "helm template patchwork ./charts/patchwork/",
1717
"helm:deploy": "helm upgrade --install patchwork ./charts/patchwork/ --set image.tag=local --set image.pullPolicy=IfNotPresent --debug --wait",
1818
"helm:test": "helm test patchwork",

src/common/conn-options.service.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
1-
import { Injectable } from '@nestjs/common'
1+
import { Injectable, Logger } from '@nestjs/common'
22
import { RedisOptions, Transport } from '@nestjs/microservices'
33
import { MicroserviceHealthIndicatorOptions } from '@nestjs/terminus'
44
import { config } from 'dotenv'
55

66
// ensure process.env is hydrated
7-
config()
7+
config({
8+
// items in .env take precedence
9+
override: true,
10+
})
811

912
@Injectable()
1013
export class ConnOptionsService {
14+
private readonly logger = new Logger(ConnOptionsService.name)
15+
1116
getRedisOptions(): RedisOptions & MicroserviceHealthIndicatorOptions {
17+
const options = {
18+
host: process.env.PATCHWORK_REDIS_HOST ?? 'localhost',
19+
port: parseInt(process.env.PATCHWORK_REDIS_PORT ?? '6379'),
20+
password: process.env.PATCHWORK_REDIS_PASSWORD ?? undefined,
21+
}
22+
this.logger.log(
23+
`Using redis host: ${options.host} on port ${options.port} for connections options, source from process.env.PATCHWORK_REDIS_HOST=${process.env.PATCHWORK_REDIS_HOST}, process.env.PATCHWORK_REDIS_PORT=${process.env.PATCHWORK_REDIS_PORT}`
24+
)
1225
return {
1326
transport: Transport.REDIS,
14-
options: {
15-
host: process.env.PATCHWORK_REDIS_HOST ?? 'localhost',
16-
port: parseInt(process.env.PATCHWORK_REDIS_PORT ?? '6379'),
17-
password: process.env.PATCHWORK_REDIS_PASSWORD ?? undefined,
18-
},
27+
options,
1928
}
2029
}
2130
}

0 commit comments

Comments
 (0)