zyc ded5be6a05
Some checks failed
Build and Deploy Backend / build-and-deploy (push) Failing after 6m4s
add build test
2026-01-29 15:16:20 +08:00

74 lines
2.3 KiB
YAML

name: Build and Deploy Backend
on:
push:
branches:
- main
- master
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
config-inline: |
[registry."docker.io"]
mirrors = ["https://docker.m.daocloud.io", "https://docker.1panel.live", "https://hub.rat.dev"]
- name: Login to Huawei Cloud SWR
uses: docker/login-action@v2
with:
registry: ${{ secrets.SWR_SERVER }}
username: ${{ secrets.SWR_USERNAME }}
password: ${{ secrets.SWR_PASSWORD }}
- name: Build and Push Backend
uses: docker/build-push-action@v4
with:
context: .
push: true
provenance: false
tags: ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/rtc-backend:latest
- name: Setup Kubectl
run: |
curl -LO "https://files.m.daocloud.io/dl.k8s.io/release/v1.28.2/bin/linux/amd64/kubectl"
chmod +x kubectl
mv kubectl /usr/local/bin/
- name: Deploy to K3s
uses: Azure/k8s-set-context@v3
with:
method: kubeconfig
kubeconfig: ${{ secrets.KUBE_CONFIG }}
- name: Update K8s Manifests
run: |
# 1. 判断分支,决定使用哪个配置文件
if [[ "${{ github.ref_name }}" == "main" || "${{ github.ref_name }}" == "master" ]]; then
echo "Environment: Production"
DEPLOY_FILE="k8s/backend-deployment-prod.yaml"
INGRESS_FILE="k8s/ingress.yaml"
DEPLOY_NAME="rtc-backend"
else
echo "Environment: Development"
DEPLOY_FILE="k8s/backend-deployment-dev.yaml"
INGRESS_FILE="k8s/ingress-dev.yaml"
DEPLOY_NAME="rtc-backend-dev"
fi
# 2. 替换镜像地址
sed -i "s|\${CI_REGISTRY_IMAGE}/backend:latest|${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/rtc-backend:latest|g" $DEPLOY_FILE
# 3. 应用配置
# kubectl apply -f k8s/redis-deployment.yaml (Cloud Redis used, skipping)
kubectl apply -f $DEPLOY_FILE
kubectl apply -f $INGRESS_FILE
kubectl rollout restart deployment/$DEPLOY_NAME