99# within its specific directory have changed. This is determined by a preliminary 'changes' job.
1010# - Dynamic Tagging: Docker images are tagged with a unique, time-based versioning scheme
1111# (v1.YYYYMMDD.HHMMSSfff) to ensure traceability.
12- # - Reusable Logic: YAML anchors are used to define the build-and-publish steps once, keeping
13- # the workflow DRY (Don't Repeat Yourself) and easy to maintain.
1412
1513name : Build and Publish Services
1614
2119 paths :
2220 - ' src/**'
2321
24- # Reusable steps for building, tagging, and pushing a Docker image.
25- # This anchor (`x-build-and-publish-steps`) is referenced by each service's job.
26- x-build-and-publish-steps : &build-and-publish-steps
27- - name : Log in to GitHub Container Registry
28- uses : docker/login-action@v3
29- with :
30- registry : ghcr.io
31- username : ${{ github.actor }}
32- password : ${{ secrets.GITHUB_TOKEN }}
33-
34- - name : Generate unique image tag
35- id : image_tag
36- run : echo "TAG=v1.$(date +'%Y%m%d.%H%M%S%3N')" >> "$GITHUB_OUTPUT"
37-
38- - name : Build and push Docker image
39- uses : docker/build-push-action@v5
40- with :
41- context : src/${{ env.SERVICE_NAME }}
42- push : true
43- tags : ghcr.io/DO-Solutions/microservices-demo-${{ env.SERVICE_NAME }}:${{ steps.image_tag.outputs.TAG }}
44-
4522jobs :
4623 # This job checks which service directories have changed and sets corresponding outputs.
4724 changes :
@@ -101,7 +78,22 @@ jobs:
10178 runs-on : ubuntu-latest
10279 env :
10380 SERVICE_NAME : adservice
104- steps : *build-and-publish-steps
81+ steps :
82+ - name : Log in to GitHub Container Registry
83+ uses : docker/login-action@v3
84+ with :
85+ registry : ghcr.io
86+ username : ${{ github.actor }}
87+ password : ${{ secrets.GITHUB_TOKEN }}
88+ - name : Generate unique image tag
89+ id : image_tag
90+ run : echo "TAG=v1.$(date +'%Y%m%d.%H%M%S%3N')" >> "$GITHUB_OUTPUT"
91+ - name : Build and push Docker image
92+ uses : docker/build-push-action@v5
93+ with :
94+ context : src/${{ env.SERVICE_NAME }}
95+ push : true
96+ tags : ghcr.io/DO-Solutions/microservices-demo-${{ env.SERVICE_NAME }}:${{ steps.image_tag.outputs.TAG }}
10597
10698 cartservice :
10799 name : Build and Publish Cart Service
@@ -110,7 +102,22 @@ jobs:
110102 runs-on : ubuntu-latest
111103 env :
112104 SERVICE_NAME : cartservice
113- steps : *build-and-publish-steps
105+ steps :
106+ - name : Log in to GitHub Container Registry
107+ uses : docker/login-action@v3
108+ with :
109+ registry : ghcr.io
110+ username : ${{ github.actor }}
111+ password : ${{ secrets.GITHUB_TOKEN }}
112+ - name : Generate unique image tag
113+ id : image_tag
114+ run : echo "TAG=v1.$(date +'%Y%m%d.%H%M%S%3N')" >> "$GITHUB_OUTPUT"
115+ - name : Build and push Docker image
116+ uses : docker/build-push-action@v5
117+ with :
118+ context : src/${{ env.SERVICE_NAME }}
119+ push : true
120+ tags : ghcr.io/DO-Solutions/microservices-demo-${{ env.SERVICE_NAME }}:${{ steps.image_tag.outputs.TAG }}
114121
115122 checkoutservice :
116123 name : Build and Publish Checkout Service
@@ -119,7 +126,22 @@ jobs:
119126 runs-on : ubuntu-latest
120127 env :
121128 SERVICE_NAME : checkoutservice
122- steps : *build-and-publish-steps
129+ steps :
130+ - name : Log in to GitHub Container Registry
131+ uses : docker/login-action@v3
132+ with :
133+ registry : ghcr.io
134+ username : ${{ github.actor }}
135+ password : ${{ secrets.GITHUB_TOKEN }}
136+ - name : Generate unique image tag
137+ id : image_tag
138+ run : echo "TAG=v1.$(date +'%Y%m%d.%H%M%S%3N')" >> "$GITHUB_OUTPUT"
139+ - name : Build and push Docker image
140+ uses : docker/build-push-action@v5
141+ with :
142+ context : src/${{ env.SERVICE_NAME }}
143+ push : true
144+ tags : ghcr.io/DO-Solutions/microservices-demo-${{ env.SERVICE_NAME }}:${{ steps.image_tag.outputs.TAG }}
123145
124146 currencyservice :
125147 name : Build and Publish Currency Service
@@ -128,7 +150,22 @@ jobs:
128150 runs-on : ubuntu-latest
129151 env :
130152 SERVICE_NAME : currencyservice
131- steps : *build-and-publish-steps
153+ steps :
154+ - name : Log in to GitHub Container Registry
155+ uses : docker/login-action@v3
156+ with :
157+ registry : ghcr.io
158+ username : ${{ github.actor }}
159+ password : ${{ secrets.GITHUB_TOKEN }}
160+ - name : Generate unique image tag
161+ id : image_tag
162+ run : echo "TAG=v1.$(date +'%Y%m%d.%H%M%S%3N')" >> "$GITHUB_OUTPUT"
163+ - name : Build and push Docker image
164+ uses : docker/build-push-action@v5
165+ with :
166+ context : src/${{ env.SERVICE_NAME }}
167+ push : true
168+ tags : ghcr.io/DO-Solutions/microservices-demo-${{ env.SERVICE_NAME }}:${{ steps.image_tag.outputs.TAG }}
132169
133170 emailservice :
134171 name : Build and Publish Email Service
@@ -137,7 +174,22 @@ jobs:
137174 runs-on : ubuntu-latest
138175 env :
139176 SERVICE_NAME : emailservice
140- steps : *build-and-publish-steps
177+ steps :
178+ - name : Log in to GitHub Container Registry
179+ uses : docker/login-action@v3
180+ with :
181+ registry : ghcr.io
182+ username : ${{ github.actor }}
183+ password : ${{ secrets.GITHUB_TOKEN }}
184+ - name : Generate unique image tag
185+ id : image_tag
186+ run : echo "TAG=v1.$(date +'%Y%m%d.%H%M%S%3N')" >> "$GITHUB_OUTPUT"
187+ - name : Build and push Docker image
188+ uses : docker/build-push-action@v5
189+ with :
190+ context : src/${{ env.SERVICE_NAME }}
191+ push : true
192+ tags : ghcr.io/DO-Solutions/microservices-demo-${{ env.SERVICE_NAME }}:${{ steps.image_tag.outputs.TAG }}
141193
142194 frontend :
143195 name : Build and Publish Frontend Service
@@ -146,7 +198,22 @@ jobs:
146198 runs-on : ubuntu-latest
147199 env :
148200 SERVICE_NAME : frontend
149- steps : *build-and-publish-steps
201+ steps :
202+ - name : Log in to GitHub Container Registry
203+ uses : docker/login-action@v3
204+ with :
205+ registry : ghcr.io
206+ username : ${{ github.actor }}
207+ password : ${{ secrets.GITHUB_TOKEN }}
208+ - name : Generate unique image tag
209+ id : image_tag
210+ run : echo "TAG=v1.$(date +'%Y%m%d.%H%M%S%3N')" >> "$GITHUB_OUTPUT"
211+ - name : Build and push Docker image
212+ uses : docker/build-push-action@v5
213+ with :
214+ context : src/${{ env.SERVICE_NAME }}
215+ push : true
216+ tags : ghcr.io/DO-Solutions/microservices-demo-${{ env.SERVICE_NAME }}:${{ steps.image_tag.outputs.TAG }}
150217
151218 loadgenerator :
152219 name : Build and Publish Load Generator
@@ -155,7 +222,22 @@ jobs:
155222 runs-on : ubuntu-latest
156223 env :
157224 SERVICE_NAME : loadgenerator
158- steps : *build-and-publish-steps
225+ steps :
226+ - name : Log in to GitHub Container Registry
227+ uses : docker/login-action@v3
228+ with :
229+ registry : ghcr.io
230+ username : ${{ github.actor }}
231+ password : ${{ secrets.GITHUB_TOKEN }}
232+ - name : Generate unique image tag
233+ id : image_tag
234+ run : echo "TAG=v1.$(date +'%Y%m%d.%H%M%S%3N')" >> "$GITHUB_OUTPUT"
235+ - name : Build and push Docker image
236+ uses : docker/build-push-action@v5
237+ with :
238+ context : src/${{ env.SERVICE_NAME }}
239+ push : true
240+ tags : ghcr.io/DO-Solutions/microservices-demo-${{ env.SERVICE_NAME }}:${{ steps.image_tag.outputs.TAG }}
159241
160242 paymentservice :
161243 name : Build and Publish Payment Service
@@ -164,7 +246,22 @@ jobs:
164246 runs-on : ubuntu-latest
165247 env :
166248 SERVICE_NAME : paymentservice
167- steps : *build-and-publish-steps
249+ steps :
250+ - name : Log in to GitHub Container Registry
251+ uses : docker/login-action@v3
252+ with :
253+ registry : ghcr.io
254+ username : ${{ github.actor }}
255+ password : ${{ secrets.GITHUB_TOKEN }}
256+ - name : Generate unique image tag
257+ id : image_tag
258+ run : echo "TAG=v1.$(date +'%Y%m%d.%H%M%S%3N')" >> "$GITHUB_OUTPUT"
259+ - name : Build and push Docker image
260+ uses : docker/build-push-action@v5
261+ with :
262+ context : src/${{ env.SERVICE_NAME }}
263+ push : true
264+ tags : ghcr.io/DO-Solutions/microservices-demo-${{ env.SERVICE_NAME }}:${{ steps.image_tag.outputs.TAG }}
168265
169266 productcatalogservice :
170267 name : Build and Publish Product Catalog Service
@@ -173,7 +270,22 @@ jobs:
173270 runs-on : ubuntu-latest
174271 env :
175272 SERVICE_NAME : productcatalogservice
176- steps : *build-and-publish-steps
273+ steps :
274+ - name : Log in to GitHub Container Registry
275+ uses : docker/login-action@v3
276+ with :
277+ registry : ghcr.io
278+ username : ${{ github.actor }}
279+ password : ${{ secrets.GITHUB_TOKEN }}
280+ - name : Generate unique image tag
281+ id : image_tag
282+ run : echo "TAG=v1.$(date +'%Y%m%d.%H%M%S%3N')" >> "$GITHUB_OUTPUT"
283+ - name : Build and push Docker image
284+ uses : docker/build-push-action@v5
285+ with :
286+ context : src/${{ env.SERVICE_NAME }}
287+ push : true
288+ tags : ghcr.io/DO-Solutions/microservices-demo-${{ env.SERVICE_NAME }}:${{ steps.image_tag.outputs.TAG }}
177289
178290 recommendationservice :
179291 name : Build and Publish Recommendation Service
@@ -182,7 +294,22 @@ jobs:
182294 runs-on : ubuntu-latest
183295 env :
184296 SERVICE_NAME : recommendationservice
185- steps : *build-and-publish-steps
297+ steps :
298+ - name : Log in to GitHub Container Registry
299+ uses : docker/login-action@v3
300+ with :
301+ registry : ghcr.io
302+ username : ${{ github.actor }}
303+ password : ${{ secrets.GITHUB_TOKEN }}
304+ - name : Generate unique image tag
305+ id : image_tag
306+ run : echo "TAG=v1.$(date +'%Y%m%d.%H%M%S%3N')" >> "$GITHUB_OUTPUT"
307+ - name : Build and push Docker image
308+ uses : docker/build-push-action@v5
309+ with :
310+ context : src/${{ env.SERVICE_NAME }}
311+ push : true
312+ tags : ghcr.io/DO-Solutions/microservices-demo-${{ env.SERVICE_NAME }}:${{ steps.image_tag.outputs.TAG }}
186313
187314 shippingservice :
188315 name : Build and Publish Shipping Service
@@ -191,7 +318,22 @@ jobs:
191318 runs-on : ubuntu-latest
192319 env :
193320 SERVICE_NAME : shippingservice
194- steps : *build-and-publish-steps
321+ steps :
322+ - name : Log in to GitHub Container Registry
323+ uses : docker/login-action@v3
324+ with :
325+ registry : ghcr.io
326+ username : ${{ github.actor }}
327+ password : ${{ secrets.GITHUB_TOKEN }}
328+ - name : Generate unique image tag
329+ id : image_tag
330+ run : echo "TAG=v1.$(date +'%Y%m%d.%H%M%S%3N')" >> "$GITHUB_OUTPUT"
331+ - name : Build and push Docker image
332+ uses : docker/build-push-action@v5
333+ with :
334+ context : src/${{ env.SERVICE_NAME }}
335+ push : true
336+ tags : ghcr.io/DO-Solutions/microservices-demo-${{ env.SERVICE_NAME }}:${{ steps.image_tag.outputs.TAG }}
195337
196338 shoppingassistantservice :
197339 name : Build and Publish Shopping Assistant Service
@@ -200,4 +342,19 @@ jobs:
200342 runs-on : ubuntu-latest
201343 env :
202344 SERVICE_NAME : shoppingassistantservice
203- steps : *build-and-publish-steps
345+ steps :
346+ - name : Log in to GitHub Container Registry
347+ uses : docker/login-action@v3
348+ with :
349+ registry : ghcr.io
350+ username : ${{ github.actor }}
351+ password : ${{ secrets.GITHUB_TOKEN }}
352+ - name : Generate unique image tag
353+ id : image_tag
354+ run : echo "TAG=v1.$(date +'%Y%m%d.%H%M%S%3N')" >> "$GITHUB_OUTPUT"
355+ - name : Build and push Docker image
356+ uses : docker/build-push-action@v5
357+ with :
358+ context : src/${{ env.SERVICE_NAME }}
359+ push : true
360+ tags : ghcr.io/DO-Solutions/microservices-demo-${{ env.SERVICE_NAME }}:${{ steps.image_tag.outputs.TAG }}
0 commit comments