Skip to content

Commit a9b1839

Browse files
authored
feat: Add Docker Build and Push to CI Pipeline (#10)
## Implementation - [x] Add docker build to CI pipeline - [x] Publish docker image to GitHub Each micro service is built and published separately. - In branches other than `master`, only build will run. - In the `master` branch, both build and publish will run. ## Test - GitHub Actions for Docker Build when running at PR <img width="200" height="400" alt="image" src="https://github.com/user-attachments/assets/64e08088-f0c5-44a7-aa2a-438032c77377" /> <img width="300" height="204" alt="image" src="https://github.com/user-attachments/assets/936b2ad1-2892-4813-9678-1a37dca0f7a9" />
1 parent 20abfd9 commit a9b1839

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Build & Push Docker images
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
permissions:
12+
packages: write
13+
14+
jobs:
15+
docker:
16+
runs-on: ubuntu-latest
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
service:
21+
# Add one entry per microservice
22+
- name: matching-ui
23+
context: ./ui-services/matching-ui-service
24+
- name: questions-ui
25+
context: ./ui-services/question-ui-service
26+
- name: collab-ui
27+
context: ./ui-services/collab-ui-service
28+
- name: user-ui
29+
context: ./ui-services/user-ui-service
30+
- name: history-ui
31+
context: ./ui-services/history-ui-service
32+
33+
steps:
34+
- name: Checkout Repository
35+
uses: actions/checkout@v4
36+
37+
- name: Force owner to lowercase
38+
id: lc
39+
run: echo "value=${GITHUB_REPOSITORY_OWNER,,}" >> "$GITHUB_OUTPUT"
40+
41+
- name: Set up Docker Buildx
42+
uses: docker/setup-buildx-action@v3
43+
44+
- name: Log in to GHCR
45+
if: ${{ github.event_name != 'pull_request' }}
46+
uses: docker/login-action@v3
47+
with:
48+
registry: ghcr.io
49+
username: ${{ steps.lc.outputs.value }}
50+
password: ${{ secrets.GITHUB_TOKEN }}
51+
52+
- name: Extract Docker metadata (tags/labels)
53+
id: meta
54+
uses: docker/metadata-action@v5
55+
with:
56+
images: |
57+
ghcr.io/${{ steps.lc.outputs.value }}/peerprep-${{ matrix.service.name }}
58+
tags: |
59+
type=raw,value=${{ github.sha }}
60+
type=ref,event=branch
61+
type=ref,event=tag
62+
type=raw,value=latest,enable=${{ github.ref_name == 'master' }}
63+
64+
- name: Build (no push for PRs)
65+
if: ${{ github.event_name == 'pull_request' }}
66+
uses: docker/build-push-action@v6
67+
with:
68+
context: ${{ matrix.service.context }}
69+
file: ${{ matrix.service.dockerfile }}
70+
push: false
71+
labels: ${{ steps.meta.outputs.labels }}
72+
cache-from: type=gha
73+
cache-to: type=gha,mode=max
74+
75+
- name: Build & Push
76+
if: ${{ github.event_name != 'pull_request' }}
77+
uses: docker/build-push-action@v6
78+
with:
79+
context: ${{ matrix.service.context }}
80+
file: ${{ matrix.service.dockerfile }}
81+
push: true
82+
tags: ${{ steps.meta.outputs.tags }}
83+
labels: ${{ steps.meta.outputs.labels }}
84+
cache-from: type=gha
85+
cache-to: type=gha,mode=max
86+

0 commit comments

Comments
 (0)