Add kubectl installation
Some checks failed
Build and Deploy Backend / build-and-deploy (push) Failing after 9s

This commit is contained in:
2025-11-19 16:26:53 +08:00
parent 228f6f6dce
commit 394c0bc60e

View File

@@ -13,14 +13,27 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v3
- name: Install kubectl
run: |
curl -LO "https://dl.k8s.io/release/v1.28.0/bin/linux/amd64/kubectl"
chmod +x kubectl
mkdir -p ~/.local/bin
mv kubectl ~/.local/bin/
export PATH=$PATH:~/.local/bin
- name: Configure kubectl
run: |
# Runner 應該有 in-cluster config
# 或者用 service account token
kubectl cluster-info
- name: Build with Kaniko - name: Build with Kaniko
run: | run: |
# 用 kubectl 建立 Kaniko Job 去 build image ~/.local/bin/kubectl apply -f - <<EOJOB
cat <<EOJOB | kubectl apply -f -
apiVersion: batch/v1 apiVersion: batch/v1
kind: Job kind: Job
metadata: metadata:
name: build-backend-${{ github.sha }} name: build-backend-${GITHUB_SHA:0:8}
namespace: cloudforge namespace: cloudforge
spec: spec:
ttlSecondsAfterFinished: 600 ttlSecondsAfterFinished: 600
@@ -32,41 +45,23 @@ jobs:
args: args:
- "--dockerfile=Dockerfile" - "--dockerfile=Dockerfile"
- "--context=git://gitea-http.gitea.svc.cluster.local:3000/cloudforge-dev/dashboard-backend.git#main" - "--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" - "--destination=cloudforge-dashboard-backend:latest"
- "--insecure" - "--insecure"
- "--skip-tls-verify" - "--skip-tls-verify"
- "--no-push" - "--no-push"
volumeMounts:
- name: docker-config
mountPath: /kaniko/.docker
restartPolicy: Never restartPolicy: Never
volumes:
- name: docker-config
emptyDir: {}
EOJOB EOJOB
- name: Wait for build - name: Wait and Deploy
run: | run: |
kubectl wait --for=condition=complete \ ~/.local/bin/kubectl wait --for=condition=complete \
--timeout=600s \ --timeout=600s \
job/build-backend-${{ github.sha }} \ job/build-backend-${GITHUB_SHA:0:8} \
-n cloudforge
~/.local/bin/kubectl set image deployment/dashboard-backend \
backend=cloudforge-dashboard-backend:latest \
-n cloudforge
~/.local/bin/kubectl rollout status deployment/dashboard-backend \
-n cloudforge -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