1+ name : Create and publish a Docker images for apps
2+
3+ on :
4+ push :
5+ branches :
6+ - main
7+ paths :
8+ - ' TasksTracker.Processor.Backend.Svc/**'
9+ - ' TasksTracker.TasksManager.Backend.Api/**'
10+ - ' TasksTracker.WebPortal.Frontend.Ui/**'
11+ workflow_dispatch : {}
12+
13+ env :
14+ REGISTRY : ghcr.io
15+ BACKEND_API_IMAGE_NAME : azure/tasksmanager-backend-api
16+ FRONTEND_APP_IMAGE_NAME : azure/tasksmanager-frontend-webapp
17+ BACKEND_PROCESSOR_IMAGE_NAME : azure/tasksmanager-backend-processor
18+
19+ jobs :
20+ detect-changes :
21+ name : Detect apps which has changed to trigger image jobs conditionally
22+ runs-on : ubuntu-latest
23+ permissions :
24+ pull-requests : read
25+ outputs :
26+ backend : ${{ steps.filter.outputs.backend }}
27+ frontend : ${{ steps.filter.outputs.frontend }}
28+ processor : ${{ steps.filter.outputs.processor }}
29+ steps :
30+ - uses : actions/checkout@v3
31+ - uses : dorny/paths-filter@v2
32+ id : filter
33+ with :
34+ filters : |
35+ backend:
36+ - 'TasksTracker.TasksManager.Backend.Api/**'
37+ frontend:
38+ - 'TasksTracker.WebPortal.Frontend.Ui/**'
39+ processor:
40+ - 'TasksTracker.Processor.Backend.Svc/**'
41+
42+ build-and-push-backend-image :
43+ needs : detect-changes
44+ name : Build and push backend image
45+ if : ${{ needs.detect-changes.outputs.backend == 'true' }}
46+ runs-on : ubuntu-latest
47+ permissions :
48+ contents : read
49+ packages : write
50+
51+ steps :
52+ - name : Log in to the Container registry
53+ uses : docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
54+ with :
55+ registry : ${{ env.REGISTRY }}
56+ username : ${{ github.actor }}
57+ password : ${{ secrets.GITHUB_TOKEN }}
58+
59+ - name : Extract metadata (tags, labels) for Docker
60+ id : meta
61+ uses : docker/metadata-action@v4
62+ with :
63+ images : ${{ env.REGISTRY }}/${{ env.BACKEND_API_IMAGE_NAME }}
64+ tags : |
65+ type=raw,value=latest,enable={{is_default_branch}}
66+ type=ref,event=branch
67+ type=sha
68+
69+ - name : Build and push Docker image
70+ uses : docker/build-push-action@v4
71+ with :
72+ file : ./TasksTracker.TasksManager.Backend.Api/Dockerfile
73+ push : true
74+ tags : ${{ steps.meta.outputs.tags }}
75+ labels : ${{ steps.meta.outputs.labels }}
76+
77+ build-and-push-frontend-image :
78+ needs : detect-changes
79+ name : Build and push frontend image
80+ if : ${{ needs.detect-changes.outputs.frontend == 'true' }}
81+ runs-on : ubuntu-latest
82+ permissions :
83+ contents : read
84+ packages : write
85+
86+ steps :
87+ - name : Log in to the Container registry
88+ uses : docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
89+ with :
90+ registry : ${{ env.REGISTRY }}
91+ username : ${{ github.actor }}
92+ password : ${{ secrets.GITHUB_TOKEN }}
93+
94+ - name : Extract metadata (tags, labels) for Docker
95+ id : meta
96+ uses : docker/metadata-action@v4
97+ with :
98+ images : ${{ env.REGISTRY }}/${{ env.FRONTEND_APP_IMAGE_NAME }}
99+ tags : |
100+ type=raw,value=latest,enable={{is_default_branch}}
101+ type=ref,event=branch
102+ type=sha
103+
104+ - name : Build and push Docker image
105+ uses : docker/build-push-action@v4
106+ with :
107+ file : ./TasksTracker.WebPortal.Frontend.Ui/Dockerfile
108+ push : true
109+ tags : ${{ steps.meta.outputs.tags }}
110+ labels : ${{ steps.meta.outputs.labels }}
111+
112+ build-and-push-backend-processor-image :
113+ needs : detect-changes
114+ name : Build and push backend processor image
115+ if : ${{ needs.detect-changes.outputs.processor == 'true' }}
116+ runs-on : ubuntu-latest
117+ permissions :
118+ contents : read
119+ packages : write
120+
121+ steps :
122+ - name : Log in to the Container registry
123+ uses : docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
124+ with :
125+ registry : ${{ env.REGISTRY }}
126+ username : ${{ github.actor }}
127+ password : ${{ secrets.GITHUB_TOKEN }}
128+
129+ - name : Extract metadata (tags, labels) for Docker
130+ id : meta
131+ uses : docker/metadata-action@v4
132+ with :
133+ images : ${{ env.REGISTRY }}/${{ env.BACKEND_PROCESSOR_IMAGE_NAME }}
134+ tags : |
135+ type=raw,value=latest,enable={{is_default_branch}}
136+ type=ref,event=branch
137+ type=sha
138+
139+ - name : Build and push Docker image
140+ uses : docker/build-push-action@v4
141+ with :
142+ file : ./TasksTracker.Processor.Backend.Svc/Dockerfile
143+ push : true
144+ tags : ${{ steps.meta.outputs.tags }}
145+ labels : ${{ steps.meta.outputs.labels }}
0 commit comments