diff --git a/.gitea/workflows/build-deploy.yml b/.gitea/workflows/build-deploy.yml new file mode 100644 index 0000000..a6da2ee --- /dev/null +++ b/.gitea/workflows/build-deploy.yml @@ -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 < - --context=dir://./dashboard-backend - --dockerfile=./dashboard-backend/Dockerfile - --destination=cloudforge-dashboard-backend:${{ github.sha }} - --destination=cloudforge-dashboard-backend:latest - --no-push - --tar-path=/workspace/backend.tar - - - name: Build Frontend with Kaniko - uses: docker://gcr.io/kaniko-project/executor:latest - with: - args: > - --context=dir://./dashboard-frontend - --dockerfile=./dashboard-frontend/Dockerfile - --destination=cloudforge-dashboard-frontend:${{ github.sha }} - --destination=cloudforge-dashboard-frontend:latest - --no-push - --tar-path=/workspace/frontend.tar - - - name: Load images to containerd - run: | - # Import 到 K3S - ctr -n k8s.io images import /workspace/backend.tar - ctr -n k8s.io images import /workspace/frontend.tar - - - name: Deploy with kubectl - run: | - kubectl set image deployment/dashboard-backend \ - backend=cloudforge-dashboard-backend:${{ github.sha }} \ - -n cloudforge || echo "Deployment not found, will create" - - kubectl set image deployment/dashboard-frontend \ - frontend=cloudforge-dashboard-frontend:${{ github.sha }} \ - -n cloudforge || echo "Deployment not found, will create" - - - name: Verify - run: | - kubectl rollout status deployment/dashboard-backend -n cloudforge -t 300s - kubectl rollout status deployment/dashboard-frontend -n cloudforge -t 300s