add diff env
All checks were successful
Build and Deploy Web / build-and-deploy (push) Successful in 1m50s

This commit is contained in:
zyc 2026-01-29 15:02:40 +08:00
parent 50acdede38
commit d0540951b6
6 changed files with 87 additions and 20 deletions

2
.env.production Normal file
View File

@ -0,0 +1,2 @@
# 生产环境配置
VITE_API_BASE_URL=https://qiyuan-rtc-api.airlabs.art

View File

@ -49,9 +49,27 @@ jobs:
- name: Update K8s Manifests - name: Update K8s Manifests
run: | run: |
sed -i "s|\${CI_REGISTRY_IMAGE}/web:latest|${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/rtc-web:latest|g" k8s/web-deployment.yaml # 1. 判断分支
if [[ "${{ github.ref_name }}" == "main" || "${{ github.ref_name }}" == "master" ]]; then
echo "Environment: Production"
DEPLOY_FILE="k8s/web-deployment-prod.yaml"
INGRESS_FILE="k8s/ingress.yaml"
else
echo "Environment: Development"
DEPLOY_FILE="k8s/web-deployment-dev.yaml"
INGRESS_FILE="k8s/ingress-dev.yaml"
fi
# 2. 替换镜像地址
sed -i "s|\${CI_REGISTRY_IMAGE}/web:latest|${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/rtc-web:latest|g" $DEPLOY_FILE
kubectl apply -f k8s/web-deployment.yaml # 3. 应用配置
kubectl apply -f k8s/ingress.yaml kubectl apply -f $DEPLOY_FILE
kubectl apply -f $INGRESS_FILE
kubectl rollout restart deployment/rtc-web # 4. 根据分支重启对应服务
if [[ "${{ github.ref_name }}" == "main" || "${{ github.ref_name }}" == "master" ]]; then
kubectl rollout restart deployment/rtc-web
else
kubectl rollout restart deployment/rtc-web-dev
fi

18
k8s/ingress-dev.yaml Normal file
View File

@ -0,0 +1,18 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: rtc-web-ingress-dev
annotations:
kubernetes.io/ingress.class: "traefik"
spec:
rules:
- host: qiyuan-rtc-dev-web.airlabs.art
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: rtc-web-dev
port:
number: 80

View File

@ -6,22 +6,9 @@ metadata:
kubernetes.io/ingress.class: "traefik" kubernetes.io/ingress.class: "traefik"
spec: spec:
rules: rules:
- http: - host: qiyuan-rtc-web.airlabs.art
http:
paths: paths:
- path: /api
pathType: Prefix
backend:
service:
name: rtc-backend
port:
number: 8000
- path: /admin
pathType: Prefix
backend:
service:
name: rtc-backend
port:
number: 8000
- path: / - path: /
pathType: Prefix pathType: Prefix
backend: backend:
@ -29,3 +16,4 @@ spec:
name: rtc-web name: rtc-web
port: port:
number: 80 number: 80

View File

@ -0,0 +1,41 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: rtc-web-dev
labels:
app: rtc-web-dev
spec:
replicas: 1 # 测试环境 1 个副本
selector:
matchLabels:
app: rtc-web-dev
template:
metadata:
labels:
app: rtc-web-dev
spec:
containers:
- name: rtc-web
image: ${CI_REGISTRY_IMAGE}/web:latest
imagePullPolicy: Always
ports:
- containerPort: 80
resources:
requests:
memory: "64Mi"
cpu: "100m"
limits:
memory: "512Mi"
cpu: "500m"
---
apiVersion: v1
kind: Service
metadata:
name: rtc-web-dev
spec:
selector:
app: rtc-web-dev
ports:
- protocol: TCP
port: 80
targetPort: 80

View File

@ -5,7 +5,7 @@ metadata:
labels: labels:
app: rtc-web app: rtc-web
spec: spec:
replicas: 1 replicas: 2
selector: selector:
matchLabels: matchLabels:
app: rtc-web app: rtc-web