1+ name : Docker Build & Push
2+
3+ on :
4+ push :
5+ tags : ["v*"]
6+ pull_request :
7+ branches : ["main"]
8+
9+ env :
10+ REGISTRY : ghcr.io
11+
12+ jobs :
13+ build :
14+ # 태그 push는 항상, PR은 [e2e] 있을 때만
15+ if : |
16+ github.event_name == 'push'
17+ runs-on : ubuntu-latest
18+ permissions :
19+ contents : read
20+ packages : write
21+
22+ steps :
23+ - name : Checkout repository
24+ uses : actions/checkout@v4
25+
26+ - name : Set up Docker Buildx
27+ uses : docker/setup-buildx-action@v3
28+
29+ - name : Log in to Container Registry
30+ uses : docker/login-action@v3
31+ with :
32+ registry : ${{ env.REGISTRY }}
33+ username : ${{ github.actor }}
34+ password : ${{ secrets.GITHUB_TOKEN }}
35+
36+ # Server image metadata
37+ - name : Extract server metadata
38+ id : meta-server
39+ uses : docker/metadata-action@v5
40+ with :
41+ images : ${{ env.REGISTRY }}/${{ github.repository }}
42+ tags : |
43+ type=ref,event=branch
44+ type=ref,event=pr
45+ type=semver,pattern={{version}}
46+ type=semver,pattern={{major}}.{{minor}}
47+ type=raw,value=latest,enable={{is_default_branch}}
48+
49+ # Worker image metadata
50+ - name : Extract worker metadata
51+ id : meta-worker
52+ uses : docker/metadata-action@v5
53+ with :
54+ images : ${{ env.REGISTRY }}/${{ github.repository }}-worker
55+ tags : |
56+ type=ref,event=branch
57+ type=ref,event=pr
58+ type=semver,pattern={{version}}
59+ type=semver,pattern={{major}}.{{minor}}
60+ type=raw,value=latest,enable={{is_default_branch}}
61+
62+ # Build and push server image
63+ - name : Build and push Server image
64+ uses : docker/build-push-action@v5
65+ with :
66+ context : .
67+ file : ./Dockerfile
68+ target : server-runtime
69+ push : true
70+ tags : ${{ steps.meta-server.outputs.tags }}
71+ labels : ${{ steps.meta-server.outputs.labels }}
72+ cache-from : type=gha
73+ cache-to : type=gha,mode=max
74+ platforms : linux/amd64
75+
76+ # Build and push worker image (uses cached builder stage)
77+ - name : Build and push Worker image
78+ uses : docker/build-push-action@v5
79+ with :
80+ context : .
81+ file : ./Dockerfile
82+ target : worker-runtime
83+ push : true
84+ tags : ${{ steps.meta-worker.outputs.tags }}
85+ labels : ${{ steps.meta-worker.outputs.labels }}
86+ cache-from : type=gha
87+ cache-to : type=gha,mode=max
88+ platforms : linux/amd64
89+
90+ - name : Build summary
91+ if : github.event_name != 'pull_request'
92+ run : |
93+ echo "## 📦 Packages Published" >> $GITHUB_STEP_SUMMARY
94+ echo "" >> $GITHUB_STEP_SUMMARY
95+ echo "Docker images have been published to GitHub Container Registry:" >> $GITHUB_STEP_SUMMARY
96+ echo "" >> $GITHUB_STEP_SUMMARY
97+ echo "### Server" >> $GITHUB_STEP_SUMMARY
98+ echo '```bash' >> $GITHUB_STEP_SUMMARY
99+ echo "docker pull ${{ env.REGISTRY }}/${{ github.repository }}:latest" >> $GITHUB_STEP_SUMMARY
100+ echo '```' >> $GITHUB_STEP_SUMMARY
101+ echo "" >> $GITHUB_STEP_SUMMARY
102+ echo "### Worker" >> $GITHUB_STEP_SUMMARY
103+ echo '```bash' >> $GITHUB_STEP_SUMMARY
104+ echo "docker pull ${{ env.REGISTRY }}/${{ github.repository }}-worker:latest" >> $GITHUB_STEP_SUMMARY
105+ echo '```' >> $GITHUB_STEP_SUMMARY
106+
107+ test :
108+ # PR에서 [e2e] 없을 때만 빌드 테스트 (push 안 함)
109+ if : |
110+ github.event_name == 'pull_request' &&
111+ !contains(github.event.pull_request.title, '[e2e]') &&
112+ !contains(github.event.pull_request.body, '[e2e]')
113+ runs-on : ubuntu-latest
114+
115+ steps :
116+ - name : Checkout repository
117+ uses : actions/checkout@v4
118+
119+ - name : Set up Docker Buildx
120+ uses : docker/setup-buildx-action@v3
121+
122+ - name : Build test server image
123+ uses : docker/build-push-action@v5
124+ with :
125+ context : .
126+ file : ./Dockerfile
127+ target : server-runtime
128+ load : true
129+ tags : V7-server:test
130+ cache-from : type=gha
131+
132+ - name : Build test worker image
133+ uses : docker/build-push-action@v5
134+ with :
135+ context : .
136+ file : ./Dockerfile
137+ target : worker-runtime
138+ load : true
139+ tags : V7-worker:test
140+ cache-from : type=gha
141+
142+ - name : Test Docker images
143+ run : |
144+ echo "Testing Docker images..."
145+ docker images V7-server:test
146+ docker images V7-worker:test
147+ echo "✅ Docker images built successfully"
0 commit comments