Add kubectl installation 3
Some checks failed
Build and Deploy Backend / build-and-deploy (push) Failing after 10m42s
Some checks failed
Build and Deploy Backend / build-and-deploy (push) Failing after 10m42s
This commit is contained in:
@@ -10,23 +10,30 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
- name: Restore kubeconfig
|
||||||
|
run: |
|
||||||
|
mkdir -p ~/.kube
|
||||||
|
echo $KUBECONFIG_DATA | base64 -d > ~/.kube/config
|
||||||
|
chmod 600 ~/.kube/config
|
||||||
|
env:
|
||||||
|
KUBECONFIG_DATA: ${{ secrets.KUBECONFIG }}
|
||||||
|
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Install kubectl + Build with Kaniko + Deploy
|
- name: Install kubectl
|
||||||
# 用 bitnami/kubectl image,呢個 image 入面有 curl, bash, kubectl
|
|
||||||
container:
|
|
||||||
image: bitnami/kubectl:latest
|
|
||||||
run: |
|
run: |
|
||||||
# ---- 下載 kubectl 前先檢查已存在版本 ----
|
curl -LO "https://dl.k8s.io/release/v1.28.0/bin/linux/amd64/kubectl"
|
||||||
kubectl version --client
|
chmod +x kubectl
|
||||||
|
sudo mv kubectl /usr/local/bin/kubectl
|
||||||
|
|
||||||
# ---- Kaniko Job ----
|
- name: Build & Deploy with Kaniko (all in one)
|
||||||
kubectl apply -f - <<EOJOB
|
run: |
|
||||||
|
/usr/local/bin/kubectl apply -f - <<EOJOB
|
||||||
apiVersion: batch/v1
|
apiVersion: batch/v1
|
||||||
kind: Job
|
kind: Job
|
||||||
metadata:
|
metadata:
|
||||||
name: build-backend-\${GITHUB_SHA:0:8}
|
name: build-backend-${GITHUB_SHA:0:8}
|
||||||
namespace: cloudforge
|
namespace: cloudforge
|
||||||
spec:
|
spec:
|
||||||
ttlSecondsAfterFinished: 600
|
ttlSecondsAfterFinished: 600
|
||||||
@@ -38,7 +45,7 @@ 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:0:8}"
|
- "--destination=cloudforge-dashboard-backend:${GITHUB_SHA:0:8}"
|
||||||
- "--destination=cloudforge-dashboard-backend:latest"
|
- "--destination=cloudforge-dashboard-backend:latest"
|
||||||
- "--insecure"
|
- "--insecure"
|
||||||
- "--skip-tls-verify"
|
- "--skip-tls-verify"
|
||||||
@@ -46,14 +53,10 @@ jobs:
|
|||||||
restartPolicy: Never
|
restartPolicy: Never
|
||||||
EOJOB
|
EOJOB
|
||||||
|
|
||||||
# ---- Wait Kaniko Build----
|
/usr/local/bin/kubectl wait --for=condition=complete --timeout=600s job/build-backend-${GITHUB_SHA:0:8} -n cloudforge
|
||||||
kubectl wait --for=condition=complete --timeout=600s job/build-backend-\${GITHUB_SHA:0:8} -n cloudforge
|
|
||||||
|
|
||||||
# ---- Deploy Backend ----
|
/usr/local/bin/kubectl set image deployment/dashboard-backend backend=cloudforge-dashboard-backend:${GITHUB_SHA:0:8} -n cloudforge --record
|
||||||
kubectl set image deployment/dashboard-backend backend=cloudforge-dashboard-backend:\${GITHUB_SHA:0:8} -n cloudforge --record
|
|
||||||
|
|
||||||
# ---- Verify Deployment ----
|
/usr/local/bin/kubectl rollout status deployment/dashboard-backend -n cloudforge --timeout=300s
|
||||||
kubectl rollout status deployment/dashboard-backend -n cloudforge --timeout=300s
|
|
||||||
|
|
||||||
# ---- Cleanup ----
|
/usr/local/bin/kubectl delete job build-backend-${GITHUB_SHA:0:8} -n cloudforge
|
||||||
kubectl delete job build-backend-\${GITHUB_SHA:0:8} -n cloudforge
|
|
||||||
|
|||||||
Reference in New Issue
Block a user