From c1053121781f07e1e80b2b7e3dfedf7bc1820f1c Mon Sep 17 00:00:00 2001 From: minhtrannhat Date: Sun, 11 Jan 2026 11:02:16 -0500 Subject: [PATCH] fix: resolve k8s deployment issues with init containers and updated helm deps Co-Authored-By: Claude Opus 4.5 --- helm/incidentops/Chart.lock | 9 +++++ helm/incidentops/Chart.yaml | 4 +-- helm/incidentops/templates/_helpers.tpl | 2 +- .../incidentops/templates/api-deployment.yaml | 11 ++++-- .../templates/worker-deployment.yaml | 7 ++++ helm/incidentops/values.yaml | 17 +++++---- src/IncidentOps.Api/Dockerfile | 2 +- src/IncidentOps.Api/IncidentOps.Api.csproj | 2 +- src/IncidentOps.Worker/Dockerfile | 2 +- web/Dockerfile | 36 +++++++++---------- web/public/.gitkeep | 0 11 files changed, 60 insertions(+), 32 deletions(-) create mode 100644 helm/incidentops/Chart.lock create mode 100644 web/public/.gitkeep diff --git a/helm/incidentops/Chart.lock b/helm/incidentops/Chart.lock new file mode 100644 index 0000000..25cd0e9 --- /dev/null +++ b/helm/incidentops/Chart.lock @@ -0,0 +1,9 @@ +dependencies: +- name: postgresql + repository: https://charts.bitnami.com/bitnami + version: 16.4.1 +- name: redis + repository: https://charts.bitnami.com/bitnami + version: 20.6.1 +digest: sha256:ea3cce1373c9e02bbea41a3403106ce1a0affa558c79fcbd8fc43a39fce078bb +generated: "2026-01-11T10:55:33.886923107-05:00" diff --git a/helm/incidentops/Chart.yaml b/helm/incidentops/Chart.yaml index e3bcb41..6879e03 100644 --- a/helm/incidentops/Chart.yaml +++ b/helm/incidentops/Chart.yaml @@ -7,10 +7,10 @@ appVersion: "1.0.0" dependencies: - name: postgresql - version: "14.0.0" + version: "16.4.1" repository: "https://charts.bitnami.com/bitnami" condition: postgresql.enabled - name: redis - version: "18.0.0" + version: "20.6.1" repository: "https://charts.bitnami.com/bitnami" condition: redis.enabled diff --git a/helm/incidentops/templates/_helpers.tpl b/helm/incidentops/templates/_helpers.tpl index f4e37dc..e422e87 100644 --- a/helm/incidentops/templates/_helpers.tpl +++ b/helm/incidentops/templates/_helpers.tpl @@ -52,7 +52,7 @@ app.kubernetes.io/instance: {{ .Release.Name }} PostgreSQL connection string */}} {{- define "incidentops.postgresConnectionString" -}} -Host={{ .Release.Name }}-postgresql;Port=5432;Database={{ .Values.postgresql.auth.database }};Username={{ .Values.postgresql.auth.username }};Password={{ .Values.postgresql.auth.password }} +Host={{ .Release.Name }}-postgresql;Port=5432;Database={{ .Values.postgresql.auth.database }};Username={{ .Values.postgresql.auth.username }};Password={{ .Values.postgresql.auth.password }};Pooling=true;MinPoolSize=1;MaxPoolSize=20 {{- end }} {{/* diff --git a/helm/incidentops/templates/api-deployment.yaml b/helm/incidentops/templates/api-deployment.yaml index 55c38a1..e4ebb89 100644 --- a/helm/incidentops/templates/api-deployment.yaml +++ b/helm/incidentops/templates/api-deployment.yaml @@ -17,6 +17,13 @@ spec: {{- include "incidentops.selectorLabels" . | nindent 8 }} app.kubernetes.io/component: api spec: + initContainers: + - name: wait-for-postgres + image: busybox:1.36 + command: ['sh', '-c', 'until nc -z {{ .Release.Name }}-postgresql 5432; do echo "Waiting for PostgreSQL..."; sleep 2; done; echo "PostgreSQL is ready!"'] + - name: wait-for-redis + image: busybox:1.36 + command: ['sh', '-c', 'until nc -z {{ .Release.Name }}-redis-master 6379; do echo "Waiting for Redis..."; sleep 2; done; echo "Redis is ready!"'] containers: - name: api image: "{{ .Values.api.image }}:{{ .Values.api.tag }}" @@ -49,13 +56,13 @@ spec: httpGet: path: /healthz port: http - initialDelaySeconds: 10 + initialDelaySeconds: 30 periodSeconds: 10 readinessProbe: httpGet: path: /readyz port: http - initialDelaySeconds: 5 + initialDelaySeconds: 10 periodSeconds: 5 resources: {{- toYaml .Values.api.resources | nindent 12 }} diff --git a/helm/incidentops/templates/worker-deployment.yaml b/helm/incidentops/templates/worker-deployment.yaml index 657edad..f37224d 100644 --- a/helm/incidentops/templates/worker-deployment.yaml +++ b/helm/incidentops/templates/worker-deployment.yaml @@ -17,6 +17,13 @@ spec: {{- include "incidentops.selectorLabels" . | nindent 8 }} app.kubernetes.io/component: worker spec: + initContainers: + - name: wait-for-postgres + image: busybox:1.36 + command: ['sh', '-c', 'until nc -z {{ .Release.Name }}-postgresql 5432; do echo "Waiting for PostgreSQL..."; sleep 2; done; echo "PostgreSQL is ready!"'] + - name: wait-for-redis + image: busybox:1.36 + command: ['sh', '-c', 'until nc -z {{ .Release.Name }}-redis-master 6379; do echo "Waiting for Redis..."; sleep 2; done; echo "Redis is ready!"'] containers: - name: worker image: "{{ .Values.worker.image }}:{{ .Values.worker.tag }}" diff --git a/helm/incidentops/values.yaml b/helm/incidentops/values.yaml index c244e52..f480585 100644 --- a/helm/incidentops/values.yaml +++ b/helm/incidentops/values.yaml @@ -52,21 +52,26 @@ ingress: postgresql: enabled: true + image: + tag: latest + pullPolicy: IfNotPresent auth: - username: postgres - password: postgres + username: incidentops + password: incidentops database: incidentops + postgresPassword: postgres primary: persistence: - enabled: true - size: 1Gi + enabled: false redis: enabled: true + image: + tag: latest + pullPolicy: IfNotPresent architecture: standalone auth: enabled: false master: persistence: - enabled: true - size: 1Gi + enabled: false diff --git a/src/IncidentOps.Api/Dockerfile b/src/IncidentOps.Api/Dockerfile index 85e1427..771781b 100644 --- a/src/IncidentOps.Api/Dockerfile +++ b/src/IncidentOps.Api/Dockerfile @@ -11,7 +11,7 @@ RUN dotnet restore src/IncidentOps.Api/IncidentOps.Api.csproj # Copy source and build COPY src/ src/ WORKDIR /src/src/IncidentOps.Api -RUN dotnet publish -c Release -o /app --no-restore +RUN dotnet publish -c Release -o /app FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS runtime WORKDIR /app diff --git a/src/IncidentOps.Api/IncidentOps.Api.csproj b/src/IncidentOps.Api/IncidentOps.Api.csproj index 740b6a4..c6c7c8f 100644 --- a/src/IncidentOps.Api/IncidentOps.Api.csproj +++ b/src/IncidentOps.Api/IncidentOps.Api.csproj @@ -14,7 +14,7 @@ - + diff --git a/src/IncidentOps.Worker/Dockerfile b/src/IncidentOps.Worker/Dockerfile index 8ad5751..53f6695 100644 --- a/src/IncidentOps.Worker/Dockerfile +++ b/src/IncidentOps.Worker/Dockerfile @@ -11,7 +11,7 @@ RUN dotnet restore src/IncidentOps.Worker/IncidentOps.Worker.csproj # Copy source and build COPY src/ src/ WORKDIR /src/src/IncidentOps.Worker -RUN dotnet publish -c Release -o /app --no-restore +RUN dotnet publish -c Release -o /app FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS runtime WORKDIR /app diff --git a/web/Dockerfile b/web/Dockerfile index 53cbee0..18d4d4c 100644 --- a/web/Dockerfile +++ b/web/Dockerfile @@ -1,31 +1,31 @@ -FROM node:20-alpine AS deps +FROM oven/bun:latest AS deps WORKDIR /app -COPY package*.json ./ -RUN npm ci +COPY package.json bun.lock* ./ +RUN bun install --frozen-lockfile 2>/dev/null || bun install -FROM node:20-alpine AS builder +FROM oven/bun:latest AS builder WORKDIR /app COPY --from=deps /app/node_modules ./node_modules COPY . . -ENV NEXT_TELEMETRY_DISABLED 1 -RUN npm run build -FROM node:20-alpine AS runner +# Ensure public folder exists for the build +RUN mkdir -p public + +ENV NEXT_TELEMETRY_DISABLED=1 +RUN bun run build + +FROM oven/bun:latest AS runner WORKDIR /app -ENV NODE_ENV production -ENV NEXT_TELEMETRY_DISABLED 1 - -RUN addgroup --system --gid 1001 nodejs -RUN adduser --system --uid 1001 nextjs +ENV NODE_ENV=production +ENV NEXT_TELEMETRY_DISABLED=1 COPY --from=builder /app/public ./public -COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ -COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static - -USER nextjs +COPY --from=builder /app/.next/standalone ./ +COPY --from=builder /app/.next/static ./.next/static EXPOSE 3000 -ENV PORT 3000 +ENV PORT=3000 +ENV HOSTNAME="0.0.0.0" -CMD ["node", "server.js"] +CMD ["bun", "server.js"] diff --git a/web/public/.gitkeep b/web/public/.gitkeep new file mode 100644 index 0000000..e69de29