Add Kaniko build workflow for backend
Some checks failed
Build and Deploy Backend / build-and-deploy (push) Failing after 7s

This commit is contained in:
2025-11-19 16:25:29 +08:00
parent 836a091eb8
commit 228f6f6dce
2 changed files with 72 additions and 57 deletions

View File

@@ -0,0 +1,72 @@
name: Build and Deploy Backend
on:
push:
branches:
- main
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Build with Kaniko
run: |
# 用 kubectl 建立 Kaniko Job 去 build image
cat <<EOJOB | kubectl apply -f -
apiVersion: batch/v1
kind: Job
metadata:
name: build-backend-${{ github.sha }}
namespace: cloudforge
spec:
ttlSecondsAfterFinished: 600
template:
spec:
containers:
- name: kaniko
image: gcr.io/kaniko-project/executor:v1.9.0
args:
- "--dockerfile=Dockerfile"
- "--context=git://gitea-http.gitea.svc.cluster.local:3000/cloudforge-dev/dashboard-backend.git#main"
- "--destination=cloudforge-dashboard-backend:${{ github.sha }}"
- "--destination=cloudforge-dashboard-backend:latest"
- "--insecure"
- "--skip-tls-verify"
- "--no-push"
volumeMounts:
- name: docker-config
mountPath: /kaniko/.docker
restartPolicy: Never
volumes:
- name: docker-config
emptyDir: {}
EOJOB
- name: Wait for build
run: |
kubectl wait --for=condition=complete \
--timeout=600s \
job/build-backend-${{ github.sha }} \
-n cloudforge
- name: Deploy Backend
run: |
# 更新 deployment image
kubectl set image deployment/dashboard-backend \
backend=cloudforge-dashboard-backend:${{ github.sha }} \
-n cloudforge \
--record
- name: Verify Deployment
run: |
kubectl rollout status deployment/dashboard-backend \
-n cloudforge \
--timeout=300s
- name: Cleanup
run: |
kubectl delete job build-backend-${{ github.sha }} -n cloudforge