完善最后的测试
This commit is contained in:
86
.gitea/workflows/docker-build-push.yml
Normal file
86
.gitea/workflows/docker-build-push.yml
Normal file
@@ -0,0 +1,86 @@
|
||||
name: Build and Push Docker Images
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main, develop ]
|
||||
tags: [ 'v*' ]
|
||||
pull_request:
|
||||
branches: [ main, develop ]
|
||||
|
||||
jobs:
|
||||
build-and-push:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
service: [frontend, backend]
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0 # 获取完整的提交历史用于标签生成
|
||||
|
||||
- name: Login to Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: gitea.zfxt.top
|
||||
username: ${{ secrets.REGISTRY_USERNAME }}
|
||||
password: ${{ secrets.REGISTRY_PASSWORD }}
|
||||
|
||||
# 为后端服务生成元数据
|
||||
- name: Extract metadata for backend
|
||||
if: matrix.service == 'backend'
|
||||
id: meta-backend
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: gitea.zfxt.top/zfxt/backend
|
||||
tags: |
|
||||
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
|
||||
type=sha,prefix=,suffix=,enable=true
|
||||
type=ref,event=branch
|
||||
type=ref,event=pr
|
||||
type=semver,pattern={{version}}
|
||||
type=semver,pattern={{major}}.{{minor}}
|
||||
type=semver,pattern={{major}}
|
||||
|
||||
# 为前端服务生成元数据
|
||||
- name: Extract metadata for frontend
|
||||
if: matrix.service == 'frontend'
|
||||
id: meta-frontend
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: gitea.zfxt.top/zfxt/frontend
|
||||
tags: |
|
||||
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
|
||||
type=sha,prefix=,suffix=,enable=true
|
||||
type=ref,event=branch
|
||||
type=ref,event=pr
|
||||
type=semver,pattern={{version}}
|
||||
type=semver,pattern={{major}}.{{minor}}
|
||||
type=semver,pattern={{major}}
|
||||
|
||||
# 构建和推送后端镜像
|
||||
- name: Build and push backend image
|
||||
if: matrix.service == 'backend'
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: ./backend
|
||||
file: ./backend/dockerfile
|
||||
push: true
|
||||
tags: ${{ steps.meta-backend.outputs.tags }}
|
||||
labels: ${{ steps.meta-backend.outputs.labels }}
|
||||
cache-from: type=registry,ref=gitea.zfxt.top/zfxt/backend:latest
|
||||
cache-to: type=registry,ref=gitea.zfxt.top/zfxt/backend:latest,mode=max
|
||||
|
||||
# 构建和推送前端镜像
|
||||
- name: Build and push frontend image
|
||||
if: matrix.service == 'frontend'
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: ./front
|
||||
file: ./front/dockerfile
|
||||
push: true
|
||||
tags: ${{ steps.meta-frontend.outputs.tags }}
|
||||
labels: ${{ steps.meta-frontend.outputs.labels }}
|
||||
cache-from: type=registry,ref=gitea.zfxt.top/zfxt/frontend:latest
|
||||
cache-to: type=registry,ref=gitea.zfxt.top/zfxt/frontend:latest,mode=max
|
||||
Reference in New Issue
Block a user