Add kubectl installation 4
This commit is contained in:
@@ -6,57 +6,126 @@ on:
|
|||||||
- main
|
- main
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-deploy:
|
# Job 1: Build Image
|
||||||
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 30 # 30分鐘 timeout
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Restore kubeconfig
|
- name: Checkout
|
||||||
run: |
|
uses: actions/checkout@v3
|
||||||
mkdir -p ~/.kube
|
|
||||||
echo $KUBECONFIG_DATA | base64 -d > ~/.kube/config
|
|
||||||
chmod 600 ~/.kube/config
|
|
||||||
env:
|
|
||||||
KUBECONFIG_DATA: ${{ secrets.KUBECONFIG }}
|
|
||||||
|
|
||||||
- name: Checkout
|
- name: Restore kubeconfig
|
||||||
uses: actions/checkout@v3
|
run: |
|
||||||
|
mkdir -p ~/.kube
|
||||||
|
echo "$KUBECONFIG_DATA" | base64 -d > ~/.kube/config
|
||||||
|
chmod 600 ~/.kube/config
|
||||||
|
env:
|
||||||
|
KUBECONFIG_DATA: ${{ secrets.KUBECONFIG }}
|
||||||
|
|
||||||
- name: Install kubectl
|
- name: Install kubectl
|
||||||
run: |
|
run: |
|
||||||
curl -LO "https://dl.k8s.io/release/v1.28.0/bin/linux/amd64/kubectl"
|
curl -LO "https://dl.k8s.io/release/v1.28.0/bin/linux/amd64/kubectl"
|
||||||
chmod +x kubectl
|
chmod +x kubectl
|
||||||
sudo mv kubectl /usr/local/bin/kubectl
|
sudo mv kubectl /usr/local/bin/kubectl
|
||||||
|
|
||||||
- name: Build & Deploy with Kaniko (all in one)
|
- name: Create Kaniko Build Job
|
||||||
run: |
|
run: |
|
||||||
/usr/local/bin/kubectl apply -f - <<EOJOB
|
/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: 3600
|
||||||
template:
|
template:
|
||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: kaniko
|
- name: kaniko
|
||||||
image: gcr.io/kaniko-project/executor:v1.9.0
|
image: gcr.io/kaniko-project/executor:v1.9.0
|
||||||
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"
|
||||||
- "--no-push"
|
- "--no-push"
|
||||||
restartPolicy: Never
|
restartPolicy: Never
|
||||||
EOJOB
|
EOJOB
|
||||||
|
|
||||||
/usr/local/bin/kubectl wait --for=condition=complete --timeout=600s job/build-backend-${GITHUB_SHA:0:8} -n cloudforge
|
- name: Wait for Build (20 min timeout)
|
||||||
|
run: |
|
||||||
|
/usr/local/bin/kubectl wait --for=condition=complete \
|
||||||
|
--timeout=1200s \
|
||||||
|
job/build-backend-${GITHUB_SHA:0:8} \
|
||||||
|
-n cloudforge
|
||||||
|
|
||||||
/usr/local/bin/kubectl set image deployment/dashboard-backend backend=cloudforge-dashboard-backend:${GITHUB_SHA:0:8} -n cloudforge --record
|
# Job 2: Deploy
|
||||||
|
deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: build # 等 build job 完成
|
||||||
|
timeout-minutes: 15
|
||||||
|
|
||||||
/usr/local/bin/kubectl rollout status deployment/dashboard-backend -n cloudforge --timeout=300s
|
steps:
|
||||||
|
- name: Restore kubeconfig
|
||||||
|
run: |
|
||||||
|
mkdir -p ~/.kube
|
||||||
|
echo "$KUBECONFIG_DATA" | base64 -d > ~/.kube/config
|
||||||
|
chmod 600 ~/.kube/config
|
||||||
|
env:
|
||||||
|
KUBECONFIG_DATA: ${{ secrets.KUBECONFIG }}
|
||||||
|
|
||||||
/usr/local/bin/kubectl delete job build-backend-${GITHUB_SHA:0:8} -n cloudforge
|
- name: Install kubectl
|
||||||
|
run: |
|
||||||
|
curl -LO "https://dl.k8s.io/release/v1.28.0/bin/linux/amd64/kubectl"
|
||||||
|
chmod +x kubectl
|
||||||
|
sudo mv kubectl /usr/local/bin/kubectl
|
||||||
|
|
||||||
|
- name: Update Deployment
|
||||||
|
run: |
|
||||||
|
/usr/local/bin/kubectl set image deployment/dashboard-backend \
|
||||||
|
backend=cloudforge-dashboard-backend:${GITHUB_SHA:0:8} \
|
||||||
|
-n cloudforge \
|
||||||
|
--record
|
||||||
|
|
||||||
|
- name: Wait for Rollout (10 min)
|
||||||
|
run: |
|
||||||
|
/usr/local/bin/kubectl rollout status deployment/dashboard-backend \
|
||||||
|
-n cloudforge \
|
||||||
|
--timeout=600s
|
||||||
|
|
||||||
|
# Job 3: Verify & Cleanup
|
||||||
|
verify:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: deploy # 等 deploy job 完成
|
||||||
|
timeout-minutes: 10
|
||||||
|
|
||||||
|
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: Install kubectl
|
||||||
|
run: |
|
||||||
|
curl -LO "https://dl.k8s.io/release/v1.28.0/bin/linux/amd64/kubectl"
|
||||||
|
chmod +x kubectl
|
||||||
|
sudo mv kubectl /usr/local/bin/kubectl
|
||||||
|
|
||||||
|
- name: Verify Pods Running
|
||||||
|
run: |
|
||||||
|
/usr/local/bin/kubectl get pods -n cloudforge
|
||||||
|
/usr/local/bin/kubectl get deployment dashboard-backend -n cloudforge
|
||||||
|
|
||||||
|
- name: Cleanup Build Job
|
||||||
|
run: |
|
||||||
|
/usr/local/bin/kubectl delete job build-backend-${GITHUB_SHA:0:8} -n cloudforge || true
|
||||||
|
|
||||||
|
- name: Show Logs
|
||||||
|
run: |
|
||||||
|
/usr/local/bin/kubectl logs deployment/dashboard-backend -n cloudforge --tail=50
|
||||||
|
|||||||
Reference in New Issue
Block a user