Add Kaniko build workflow for backend
Some checks failed
Build and Deploy Backend / build-and-deploy (push) Failing after 7s
Some checks failed
Build and Deploy Backend / build-and-deploy (push) Failing after 7s
This commit is contained in:
72
.gitea/workflows/build-deploy.yml
Normal file
72
.gitea/workflows/build-deploy.yml
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
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: Build with Kaniko
|
||||||
|
run: |
|
||||||
|
# 用 kubectl 建立 Kaniko Job 去 build image
|
||||||
|
cat <<EOJOB | kubectl apply -f -
|
||||||
|
apiVersion: batch/v1
|
||||||
|
kind: Job
|
||||||
|
metadata:
|
||||||
|
name: build-backend-${{ github.sha }}
|
||||||
|
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 }}"
|
||||||
|
- "--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
|
||||||
|
run: |
|
||||||
|
kubectl wait --for=condition=complete \
|
||||||
|
--timeout=600s \
|
||||||
|
job/build-backend-${{ github.sha }} \
|
||||||
|
-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
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
name: Build with Kaniko
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Build Backend with Kaniko
|
|
||||||
uses: docker://gcr.io/kaniko-project/executor:latest
|
|
||||||
with:
|
|
||||||
args: >
|
|
||||||
--context=dir://./dashboard-backend
|
|
||||||
--dockerfile=./dashboard-backend/Dockerfile
|
|
||||||
--destination=cloudforge-dashboard-backend:${{ github.sha }}
|
|
||||||
--destination=cloudforge-dashboard-backend:latest
|
|
||||||
--no-push
|
|
||||||
--tar-path=/workspace/backend.tar
|
|
||||||
|
|
||||||
- name: Build Frontend with Kaniko
|
|
||||||
uses: docker://gcr.io/kaniko-project/executor:latest
|
|
||||||
with:
|
|
||||||
args: >
|
|
||||||
--context=dir://./dashboard-frontend
|
|
||||||
--dockerfile=./dashboard-frontend/Dockerfile
|
|
||||||
--destination=cloudforge-dashboard-frontend:${{ github.sha }}
|
|
||||||
--destination=cloudforge-dashboard-frontend:latest
|
|
||||||
--no-push
|
|
||||||
--tar-path=/workspace/frontend.tar
|
|
||||||
|
|
||||||
- name: Load images to containerd
|
|
||||||
run: |
|
|
||||||
# Import 到 K3S
|
|
||||||
ctr -n k8s.io images import /workspace/backend.tar
|
|
||||||
ctr -n k8s.io images import /workspace/frontend.tar
|
|
||||||
|
|
||||||
- name: Deploy with kubectl
|
|
||||||
run: |
|
|
||||||
kubectl set image deployment/dashboard-backend \
|
|
||||||
backend=cloudforge-dashboard-backend:${{ github.sha }} \
|
|
||||||
-n cloudforge || echo "Deployment not found, will create"
|
|
||||||
|
|
||||||
kubectl set image deployment/dashboard-frontend \
|
|
||||||
frontend=cloudforge-dashboard-frontend:${{ github.sha }} \
|
|
||||||
-n cloudforge || echo "Deployment not found, will create"
|
|
||||||
|
|
||||||
- name: Verify
|
|
||||||
run: |
|
|
||||||
kubectl rollout status deployment/dashboard-backend -n cloudforge -t 300s
|
|
||||||
kubectl rollout status deployment/dashboard-frontend -n cloudforge -t 300s
|
|
||||||
Reference in New Issue
Block a user