1+ name : Build and Push Docker Images
2+
3+ on :
4+ push :
5+ branches :
6+ - main
7+ tags :
8+ - ' v*'
9+ pull_request :
10+ branches :
11+ - main
12+
13+ env :
14+ REGISTRY : ghcr.io
15+ IMAGE_BACKEND : ghcr.io/${{ github.repository_owner }}/wharttest-backend
16+ IMAGE_FRONTEND : ghcr.io/${{ github.repository_owner }}/wharttest-frontend
17+ IMAGE_MCP : ghcr.io/${{ github.repository_owner }}/wharttest-mcp
18+
19+ jobs :
20+ build-and-push :
21+ runs-on : ubuntu-latest
22+ permissions :
23+ contents : read
24+ packages : write
25+
26+ steps :
27+ - name : Checkout repository
28+ uses : actions/checkout@v4
29+
30+ - name : Set up Docker Buildx
31+ uses : docker/setup-buildx-action@v3
32+
33+ - name : Log in to GitHub Container Registry
34+ if : github.event_name != 'pull_request'
35+ uses : docker/login-action@v3
36+ with :
37+ registry : ${{ env.REGISTRY }}
38+ username : ${{ github.actor }}
39+ password : ${{ secrets.GITHUB_TOKEN }}
40+
41+ - name : Extract metadata for backend
42+ id : meta-backend
43+ uses : docker/metadata-action@v5
44+ with :
45+ images : ${{ env.IMAGE_BACKEND }}
46+ tags : |
47+ type=ref,event=branch
48+ type=ref,event=pr
49+ type=semver,pattern={{version}}
50+ type=semver,pattern={{major}}.{{minor}}
51+ type=semver,pattern={{major}}
52+ type=raw,value=latest,enable={{is_default_branch}}
53+
54+ - name : Extract metadata for frontend
55+ id : meta-frontend
56+ uses : docker/metadata-action@v5
57+ with :
58+ images : ${{ env.IMAGE_FRONTEND }}
59+ tags : |
60+ type=ref,event=branch
61+ type=ref,event=pr
62+ type=semver,pattern={{version}}
63+ type=semver,pattern={{major}}.{{minor}}
64+ type=semver,pattern={{major}}
65+ type=raw,value=latest,enable={{is_default_branch}}
66+
67+ - name : Extract metadata for MCP
68+ id : meta-mcp
69+ uses : docker/metadata-action@v5
70+ with :
71+ images : ${{ env.IMAGE_MCP }}
72+ tags : |
73+ type=ref,event=branch
74+ type=ref,event=pr
75+ type=semver,pattern={{version}}
76+ type=semver,pattern={{major}}.{{minor}}
77+ type=semver,pattern={{major}}
78+ type=raw,value=latest,enable={{is_default_branch}}
79+
80+ - name : Build and push backend image
81+ uses : docker/build-push-action@v5
82+ with :
83+ context : ./WHartTest_Django
84+ file : ./WHartTest_Django/Dockerfile
85+ push : ${{ github.event_name != 'pull_request' }}
86+ tags : ${{ steps.meta-backend.outputs.tags }}
87+ labels : ${{ steps.meta-backend.outputs.labels }}
88+ cache-from : type=gha
89+ cache-to : type=gha,mode=max
90+
91+ - name : Build and push frontend image
92+ uses : docker/build-push-action@v5
93+ with :
94+ context : ./WHartTest_Vue
95+ file : ./WHartTest_Vue/Dockerfile
96+ push : ${{ github.event_name != 'pull_request' }}
97+ tags : ${{ steps.meta-frontend.outputs.tags }}
98+ labels : ${{ steps.meta-frontend.outputs.labels }}
99+ cache-from : type=gha
100+ cache-to : type=gha,mode=max
101+
102+ - name : Build and push MCP image
103+ uses : docker/build-push-action@v5
104+ with :
105+ context : ./WHartTest_MCP
106+ file : ./WHartTest_MCP/Dockerfile
107+ push : ${{ github.event_name != 'pull_request' }}
108+ tags : ${{ steps.meta-mcp.outputs.tags }}
109+ labels : ${{ steps.meta-mcp.outputs.labels }}
110+ cache-from : type=gha
111+ cache-to : type=gha,mode=max
112+
113+ - name : Image digest
114+ run : |
115+ echo "Backend: ${{ steps.meta-backend.outputs.tags }}"
116+ echo "Frontend: ${{ steps.meta-frontend.outputs.tags }}"
117+ echo "MCP: ${{ steps.meta-mcp.outputs.tags }}"
0 commit comments