Some checks failed
Build and Deploy Backend / build-and-deploy (push) Failing after 6s
60 lines
1.9 KiB
YAML
60 lines
1.9 KiB
YAML
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: Install kubectl + Build with Kaniko + Deploy
|
||
# 用 bitnami/kubectl image,呢個 image 入面有 curl, bash, kubectl
|
||
container:
|
||
image: bitnami/kubectl:latest
|
||
run: |
|
||
# ---- 下載 kubectl 前先檢查已存在版本 ----
|
||
kubectl version --client
|
||
|
||
# ---- Kaniko Job ----
|
||
kubectl apply -f - <<EOJOB
|
||
apiVersion: batch/v1
|
||
kind: Job
|
||
metadata:
|
||
name: build-backend-\${GITHUB_SHA:0:8}
|
||
namespace: cloudforge
|
||
spec:
|
||
ttlSecondsAfterFinished: 600
|
||
template:
|
||
spec:
|
||
containers:
|
||
- name: kaniko
|
||
image: gcr.io/kaniko-project/executor:v1.9.0
|
||
args:
|
||
- "--dockerfile=Dockerfile"
|
||
- "--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:latest"
|
||
- "--insecure"
|
||
- "--skip-tls-verify"
|
||
- "--no-push"
|
||
restartPolicy: Never
|
||
EOJOB
|
||
|
||
# ---- Wait Kaniko Build----
|
||
kubectl wait --for=condition=complete --timeout=600s job/build-backend-\${GITHUB_SHA:0:8} -n cloudforge
|
||
|
||
# ---- Deploy Backend ----
|
||
kubectl set image deployment/dashboard-backend backend=cloudforge-dashboard-backend:\${GITHUB_SHA:0:8} -n cloudforge --record
|
||
|
||
# ---- Verify Deployment ----
|
||
kubectl rollout status deployment/dashboard-backend -n cloudforge --timeout=300s
|
||
|
||
# ---- Cleanup ----
|
||
kubectl delete job build-backend-\${GITHUB_SHA:0:8} -n cloudforge
|