1- name : Build and Push Multi-Arch Docker Images
1+ name : Build and Push Docker Images
22
33on :
44 push :
5- tags : ["v*"]
5+ tags :
6+ - " v*" # 主项目版本
7+ - " mcp-v*" # MCP 版本
68 workflow_dispatch :
9+ inputs :
10+ image :
11+ description : " 选择要构建的镜像"
12+ required : true
13+ default : " all"
14+ type : choice
15+ options :
16+ - all
17+ - crawler
18+ - mcp
719
820env :
921 REGISTRY : docker.io
10- IMAGE_NAME : wantcat/trendradar
1122
1223jobs :
13- build :
24+ build-crawler :
1425 runs-on : ubuntu-latest
26+ # 条件:v* 标签(排除 mcp-v*)或手动触发选择 all/crawler
27+ if : |
28+ (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') && !startsWith(github.ref, 'refs/tags/mcp-v')) ||
29+ (github.event_name == 'workflow_dispatch' && (github.event.inputs.image == 'all' || github.event.inputs.image == 'crawler'))
30+
1531 steps :
1632 - name : Checkout
1733 uses : actions/checkout@v4
@@ -35,12 +51,11 @@ jobs:
3551 id : meta
3652 uses : docker/metadata-action@v5
3753 with :
38- images : ${{ env.IMAGE_NAME }}
54+ images : wantcat/trendradar
3955 tags : |
40- type=ref,event=branch
4156 type=semver,pattern={{version}}
4257 type=semver,pattern={{major}}.{{minor}}
43- type=raw,value=latest,enable={{is_default_branch}}
58+ type=raw,value=latest
4459
4560 - name : Build and push
4661 uses : docker/build-push-action@v5
5570 labels : ${{ steps.meta.outputs.labels }}
5671 cache-from : type=gha
5772 cache-to : type=gha,mode=max
58- build-args : |
59- BUILDKIT_INLINE_CACHE=1
73+
74+ build-mcp :
75+ runs-on : ubuntu-latest
76+ # 条件:mcp-v* 标签 或手动触发选择 all/mcp
77+ if : |
78+ (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/mcp-v')) ||
79+ (github.event_name == 'workflow_dispatch' && (github.event.inputs.image == 'all' || github.event.inputs.image == 'mcp'))
80+
81+ steps :
82+ - name : Checkout
83+ uses : actions/checkout@v4
84+
85+ - name : Set up QEMU
86+ uses : docker/setup-qemu-action@v3
87+
88+ - name : Set up Docker Buildx
89+ uses : docker/setup-buildx-action@v3
90+ with :
91+ driver-opts : |
92+ network=host
93+
94+ - name : Login to Docker Hub
95+ uses : docker/login-action@v3
96+ with :
97+ username : ${{ secrets.DOCKERHUB_USERNAME }}
98+ password : ${{ secrets.DOCKERHUB_TOKEN }}
99+
100+ - name : Extract version from tag
101+ id : version
102+ run : |
103+ if [[ "${{ github.ref }}" == refs/tags/mcp-v* ]]; then
104+ VERSION="${GITHUB_REF#refs/tags/mcp-v}"
105+ echo "version=${VERSION}" >> $GITHUB_OUTPUT
106+ echo "major_minor=$(echo $VERSION | cut -d. -f1,2)" >> $GITHUB_OUTPUT
107+ else
108+ echo "version=latest" >> $GITHUB_OUTPUT
109+ echo "major_minor=latest" >> $GITHUB_OUTPUT
110+ fi
111+
112+ - name : Extract metadata
113+ id : meta
114+ uses : docker/metadata-action@v5
115+ with :
116+ images : wantcat/trendradar-mcp
117+ tags : |
118+ type=raw,value=${{ steps.version.outputs.version }}
119+ type=raw,value=${{ steps.version.outputs.major_minor }}
120+ type=raw,value=latest
121+
122+ - name : Build and push
123+ uses : docker/build-push-action@v5
124+ env :
125+ BUILDKIT_PROGRESS : plain
126+ with :
127+ context : .
128+ file : ./docker/Dockerfile.mcp
129+ platforms : linux/amd64,linux/arm64
130+ push : true
131+ tags : ${{ steps.meta.outputs.tags }}
132+ labels : ${{ steps.meta.outputs.labels }}
133+ cache-from : type=gha
134+ cache-to : type=gha,mode=max
0 commit comments