Private
Public Access
1
0

Add NATS deployment and service configuration, integrate environment variables, and update server to support NATS and Redis connections.
All checks were successful
Dynamic Branch Deploy / build-and-deploy (push) Successful in 2m24s

This commit is contained in:
Sebastian Unterschütz
2026-01-04 15:37:09 +01:00
parent ecd994ae73
commit 43680ece16
4 changed files with 73 additions and 2 deletions

View File

@@ -104,6 +104,7 @@ jobs:
# Anwenden
echo "Deploying Resources to Namespace: ${{ env.TARGET_NS }}"
kubectl apply -f k8s/pvc.yaml -n ${{ env.TARGET_NS }}
kubectl apply -f k8s/nats.yaml -n ${{ env.TARGET_NS }}
kubectl apply -f k8s/redis.yaml -n ${{ env.TARGET_NS }}
kubectl apply -f k8s/app.yaml -n ${{ env.TARGET_NS }}
kubectl apply -f k8s/ingress.yaml -n ${{ env.TARGET_NS }}

View File

@@ -4,6 +4,7 @@ import (
"encoding/json"
"io/ioutil"
"log"
"os"
"path/filepath"
"sync"
@@ -29,12 +30,14 @@ func main() {
loadServerAssets(globalWorld)
// 1b. Redis-Leaderboard initialisieren
if err := server.InitLeaderboard("localhost:6379"); err != nil {
redisAddr := getEnv("REDIS_ADDR", "localhost:6379")
if err := server.InitLeaderboard(redisAddr); err != nil {
log.Fatal("❌ Konnte nicht zu Redis verbinden: ", err)
}
log.Printf("✅ Verbunden mit Redis: %s", redisAddr)
// 2. NATS VERBINDUNG
natsURL := "nats://localhost:4222"
natsURL := getEnv("NATS_URL", "nats://localhost:4222")
nc, err := nats.Connect(natsURL)
if err != nil {
log.Fatal("❌ Konnte nicht zu NATS verbinden: ", err)
@@ -179,6 +182,13 @@ func main() {
}
}
func getEnv(key, defaultValue string) string {
if value := os.Getenv(key); value != "" {
return value
}
return defaultValue
}
func loadServerAssets(w *game.World) {
assetDir := "./cmd/client/web/assets"
chunkDir := filepath.Join(assetDir, "chunks")

View File

@@ -22,6 +22,11 @@ spec:
- containerPort: 8080
name: http
protocol: TCP
env:
- name: REDIS_ADDR
value: "redis-service:6379"
- name: NATS_URL
value: "nats://nats-service:4222"
livenessProbe:
httpGet:
path: /health

55
k8s/nats.yaml Normal file
View File

@@ -0,0 +1,55 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: nats
labels:
app: nats
spec:
replicas: 1
selector:
matchLabels:
app: nats
template:
metadata:
labels:
app: nats
spec:
containers:
- name: nats
image: nats:2-alpine
ports:
- containerPort: 4222
name: client
- containerPort: 8222
name: monitoring
resources:
requests:
memory: "64Mi"
cpu: "100m"
limits:
memory: "256Mi"
cpu: "500m"
args:
- "-js"
- "-m"
- "8222"
---
apiVersion: v1
kind: Service
metadata:
name: nats-service
labels:
app: nats
spec:
type: ClusterIP
selector:
app: nats
ports:
- port: 4222
targetPort: 4222
name: client
protocol: TCP
- port: 8222
targetPort: 8222
name: monitoring
protocol: TCP