Use Kaniko for K8S native build
Some checks failed
Build with Kaniko / build (push) Failing after 1m15s
Some checks failed
Build with Kaniko / build (push) Failing after 1m15s
This commit is contained in:
@@ -1,57 +0,0 @@
|
|||||||
name: Build and Deploy with Buildkit
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build-deploy:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Set up Buildx (buildkit)
|
|
||||||
run: |
|
|
||||||
# 安裝 buildx
|
|
||||||
mkdir -p ~/.docker/cli-plugins
|
|
||||||
curl https://github.com/docker/buildx/releases/download/v0.12.0/buildx-v0.12.0.linux-amd64 -L -o ~/.docker/cli-plugins/docker-buildx
|
|
||||||
chmod +x ~/.docker/cli-plugins/docker-buildx
|
|
||||||
|
|
||||||
- name: Build with buildkit (no docker daemon needed)
|
|
||||||
run: |
|
|
||||||
# 啟用 buildx builder
|
|
||||||
docker buildx create --use --name=buildkit-runner 2>/dev/null || docker buildx use buildkit-runner
|
|
||||||
|
|
||||||
# 構建後端
|
|
||||||
docker buildx build \
|
|
||||||
--load \
|
|
||||||
-t cloudforge-dashboard-backend:${{ github.sha }} \
|
|
||||||
-t cloudforge-dashboard-backend:latest \
|
|
||||||
.
|
|
||||||
|
|
||||||
# # 構建前端
|
|
||||||
# docker buildx build \
|
|
||||||
# --load \
|
|
||||||
# -t cloudforge-dashboard-frontend:${{ github.sha }} \
|
|
||||||
# -t cloudforge-dashboard-frontend:latest \
|
|
||||||
# ./dashboard-frontend
|
|
||||||
|
|
||||||
- name: Verify images
|
|
||||||
run: |
|
|
||||||
docker images | grep cloudforge
|
|
||||||
echo "✅ Images built successfully"
|
|
||||||
|
|
||||||
- name: Save images
|
|
||||||
run: |
|
|
||||||
# 保存為 tar,用於後續部署
|
|
||||||
mkdir -p /tmp/images
|
|
||||||
docker save cloudforge-dashboard-backend:latest -o /tmp/images/backend.tar
|
|
||||||
# docker save cloudforge-dashboard-frontend:latest -o /tmp/images/frontend.tar
|
|
||||||
|
|
||||||
- name: Summary
|
|
||||||
run: |
|
|
||||||
echo "✅ Build completed"
|
|
||||||
echo "Images ready for deployment"
|
|
||||||
57
.gitea/workflows/kaniko-build.yml
Normal file
57
.gitea/workflows/kaniko-build.yml
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
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