Files
tonePage/.gitea/workflows/deploy.yml
tone 1c518b44cc
All checks were successful
Deploy to K3s / deploy (push) Successful in 11s
chore: 移除自动迁移...
2025-12-27 14:32:01 +08:00

81 lines
2.2 KiB
YAML

# .gitea/workflows/deploy.yml
name: Deploy to K3s
on:
push:
branches:
- master
jobs:
deploy:
runs-on: ubuntu-latest
container:
image: localhost:5000/tiny-ci-runner:latest
env:
IMAGE_TAG: ${{ github.sha }}
KUBECONFIG: /tmp/.kube/config
NODE_ENV: production
steps:
- name: Write kubeconfig
run: |
mkdir -p /tmp/.kube
cat << 'EOF' > /tmp/.kube/config
${{ secrets.KUBECONFIG_DATA }}
EOF
chmod 600 /tmp/.kube/config
- name: Verify Kubernetes access
run: |
kubectl cluster-info
kubectl get nodes
- name: Checkout code
run: |
git clone --depth=1 --branch master \
https://git.tonesc.cn/tone/tonePage.git \
/workspace/tone/tonePage
cd /workspace/tone/tonePage
git log -1 --oneline
- name: Build and push backend image
run: |
cd /workspace/tone/tonePage/apps/backend
docker build -t localhost:5000/backend:${IMAGE_TAG} .
docker push localhost:5000/backend:${IMAGE_TAG}
- name: Build and push frontend image
run: |
cd /workspace/tone/tonePage/apps/frontend
docker build \
--build-arg API_BASE="http://backend-service:3001" \
-t localhost:5000/frontend:${IMAGE_TAG} .
docker push localhost:5000/frontend:${IMAGE_TAG}
- name: Deploy to K3s
run: |
cd /workspace/tone/tonePage/apps/deploy
# 基础资源
kubectl apply -f postgres-deployment.yaml
kubectl apply -f backend-deployment.yaml
kubectl apply -f frontend-deployment.yaml
# 更新镜像(触发滚动更新)
kubectl set image deployment/backend \
backend=localhost:5000/backend:${IMAGE_TAG}
kubectl set image deployment/frontend \
frontend=localhost:5000/frontend:${IMAGE_TAG}
# 等待滚动完成
kubectl rollout status deployment/backend --timeout=120s
kubectl rollout status deployment/frontend --timeout=120s
- name: Post-deploy sanity check
run: |
kubectl get pods
kubectl get svc