[BACKEND] Initialize Go backend structure and dependencies (#23)

This commit is contained in:
2026-02-15 22:50:06 +00:00
parent 7157877f0b
commit c75f976a2d
29 changed files with 1857 additions and 253 deletions

100
k8s/backend.yaml Normal file
View File

@@ -0,0 +1,100 @@
# k8s/backend.yaml
# ============================================
# Chat Switchboard - Backend Deployment
# ============================================
apiVersion: apps/v1
kind: Deployment
metadata:
name: switchboard-be${DEPLOY_SUFFIX}
namespace: ${NAMESPACE}
labels:
app: switchboard
component: backend
env: ${ENVIRONMENT}
spec:
replicas: ${BE_REPLICAS}
selector:
matchLabels:
app: switchboard
component: backend
env: ${ENVIRONMENT}
template:
metadata:
labels:
app: switchboard
component: backend
env: ${ENVIRONMENT}
spec:
containers:
- name: backend
image: ${BE_IMAGE}:${IMAGE_TAG}
imagePullPolicy: Always
ports:
- containerPort: 8080
name: http
env:
- name: ENVIRONMENT
value: "${ENVIRONMENT}"
- name: PORT
value: "8080"
- name: POSTGRES_HOST
value: "${POSTGRES_HOST}"
- name: POSTGRES_PORT
value: "${POSTGRES_PORT}"
- name: POSTGRES_DB
value: "${DB_NAME}"
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
name: switchboard-db-credentials
key: POSTGRES_USER
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: switchboard-db-credentials
key: POSTGRES_PASSWORD
- name: DATABASE_URL
value: "postgres://$(POSTGRES_USER):$(POSTGRES_PASSWORD)@${POSTGRES_HOST}:${POSTGRES_PORT}/${DB_NAME}?sslmode=disable"
resources:
requests:
memory: "${BE_MEMORY_REQUEST}"
cpu: "${BE_CPU_REQUEST}"
limits:
memory: "${BE_MEMORY_LIMIT}"
cpu: "${BE_CPU_LIMIT}"
readinessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 5
periodSeconds: 10
timeoutSeconds: 3
failureThreshold: 3
livenessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 10
periodSeconds: 30
timeoutSeconds: 5
failureThreshold: 3
---
apiVersion: v1
kind: Service
metadata:
name: switchboard-be${DEPLOY_SUFFIX}
namespace: ${NAMESPACE}
labels:
app: switchboard
component: backend
env: ${ENVIRONMENT}
spec:
selector:
app: switchboard
component: backend
env: ${ENVIRONMENT}
ports:
- protocol: TCP
port: 8080
targetPort: 8080
name: http

135
k8s/deployment.yaml Normal file
View File

@@ -0,0 +1,135 @@
# k8s/deployment.yaml
# ============================================
# Chat Switchboard - Kubernetes Deployment Template
# ============================================
# Variables substituted by CI/CD via envsubst:
# DEPLOY_NAME, ENVIRONMENT, IMAGE_TAG, BASE_PATH,
# DB_NAME, REPLICAS, NAMESPACE, REGISTRY, IMAGE_NAME,
# DOMAIN, CERT_ISSUER, POSTGRES_HOST, POSTGRES_PORT,
# MEMORY_REQUEST, MEMORY_LIMIT, CPU_REQUEST, CPU_LIMIT
# ============================================
apiVersion: apps/v1
kind: Deployment
metadata:
name: ${DEPLOY_NAME}
namespace: ${NAMESPACE}
labels:
app: chat-switchboard
env: ${ENVIRONMENT}
service: chat-switchboard
spec:
replicas: ${REPLICAS}
selector:
matchLabels:
app: chat-switchboard
env: ${ENVIRONMENT}
template:
metadata:
labels:
app: chat-switchboard
env: ${ENVIRONMENT}
service: chat-switchboard
spec:
containers:
- name: switchboard
image: ${REGISTRY}/${IMAGE_NAME}:${IMAGE_TAG}
imagePullPolicy: Always
ports:
- containerPort: 80
name: http
env:
- name: ENVIRONMENT
value: "${ENVIRONMENT}"
- name: BASE_PATH
value: "${BASE_PATH}"
- name: PORT
value: "8080"
# ── Database connection ──
- name: POSTGRES_HOST
value: "${POSTGRES_HOST}"
- name: POSTGRES_PORT
value: "${POSTGRES_PORT}"
- name: POSTGRES_DB
value: "${DB_NAME}"
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
name: switchboard-db-credentials
key: POSTGRES_USER
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: switchboard-db-credentials
key: POSTGRES_PASSWORD
- name: DATABASE_URL
value: "postgres://$(POSTGRES_USER):$(POSTGRES_PASSWORD)@${POSTGRES_HOST}:${POSTGRES_PORT}/${DB_NAME}?sslmode=disable"
resources:
requests:
memory: "${MEMORY_REQUEST}"
cpu: "${CPU_REQUEST}"
limits:
memory: "${MEMORY_LIMIT}"
cpu: "${CPU_LIMIT}"
livenessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 10
periodSeconds: 30
timeoutSeconds: 5
failureThreshold: 3
readinessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 5
periodSeconds: 10
timeoutSeconds: 3
failureThreshold: 3
---
apiVersion: v1
kind: Service
metadata:
name: ${DEPLOY_NAME}
namespace: ${NAMESPACE}
labels:
app: chat-switchboard
env: ${ENVIRONMENT}
spec:
selector:
app: chat-switchboard
env: ${ENVIRONMENT}
ports:
- protocol: TCP
port: 80
targetPort: 80
name: http
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ${DEPLOY_NAME}
namespace: ${NAMESPACE}
annotations:
cert-manager.io/cluster-issuer: "${CERT_ISSUER}"
traefik.ingress.kubernetes.io/router.entrypoints: websecure
labels:
app: chat-switchboard
env: ${ENVIRONMENT}
spec:
ingressClassName: "traefik"
tls:
- hosts:
- ${DOMAIN}
secretName: chat-switchboard-tls
rules:
- host: "${DOMAIN}"
http:
paths:
- path: ${BASE_PATH}
pathType: Prefix
backend:
service:
name: ${DEPLOY_NAME}
port:
number: 80

80
k8s/frontend.yaml Normal file
View File

@@ -0,0 +1,80 @@
# k8s/frontend.yaml
# ============================================
# Chat Switchboard - Frontend Deployment
# ============================================
# Static nginx serving the SPA. No /api/ proxy here —
# the Ingress routes /api/ directly to the backend service.
# ============================================
apiVersion: apps/v1
kind: Deployment
metadata:
name: switchboard-fe${DEPLOY_SUFFIX}
namespace: ${NAMESPACE}
labels:
app: switchboard
component: frontend
env: ${ENVIRONMENT}
spec:
replicas: ${FE_REPLICAS}
selector:
matchLabels:
app: switchboard
component: frontend
env: ${ENVIRONMENT}
template:
metadata:
labels:
app: switchboard
component: frontend
env: ${ENVIRONMENT}
spec:
containers:
- name: frontend
image: ${FE_IMAGE}:${IMAGE_TAG}
imagePullPolicy: Always
ports:
- containerPort: 80
name: http
resources:
requests:
memory: "${FE_MEMORY_REQUEST}"
cpu: "${FE_CPU_REQUEST}"
limits:
memory: "${FE_MEMORY_LIMIT}"
cpu: "${FE_CPU_LIMIT}"
readinessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 3
periodSeconds: 10
timeoutSeconds: 3
failureThreshold: 3
livenessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 5
periodSeconds: 30
timeoutSeconds: 5
failureThreshold: 3
---
apiVersion: v1
kind: Service
metadata:
name: switchboard-fe${DEPLOY_SUFFIX}
namespace: ${NAMESPACE}
labels:
app: switchboard
component: frontend
env: ${ENVIRONMENT}
spec:
selector:
app: switchboard
component: frontend
env: ${ENVIRONMENT}
ports:
- protocol: TCP
port: 80
targetPort: 80
name: http

45
k8s/ingress.yaml Normal file
View File

@@ -0,0 +1,45 @@
# k8s/ingress.yaml
# ============================================
# Chat Switchboard - Ingress
# ============================================
# Routes for a single subdomain:
# /api/* → backend service (Go API on :8080)
# /* → frontend service (nginx SPA on :80)
# ============================================
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: switchboard${DEPLOY_SUFFIX}
namespace: ${NAMESPACE}
annotations:
cert-manager.io/cluster-issuer: "${CERT_ISSUER}"
traefik.ingress.kubernetes.io/router.entrypoints: websecure
labels:
app: switchboard
env: ${ENVIRONMENT}
spec:
ingressClassName: "traefik"
tls:
- hosts:
- ${DEPLOY_HOST}
secretName: switchboard${DEPLOY_SUFFIX}-tls
rules:
- host: "${DEPLOY_HOST}"
http:
paths:
# API routes → backend
- path: /api
pathType: Prefix
backend:
service:
name: switchboard-be${DEPLOY_SUFFIX}
port:
number: 8080
# Everything else → frontend
- path: /
pathType: Prefix
backend:
service:
name: switchboard-fe${DEPLOY_SUFFIX}
port:
number: 80

104
k8s/lite.yaml Normal file
View File

@@ -0,0 +1,104 @@
# k8s/lite.yaml
# ============================================
# Chat Switchboard - Lite (FE-Only)
# ============================================
# Static SPA with no backend. All data in localStorage.
# Deployed to lite.DOMAIN on push to main.
# ============================================
apiVersion: apps/v1
kind: Deployment
metadata:
name: switchboard-lite
namespace: ${NAMESPACE}
labels:
app: switchboard
component: frontend
env: lite
spec:
replicas: 1
selector:
matchLabels:
app: switchboard
component: frontend
env: lite
template:
metadata:
labels:
app: switchboard
component: frontend
env: lite
spec:
containers:
- name: frontend
image: ${FE_IMAGE}:${IMAGE_TAG}
imagePullPolicy: Always
ports:
- containerPort: 80
name: http
resources:
requests:
memory: "32Mi"
cpu: "10m"
limits:
memory: "64Mi"
cpu: "50m"
readinessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 3
periodSeconds: 10
livenessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 5
periodSeconds: 30
---
apiVersion: v1
kind: Service
metadata:
name: switchboard-lite
namespace: ${NAMESPACE}
labels:
app: switchboard
env: lite
spec:
selector:
app: switchboard
component: frontend
env: lite
ports:
- protocol: TCP
port: 80
targetPort: 80
name: http
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: switchboard-lite
namespace: ${NAMESPACE}
annotations:
cert-manager.io/cluster-issuer: "${CERT_ISSUER}"
traefik.ingress.kubernetes.io/router.entrypoints: websecure
labels:
app: switchboard
env: lite
spec:
ingressClassName: "traefik"
tls:
- hosts:
- ${DEPLOY_HOST}
secretName: switchboard-lite-tls
rules:
- host: "${DEPLOY_HOST}"
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: switchboard-lite
port:
number: 80