-
Notifications
You must be signed in to change notification settings - Fork 0
180 lines (163 loc) · 6.45 KB
/
docker-image.yml
File metadata and controls
180 lines (163 loc) · 6.45 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
name: Build and Publish Docker Image
on:
push:
branches: [main]
pull_request:
branches: [main]
env:
MAVEN_VERSION: "3.9.11"
REGISTRY_IMAGE: ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKERHUB_PROJECT_NAME }}
jobs:
build-test-push:
name: Build/Test/Publish (Java ${{ matrix.java-version }}, Boot ${{ matrix.spring-boot-version }})
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
include:
- java-version: "17"
spring-boot-version: "4.0.0"
spring-cloud-version: "2025.1.0"
- java-version: "21"
spring-boot-version: "4.0.0"
spring-cloud-version: "2025.1.0"
- java-version: "25"
spring-boot-version: "4.0.0"
spring-cloud-version: "2025.1.0"
- java-version: "17"
spring-boot-version: "3.5.8"
spring-cloud-version: "2025.0.0"
- java-version: "21"
spring-boot-version: "3.5.8"
spring-cloud-version: "2025.0.0"
- java-version: "25"
spring-boot-version: "3.5.8"
spring-cloud-version: "2025.0.0"
steps:
- name: Checkout source code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Java
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: ${{ matrix.java-version }}
cache: maven
- name: Align Maven versions for matrix
run: |
mvn -B -ntp versions:update-parent \
-DparentVersion="[${{ matrix.spring-boot-version }}]" \
-DgenerateBackupPoms=false \
-DskipResolution=true \
-DallowSnapshots=false \
-DforceVersion=true
mvn -B -ntp versions:set-property \
-Dproperty=spring-cloud.version \
-DnewVersion=${{ matrix.spring-cloud-version }} \
-DgenerateBackupPoms=false
mvn -B -ntp versions:set-property \
-Dproperty=java.version \
-DnewVersion=${{ matrix.java-version }} \
-DgenerateBackupPoms=false
- name: Run Maven tests
run: mvn -B -ntp verify
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-java${{ matrix.java-version }}-boot${{ matrix.spring-boot-version }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-java${{ matrix.java-version }}-boot${{ matrix.spring-boot-version }}-
${{ runner.os }}-buildx-
- name: Build test image
run: |
docker build \
--build-arg JAVA_VERSION=${{ matrix.java-version }} \
--build-arg MAVEN_VERSION=${{ env.MAVEN_VERSION }} \
--build-arg SPRING_BOOT_VERSION=${{ matrix.spring-boot-version }} \
--build-arg SPRING_CLOUD_VERSION=${{ matrix.spring-cloud-version }} \
-t config-server:ci-test .
- name: Smoke test default Git backend
run: |
set -euo pipefail
container_name=config-server-smoke-git
cleanup() {
docker logs "$container_name" || true
docker rm -f "$container_name" >/dev/null 2>&1 || true
}
trap cleanup EXIT
docker run -d --rm --name "$container_name" -p 8888:8888 config-server:ci-test
for attempt in $(seq 1 30); do
if curl -fsS http://localhost:8888/actuator/health | grep -q '"status":"UP"'; then
exit 0
fi
sleep 2
done
echo "Config Server (Git backend) did not become healthy in time" >&2
exit 1
- name: Smoke test native filesystem backend
run: |
set -euo pipefail
native_dir="$(mktemp -d)"
cat <<'EOF' > "$native_dir"/application.yml
example:
message: native-backend
EOF
container_name=config-server-smoke-native
cleanup() {
docker logs "$container_name" || true
docker rm -f "$container_name" >/dev/null 2>&1 || true
rm -rf "$native_dir"
}
trap cleanup EXIT
docker run -d --rm --name "$container_name" -p 8888:8888 \
-e SPRING_PROFILES_ACTIVE=native \
-e SPRING_CLOUD_CONFIG_SERVER_NATIVE_SEARCH_LOCATIONS=file:/opt/config-server/native \
-v "$native_dir":/opt/config-server/native:ro \
config-server:ci-test
for attempt in $(seq 1 30); do
if curl -fsS http://localhost:8888/actuator/health | grep -q '"status":"UP"'; then
exit 0
fi
sleep 2
done
echo "Config Server (native backend) did not become healthy in time" >&2
exit 1
- name: Extract metadata
id: meta
run: |
echo "repo_name=${GITHUB_REPOSITORY##*/}" >> "$GITHUB_OUTPUT"
echo "short_sha=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
- name: Log in to Docker Hub
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and (optionally) push image
uses: docker/build-push-action@v6
with:
context: .
push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
platforms: linux/amd64,linux/arm64
tags: |
${{ env.REGISTRY_IMAGE }}:java${{ matrix.java-version }}-boot${{ matrix.spring-boot-version }}
${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.short_sha }}-java${{ matrix.java-version }}-boot${{ matrix.spring-boot-version }}
build-args: |
JAVA_VERSION=${{ matrix.java-version }}
MAVEN_VERSION=${{ env.MAVEN_VERSION }}
SPRING_BOOT_VERSION=${{ matrix.spring-boot-version }}
SPRING_CLOUD_VERSION=${{ matrix.spring-cloud-version }}
labels: |
org.opencontainers.image.source=${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache,mode=max