diff --git a/.github/workflows/build-kubernetes-chart.yaml b/.github/workflows/build-kubernetes-chart.yaml new file mode 100644 index 0000000..2b517f7 --- /dev/null +++ b/.github/workflows/build-kubernetes-chart.yaml @@ -0,0 +1,28 @@ +name: Release Charts + +on: + push: + +permissions: write-all + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Configure Git + run: | + git config user.name "$GITHUB_ACTOR" + git config user.email "$GITHUB_ACTOR@users.noreply.github.com" + + - name: Run chart-releaser + id: cr + uses: helm/chart-releaser-action@v1.5.0 + env: + CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + with: + charts_dir: ./charts \ No newline at end of file diff --git a/charts/textbee/.helmignore b/charts/textbee/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/charts/textbee/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/charts/textbee/Chart.yaml b/charts/textbee/Chart.yaml new file mode 100644 index 0000000..428a09a --- /dev/null +++ b/charts/textbee/Chart.yaml @@ -0,0 +1,8 @@ +apiVersion: v2 +name: textbee +description: A Helm chart to deploy TextBee. +type: application + +version: 0.1.9 + +appVersion: "v2.6.2" diff --git a/charts/textbee/example/values.yaml b/charts/textbee/example/values.yaml new file mode 100644 index 0000000..54cf168 --- /dev/null +++ b/charts/textbee/example/values.yaml @@ -0,0 +1,30 @@ +web: + enabled: true + service: + enabled: true + type: LoadBalancer + annotations: + tailscale.com/expose: "true" + tailscale.com/hostname: "textbee-web" +api: + autoscaling: + enabled: true + minReplicas: 1 + maxReplicas: 3 + targetCPUUtilizationPercentage: 80 + service: + enabled: true + ingress: + enabled: true + hosts: + - host: textbee-api.demo.com + paths: + - path: / + pathType: Prefix + className: nginx + annotations: + cert-manager.io/cluster-issuer: "letsencrypt-prod" + tls: + - secretName: textbee-api-tls + hosts: + - textbee-api.demo.com \ No newline at end of file diff --git a/charts/textbee/templates/NOTES.txt b/charts/textbee/templates/NOTES.txt new file mode 100644 index 0000000..ef855bd --- /dev/null +++ b/charts/textbee/templates/NOTES.txt @@ -0,0 +1,85 @@ + +######################## +# IMPORTANT # +######################## + +TextBee is almost ready ! + +Create those secrets below: +--- +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "textbee.fullname" . }}-secrets + namespace: {{ .Release.Namespace }} +type: Opaque +stringData: + JWT_SECRET: "" # https://generate-secret.vercel.app/32 + JWT_EXPIRATION: 60d + # Go to Firebase Console -> Press on cog (Project Settings) -> Service Accounts -> Generate new private key + FIREBASE_PROJECT_ID: "" + FIREBASE_PRIVATE_KEY_ID: "" + FIREBASE_PRIVATE_KEY: "" + FIREBASE_CLIENT_EMAIL: "" + FIREBASE_CLIENT_ID: "" + FIREBASE_CLIENT_C509_CERT_URL: "" + MAIL_HOST: "" + MAIL_PORT: "" + MAIL_USER: "" + MAIL_PASS: "" + MAIL_FROM: "" + MAIL_REPLY_TO: "" + +--- +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "textbee.fullname" . }}-web-secrets + namespace: {{ .Release.Namespace }} +type: Opaque +stringData: + NEXT_PUBLIC_GOOGLE_CLIENT_ID: "" + NEXT_PUBLIC_TAWKTO_EMBED_URL: "" + MAIL_HOST: "" + MAIL_PORT: "" + MAIL_USER: "" + MAIL_PASS: "" + MAIL_FROM: "" + ADMIN_EMAIL: "" + +--- + +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "textbee.fullname" . }}-web-secrets + namespace: {{ .Release.Namespace }} +type: Opaque +stringData: + NEXT_PUBLIC_GOOGLE_CLIENT_ID: "" + NEXT_PUBLIC_TAWKTO_EMBED_URL: "" + MAIL_HOST: "" + MAIL_PORT: "" + MAIL_USER: "" + MAIL_PASS: "" + MAIL_FROM: "" + ADMIN_EMAIL: "" + AUTH_SECRET: "" https://generate-secret.vercel.app/32 + +--- +apiVersion: v1 +kind: Secret +metadata: + name: {{ .Values.globals.mongo_uri.secretName }} + namespace: {{ .Release.Namespace }} +type: Opaque +stringData: + uri: "" # mongodb://user:password@host:port/database + +--- + +######################## +# IMPORTANT # +######################## + +Create those secrets above! \ No newline at end of file diff --git a/charts/textbee/templates/_helpers.tpl b/charts/textbee/templates/_helpers.tpl new file mode 100644 index 0000000..1fcf6ec --- /dev/null +++ b/charts/textbee/templates/_helpers.tpl @@ -0,0 +1,51 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "textbee.name" -}} +{{- default .Chart.Name .Values.api.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "textbee.fullname" -}} +{{- if .Values.api.fullnameOverride }} +{{- .Values.api.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.api.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "textbee.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "textbee.labels" -}} +helm.sh/chart: {{ include "textbee.chart" . }} +{{ include "textbee.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "textbee.selectorLabels" -}} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + diff --git a/charts/textbee/templates/api-deployment.yaml b/charts/textbee/templates/api-deployment.yaml new file mode 100644 index 0000000..8d3a67f --- /dev/null +++ b/charts/textbee/templates/api-deployment.yaml @@ -0,0 +1,82 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "textbee.fullname" .}}-api + labels: + app: {{ include "textbee.fullname" .}}-api + {{- include "textbee.labels" . | nindent 4 }} +spec: + {{- if not .Values.api.autoscaling.enabled }} + replicas: {{ .Values.api.replicaCount }} + {{- end }} + selector: + matchLabels: + app: {{ include "textbee.fullname" .}}-api + template: + metadata: + labels: + app: {{ include "textbee.fullname" .}}-api + spec: + containers: + - name: {{ include "textbee.fullname" .}}-api + image: "{{ .Values.api.image.repository }}:{{ .Values.api.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.api.image.pullPolicy }} + ports: + - name: http + containerPort: {{ .Values.api.service.port }} + env: + - name: PORT + value: "{{ .Values.api.service.port }}" + {{- if .Values.web.enabled }} + - name: FRONTEND_URL + value: "http://svc-{{ include "textbee.fullname" .}}-web:{{ .Values.web.service.port }}" + {{- end}} + {{- if .Values.api.redis.enabled }} + - name: REDIS_URL + value: "{{ .Values.api.redis.dsn }}" + - name: USE_SMS_QUEUE + value: "true" + {{- else }} + - name: USE_SMS_QUEUE + value: "false" + {{- end }} + - name: MONGO_URI + valueFrom: + secretKeyRef: + name: {{ .Values.globals.mongo_uri.secretName }} + key: {{ .Values.globals.mongo_uri.secretKey }} + envFrom: + - secretRef: + name: {{ .Values.api.envSecretName | default (include "textbee.fullname" .) }}-api-secrets + {{- with .Values.api.livenessProbe }} + livenessProbe: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.api.readinessProbe }} + readinessProbe: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.api.resources }} + resources: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.api.volumeMounts }} + volumeMounts: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.api.volumes }} + volumes: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.api.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.api.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.api.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} \ No newline at end of file diff --git a/charts/textbee/templates/api-hpa.yaml b/charts/textbee/templates/api-hpa.yaml new file mode 100644 index 0000000..389e242 --- /dev/null +++ b/charts/textbee/templates/api-hpa.yaml @@ -0,0 +1,32 @@ +{{- if .Values.api.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "textbee.fullname" . }}-api-hpa + labels: + {{- include "textbee.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "textbee.fullname" . }}-api + minReplicas: {{ .Values.api.autoscaling.minReplicas }} + maxReplicas: {{ .Values.api.autoscaling.maxReplicas }} + metrics: + {{- if .Values.api.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ .Values.api.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.api.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + target: + type: Utilization + averageUtilization: {{ .Values.api.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/charts/textbee/templates/api-ingress.yaml b/charts/textbee/templates/api-ingress.yaml new file mode 100644 index 0000000..5aeec6e --- /dev/null +++ b/charts/textbee/templates/api-ingress.yaml @@ -0,0 +1,43 @@ +{{- if .Values.api.ingress.enabled -}} +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: ingress-{{ include "textbee.fullname" . }}-api + labels: + {{- include "textbee.labels" . | nindent 4 }} + {{- with .Values.api.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- with .Values.api.ingress.className }} + ingressClassName: {{ . }} + {{- end }} + {{- if .Values.api.ingress.tls }} + tls: + {{- range .Values.api.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} + {{- end }} + rules: + {{- range .Values.api.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + {{- with .pathType }} + pathType: {{ . }} + {{- end }} + backend: + service: + name: svc-{{ include "textbee.fullname" $ }}-api + port: + number: {{ $.Values.api.service.port }} + {{- end }} + {{- end }} +{{- end }} \ No newline at end of file diff --git a/charts/textbee/templates/api-service.yaml b/charts/textbee/templates/api-service.yaml new file mode 100644 index 0000000..e345d03 --- /dev/null +++ b/charts/textbee/templates/api-service.yaml @@ -0,0 +1,21 @@ +apiVersion: v1 +kind: Service +metadata: + name: svc-{{ include "textbee.fullname" .}}-api + labels: + app: textbee-api + {{- include "textbee.labels" . | nindent 4 }} + {{- if .Values.api.service.labels }} + {{- toYaml .Values.api.service.labels | nindent 4 }} + {{- end }} + {{- if .Values.api.service.annotations }} + annotations: + {{- toYaml .Values.api.service.annotations | nindent 4 }} + {{- end }} +spec: + selector: + app: {{ include "textbee.fullname" .}}-api + ports: + - port: {{ .Values.api.service.port }} + targetPort: {{ .Values.api.service.port }} + type: {{ .Values.api.service.type }} diff --git a/charts/textbee/templates/web-deployment.yaml b/charts/textbee/templates/web-deployment.yaml new file mode 100644 index 0000000..1aa8618 --- /dev/null +++ b/charts/textbee/templates/web-deployment.yaml @@ -0,0 +1,74 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "textbee.fullname" .}}-web + labels: + app: {{ include "textbee.fullname" .}}-web + {{- include "textbee.labels" . | nindent 4 }} +spec: + replicas: 1 + selector: + matchLabels: + app: {{ include "textbee.fullname" .}}-web + template: + metadata: + labels: + app: {{ include "textbee.fullname" .}}-web + spec: + containers: + - name: {{ include "textbee.fullname" .}}-web + image: "{{ .Values.web.image.repository }}:{{ .Values.web.image.tag | default .Chart.AppVersion }}" + ports: + - name: http + containerPort: {{ .Values.web.service.port }} + env: + - name: HOSTNAME + value: 0.0.0.0 + {{- if .Values.web.ingress.enabled }} + - name: NEXT_PUBLIC_SITE_URL + value: "https://{{ .Values.globals.domain }}" + {{- end }} + - name: PORT + value: "{{ .Values.web.service.port }}" + - name: NEXT_PUBLIC_API_BASE_URL + value: "http://svc-{{ include "textbee.fullname" .}}-api:{{ .Values.api.service.port }}/api/v1" + - name: DATABASE_URL + valueFrom: + secretKeyRef: + name: {{ .Values.globals.mongo_uri.secretName }} + key: {{ .Values.globals.mongo_uri.secretKey }} + envFrom: + - secretRef: + name: {{ .Values.web.envSecretName | default (include "textbee.fullname" .) }}-web-secrets + {{- with .Values.web.livenessProbe }} + livenessProbe: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.web.readinessProbe }} + readinessProbe: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.web.resources }} + resources: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.web.volumeMounts }} + volumeMounts: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.web.volumes }} + volumes: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.web.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.web.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.web.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/charts/textbee/templates/web-ingress.yaml b/charts/textbee/templates/web-ingress.yaml new file mode 100644 index 0000000..3a54914 --- /dev/null +++ b/charts/textbee/templates/web-ingress.yaml @@ -0,0 +1,43 @@ +{{- if .Values.web.ingress.enabled -}} +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: ingress-{{ include "textbee.fullname" . }}-web + labels: + {{- include "textbee.labels" . | nindent 4 }} + {{- with .Values.web.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- with .Values.web.ingress.className }} + ingressClassName: {{ . }} + {{- end }} + {{- if .Values.web.ingress.tls }} + tls: + {{- range .Values.web.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} + {{- end }} + rules: + {{- range .Values.web.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + {{- with .pathType }} + pathType: {{ . }} + {{- end }} + backend: + service: + name: svc-{{ include "textbee.fullname" $ }}-web + port: + number: {{ $.Values.web.service.port }} + {{- end }} + {{- end }} +{{- end }} \ No newline at end of file diff --git a/charts/textbee/templates/web-service.yaml b/charts/textbee/templates/web-service.yaml new file mode 100644 index 0000000..7733e62 --- /dev/null +++ b/charts/textbee/templates/web-service.yaml @@ -0,0 +1,21 @@ +apiVersion: v1 +kind: Service +metadata: + name: svc-{{ include "textbee.fullname" .}}-web + labels: + app: {{ include "textbee.fullname" .}}-web + {{- include "textbee.labels" . | nindent 4 }} + {{- if .Values.web.service.labels }} + {{- toYaml .Values.web.service.labels | nindent 4 }} + {{- end }} + {{- if .Values.web.service.annotations }} + annotations: + {{- toYaml .Values.web.service.annotations | nindent 4 }} + {{- end }} +spec: + selector: + app: {{ include "textbee.fullname" .}}-web + ports: + - port: {{ .Values.web.service.port }} + targetPort: {{ .Values.web.service.port }} + type: {{ .Values.web.service.type }} diff --git a/charts/textbee/values.yaml b/charts/textbee/values.yaml new file mode 100644 index 0000000..cd5e63e --- /dev/null +++ b/charts/textbee/values.yaml @@ -0,0 +1,231 @@ +globals: + mongo_uri: + secretName: "textbee-mongo-uri-secret" + secretKey: "uri" + domain: "https://chart-example.local" + +api: + # This will set the replicaset count more information can be found here: https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/ + replicaCount: 1 + + # This sets the container image more information can be found here: https://kubernetes.io/docs/concepts/containers/images/ + image: + repository: ghcr.io/vernu/textbee/api + # This sets the pull policy for images. + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + + + # enable SMS queueing + redis: + enabled: false + dsn: "redis://localhost:6379" + + # This is for the secrets for pulling an image from a private repository more information can be found here: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/ + imagePullSecrets: [] + # This is to override the chart name. + nameOverride: "" + fullnameOverride: "" + + # This is for setting Kubernetes Annotations to a Pod. + # For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/ + podAnnotations: {} + # This is for setting Kubernetes Labels to a Pod. + # For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/ + podLabels: {} + + podSecurityContext: {} + # fsGroup: 2000 + + securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + + # This is for setting up a service more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/ + service: + # This sets the service type more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types + type: ClusterIP + # This sets the ports more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/#field-spec-ports + port: 80 + annotations: {} + # service.beta.kubernetes.io/aws-load-balancer-backend-protocol: "tcp" + # service.beta.kubernetes.io/aws-load-balancer-ssl-cert: "arn:aws:acm:us-east-1:123456789012:certificate/12345678-1234-1234-1234-123456789012" + # service.beta.kubernetes.io/aws-load-balancer-ssl-ports: "443" + + # This block is for setting up the ingress for more information can be found here: https://kubernetes.io/docs/concepts/services-networking/ingress/ + ingress: + enabled: false + className: "" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + + resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + + # This is to setup the liveness and readiness probes more information can be found here: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/ + livenessProbe: + httpGet: + path: / + port: http + readinessProbe: + httpGet: + path: / + port: http + + # This section is for setting up autoscaling more information can be found here: https://kubernetes.io/docs/concepts/workloads/autoscaling/ + autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + + # Additional volumes on the output Deployment definition. + volumes: [] + # - name: foo + # secret: + # secretName: mysecret + # optional: false + + # Additional volumeMounts on the output Deployment definition. + volumeMounts: [] + # - name: foo + # mountPath: "/etc/foo" + # readOnly: true + + nodeSelector: {} + + tolerations: [] + + affinity: {} + +web: + # This sets the container image more information can be found here: https://kubernetes.io/docs/concepts/containers/images/ + image: + repository: ghcr.io/vernu/textbee/web + # This sets the pull policy for images. + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + + # This is for the secrets for pulling an image from a private repository more information can be found here: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/ + imagePullSecrets: [] + + # This is for setting Kubernetes Annotations to a Pod. + # For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/ + podAnnotations: {} + # This is for setting Kubernetes Labels to a Pod. + # For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/ + podLabels: {} + + podSecurityContext: {} + # fsGroup: 2000 + + securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + + # This is for setting up a service more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/ + service: + # This sets the service type more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types + type: ClusterIP + # This sets the ports more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/#field-spec-ports + port: 80 + annotations: {} + # service.beta.kubernetes.io/aws-load-balancer-backend-protocol: "tcp" + # service.beta.kubernetes.io/aws-load-balancer-ssl-cert: "arn:aws:acm:us-east-1:123456789012:certificate/12345678-1234-1234-1234-123456789012" + # service.beta.kubernetes.io/aws-load-balancer-ssl-ports: "443" + + # This block is for setting up the ingress for more information can be found here: https://kubernetes.io/docs/concepts/services-networking/ingress/ + ingress: + enabled: false + className: "" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + + resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + + # This is to setup the liveness and readiness probes more information can be found here: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/ + livenessProbe: + httpGet: + path: / + port: http + readinessProbe: + httpGet: + path: / + port: http + + # This section is for setting up autoscaling more information can be found here: https://kubernetes.io/docs/concepts/workloads/autoscaling/ + autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + + # Additional volumes on the output Deployment definition. + volumes: [] + # - name: foo + # secret: + # secretName: mysecret + # optional: false + + # Additional volumeMounts on the output Deployment definition. + volumeMounts: [] + # - name: foo + # mountPath: "/etc/foo" + # readOnly: true + + nodeSelector: {} + + tolerations: [] + + affinity: {} diff --git a/web/lib/httpServerClient.ts b/web/lib/httpServerClient.ts index d4c6177..7b26771 100644 --- a/web/lib/httpServerClient.ts +++ b/web/lib/httpServerClient.ts @@ -5,14 +5,27 @@ import { Session } from 'next-auth' // Create a base URL that works in Docker container network if running in a container // or falls back to the public URL if not in a container -const getServerSideBaseUrl = () => { - // When running server-side in Docker, use the service name from docker-compose +const getServerSideBaseUrl = (): string => { + + // Prefer explicit public API base URL if set + if (process.env.NEXT_PUBLIC_API_BASE_URL) { + return process.env.NEXT_PUBLIC_API_BASE_URL + } + + // Detect Kubernetes environment + if (process.env.KUBERNETES_SERVICE_HOST) { + console.log("Detected Kubernetes environment") + return process.env.NEXT_PUBLIC_API_BASE_URL || '' + } + + // Detect Docker container runtime if (process.env.CONTAINER_RUNTIME === 'docker') { - console.log('Running in Docker container') + console.log("Detected Docker container environment") return 'http://textbee-api:3001/api/v1' } - // Otherwise use the public URL - return process.env.NEXT_PUBLIC_API_BASE_URL || '' + + // Fallback to empty string if nothing else matches + return '' } export const httpServerClient = axios.create({