-
Notifications
You must be signed in to change notification settings - Fork 0
101 lines (90 loc) · 2.8 KB
/
Copy pathtest-build-push.yml
File metadata and controls
101 lines (90 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
name: Test, Build and Push Images
# Runs tests and builds images on every branch.
# Pushes to the registry only on main, or on a manual workflow_dispatch run.
on:
push:
branches:
- '**'
workflow_dispatch:
permissions:
contents: read
packages: write
jobs:
test:
name: Run Java Tests
runs-on: ubuntu-latest
strategy:
matrix:
service: [api-gateway, user-service, grocery-service]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: maven
- name: Run tests with Maven
run: cd server/${{ matrix.service }} && ./mvnw -B test
test-gatekeeper:
name: Run Java Tests
needs: test
runs-on: ubuntu-latest
steps:
- name: Success Gate
run: echo "All matrix sub-tests passed successfully!"
build:
name: Build ${{ matrix.image }}
needs: test-gatekeeper
runs-on: ubuntu-latest
strategy:
matrix:
include:
- image: client
context: ./client
- image: api-gateway
context: ./server/api-gateway
- image: user-service
context: ./server/user-service
- image: grocery-service
context: ./server/grocery-service
- image: gen-ai
context: ./gen-ai
- image: user-db
context: ./databases/user-db
- image: grocery-db
context: ./databases/grocery-db
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Install Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
# metadata-action lowercases the image name for ghcr.io automatically.
images: ghcr.io/${{ github.repository }}/${{ matrix.image }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=branch
type=sha,format=long,prefix=
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: ${{ matrix.context }}
file: ${{ matrix.context }}/Dockerfile
push: ${{ github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max