-
Notifications
You must be signed in to change notification settings - Fork 0
113 lines (95 loc) · 3.59 KB
/
ci-cd.yml
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
102
103
104
105
106
107
108
109
110
111
112
113
name: CI/CD Pipeline
on:
push:
branches: ['main']
jobs:
build_test_java:
name: Build Java services
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn -B package --file pom.xml
# Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive
- name: Update dependency graph
continue-on-error: true
uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6
build_publish_docker:
name: Build&Publish - Util Docker images
runs-on: ubuntu-latest
needs: build_test_java
strategy:
matrix:
image:
- prometheus
- grafana
- snmp-exporter
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
file: ./docker/${{ matrix.image }}/Dockerfile
push: true
tags: ghcr.io/tobias-pe/microservices_energyefficiency/${{ matrix.image }}:latest, ghcr.io/tobias-pe/microservices_energyefficiency/${{ matrix.image }}:${{ github.run_id }}
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
build_publish_spring_boot:
name: Build&Publish - Spring Boot Docker images
runs-on: ubuntu-latest
needs: build_test_java
strategy:
matrix:
image:
- gateway
- servicediscovery
- userservice
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'temurin'
cache: maven
- name: Make Maven Wrapper executable
if: contains(matrix.os, 'win') == false
run: chmod +x ./mvnw
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set VERSION environment variable
run: |
echo "VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout -pl ${{ matrix.image }})" >> $GITHUB_ENV
- name: Docker Build-Tag-Push
run: |
./mvnw spring-boot:build-image -pl ${{ matrix.image }} -am
docker tag ${{ matrix.image }}:${{ env.VERSION }} ghcr.io/tobias-pe/microservices_energyefficiency/${{ matrix.image }}:${{ github.run_id }}
docker tag ${{ matrix.image }}:${{ env.VERSION }} ghcr.io/tobias-pe/microservices_energyefficiency/${{ matrix.image }}:${{ env.VERSION }}
docker tag ${{ matrix.image }}:${{ env.VERSION }} ghcr.io/tobias-pe/microservices_energyefficiency/${{ matrix.image }}:latest
docker push ghcr.io/tobias-pe/microservices_energyefficiency/${{ matrix.image }}:latest