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
All checks were successful
Dynamic Branch Deploy / build-and-deploy (push) Successful in 2m24s
This commit is contained in:
1
.github/workflows/deploy.yaml
vendored
1
.github/workflows/deploy.yaml
vendored
@@ -104,6 +104,7 @@ jobs:
|
|||||||
# Anwenden
|
# Anwenden
|
||||||
echo "Deploying Resources to Namespace: ${{ env.TARGET_NS }}"
|
echo "Deploying Resources to Namespace: ${{ env.TARGET_NS }}"
|
||||||
kubectl apply -f k8s/pvc.yaml -n ${{ 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/redis.yaml -n ${{ env.TARGET_NS }}
|
||||||
kubectl apply -f k8s/app.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 }}
|
kubectl apply -f k8s/ingress.yaml -n ${{ env.TARGET_NS }}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@@ -29,12 +30,14 @@ func main() {
|
|||||||
loadServerAssets(globalWorld)
|
loadServerAssets(globalWorld)
|
||||||
|
|
||||||
// 1b. Redis-Leaderboard initialisieren
|
// 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.Fatal("❌ Konnte nicht zu Redis verbinden: ", err)
|
||||||
}
|
}
|
||||||
|
log.Printf("✅ Verbunden mit Redis: %s", redisAddr)
|
||||||
|
|
||||||
// 2. NATS VERBINDUNG
|
// 2. NATS VERBINDUNG
|
||||||
natsURL := "nats://localhost:4222"
|
natsURL := getEnv("NATS_URL", "nats://localhost:4222")
|
||||||
nc, err := nats.Connect(natsURL)
|
nc, err := nats.Connect(natsURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("❌ Konnte nicht zu NATS verbinden: ", err)
|
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) {
|
func loadServerAssets(w *game.World) {
|
||||||
assetDir := "./cmd/client/web/assets"
|
assetDir := "./cmd/client/web/assets"
|
||||||
chunkDir := filepath.Join(assetDir, "chunks")
|
chunkDir := filepath.Join(assetDir, "chunks")
|
||||||
|
|||||||
@@ -22,6 +22,11 @@ spec:
|
|||||||
- containerPort: 8080
|
- containerPort: 8080
|
||||||
name: http
|
name: http
|
||||||
protocol: TCP
|
protocol: TCP
|
||||||
|
env:
|
||||||
|
- name: REDIS_ADDR
|
||||||
|
value: "redis-service:6379"
|
||||||
|
- name: NATS_URL
|
||||||
|
value: "nats://nats-service:4222"
|
||||||
livenessProbe:
|
livenessProbe:
|
||||||
httpGet:
|
httpGet:
|
||||||
path: /health
|
path: /health
|
||||||
|
|||||||
55
k8s/nats.yaml
Normal file
55
k8s/nats.yaml
Normal 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
|
||||||
Reference in New Issue
Block a user