Add kubectl installation
Some checks failed
Build and Deploy Backend / build-and-deploy (push) Failing after 9s
Some checks failed
Build and Deploy Backend / build-and-deploy (push) Failing after 9s
This commit is contained in:
@@ -13,14 +13,27 @@ jobs:
|
||||
- name: Checkout
|
||||
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
|
||||
run: |
|
||||
# 用 kubectl 建立 Kaniko Job 去 build image
|
||||
cat <<EOJOB | kubectl apply -f -
|
||||
~/.local/bin/kubectl apply -f - <<EOJOB
|
||||
apiVersion: batch/v1
|
||||
kind: Job
|
||||
metadata:
|
||||
name: build-backend-${{ github.sha }}
|
||||
name: build-backend-${GITHUB_SHA:0:8}
|
||||
namespace: cloudforge
|
||||
spec:
|
||||
ttlSecondsAfterFinished: 600
|
||||
@@ -32,41 +45,23 @@ jobs:
|
||||
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
|
||||
- name: Wait and Deploy
|
||||
run: |
|
||||
kubectl wait --for=condition=complete \
|
||||
~/.local/bin/kubectl wait --for=condition=complete \
|
||||
--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
|
||||
|
||||
- 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
|
||||
|
||||
Reference in New Issue
Block a user