Files
demo-frontend/.gitea/workflows/build.yml
joe fe1c93eacc
Some checks failed
Build & Deploy Frontend / build (push) Has been cancelled
Build & Deploy Frontend / deploy (push) Has been cancelled
init: demo-frontend with CI/CD template
2026-07-19 02:13:25 +08:00

71 lines
2.1 KiB
YAML

# Gitea Actions workflow for Node/Vue/React frontend
# Place at: <repo>/.gitea/workflows/build.yml
name: Build & Deploy Frontend
on:
push:
branches: [main]
pull_request:
branches: [main]
env:
REGISTRY: 127.0.0.1:5000
IMAGE_NAME: web-frontend
jobs:
build:
runs-on: k3s-runner-01
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci || npm install
- name: Build
run: npm run build
env:
# 注入构建时环境变量
VITE_API_URL: ${{ vars.API_URL }}
- name: Build & push Docker image
env:
REGISTRY: ${{ env.REGISTRY }}
run: |
IMAGE_TAG="${{ env.REGISTRY }}/${IMAGE_NAME}:${GITHUB_SHA::8}"
docker build \
--build-arg VITE_API_URL="${{ vars.API_URL }}" \
-t "${IMAGE_TAG}" \
-t "${REGISTRY}/${IMAGE_NAME}:latest" \
-f Dockerfile .
docker push "${IMAGE_TAG}"
docker push "${REGISTRY}/${IMAGE_NAME}:latest"
echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_OUTPUT
echo "DEPLOY_IMAGE=${REGISTRY}/${IMAGE_NAME}:${GITHUB_SHA::8}" >> $GITHUB_ENV
- name: Update ArgoCD app
run: |
# 触发 ArgoCD 重新同步
curl -sk -X POST \
-H "Authorization: Bearer ${{ secrets.ARGOCD_TOKEN }}" \
"https://argocd.k3s-runner.cicd.svc.cluster.local/api/v1/applications/web-frontend/restart"
deploy:
needs: build
runs-on: k3s-runner-01
if: github.ref == 'refs/heads/main'
steps:
- name: Trigger ArgoCD sync
env:
IMAGE: ${{ needs.build.outputs.IMAGE_TAG }}
run: |
# Patch ArgoCD Application 指向新镜像
kubectl -n argocd patch application web-frontend --type merge \
-p "{\"spec\":{\"source\":{\"helm\":{\"parameters\":[{\"name\":\"image.tag\",\"value\":\"${GITHUB_SHA::8}\"}]}}}}"