Skip to content

Commit 0808582

Browse files
chore(spring-kafka-example): add Docker support and split application.yml by environment
1 parent e2a9cba commit 0808582

File tree

5 files changed

+129
-1
lines changed

5 files changed

+129
-1
lines changed

spring-kafka-example/.dockerignore

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Include any files or directories that you don't want to be copied to your
2+
# container here (e.g., local build artifacts, temporary files, etc.).
3+
#
4+
# For more help, visit the .dockerignore file reference guide at
5+
# https://docs.docker.com/go/build-context-dockerignore/
6+
7+
**/.DS_Store
8+
**/.classpath
9+
**/.dockerignore
10+
**/.env
11+
**/.factorypath
12+
**/.git
13+
**/.gitignore
14+
**/.idea
15+
**/.project
16+
**/.sts4-cache
17+
**/.settings
18+
**/.toolstarget
19+
**/.vs
20+
**/.vscode
21+
**/.next
22+
**/.cache
23+
**/*.dbmdl
24+
**/*.jfm
25+
**/charts
26+
**/docker-compose*
27+
**/compose.y*ml
28+
**/Dockerfile*
29+
**/secrets.dev.yaml
30+
**/values.dev.yaml
31+
**/vendor
32+
LICENSE
33+
README.md
34+
**/*.class
35+
**/*.iml
36+
**/*.ipr
37+
**/*.iws
38+
**/*.log
39+
**/.apt_generated
40+
**/.gradle
41+
**/.gradletasknamecache
42+
**/.nb-gradle
43+
**/.springBeans
44+
**/build
45+
**/dist
46+
**/gradle-app.setting
47+
**/nbbuild
48+
**/nbdist
49+
**/nbproject/private
50+
**/target
51+
*.ctxt
52+
.mtj.tmp
53+
.mvn/timing.properties
54+
buildNumber.properties
55+
dependency-reduced-pom.xml
56+
hs_err_pid*
57+
pom.xml.next
58+
pom.xml.releaseBackup
59+
pom.xml.tag
60+
pom.xml.versionsBackup
61+
release.properties
62+
replay_pid*

spring-kafka-example/Dockerfile

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
FROM eclipse-temurin:21-jdk-jammy as deps
2+
3+
WORKDIR /build
4+
5+
COPY --chmod=0755 mvnw mvnw
6+
COPY .mvn/ .mvn/
7+
8+
RUN --mount=type=bind,source=pom.xml,target=pom.xml \
9+
--mount=type=cache,target=/root/.m2 ./mvnw dependency:go-offline -DskipTests
10+
11+
FROM deps as package
12+
13+
WORKDIR /build
14+
15+
COPY ./src src/
16+
RUN --mount=type=bind,source=pom.xml,target=pom.xml \
17+
--mount=type=cache,target=/root/.m2 \
18+
./mvnw package -DskipTests && \
19+
mv target/$(./mvnw help:evaluate -Dexpression=project.artifactId -q -DforceStdout)-$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout).jar target/app.jar
20+
21+
FROM package as extract
22+
23+
WORKDIR /build
24+
25+
RUN java -Djarmode=layertools -jar target/app.jar extract --destination target/extracted
26+
27+
FROM eclipse-temurin:21-jre-jammy AS final
28+
29+
ARG UID=10001
30+
RUN adduser \
31+
--disabled-password \
32+
--gecos "" \
33+
--home "/nonexistent" \
34+
--shell "/sbin/nologin" \
35+
--no-create-home \
36+
--uid "${UID}" \
37+
appuser
38+
USER appuser
39+
40+
COPY --from=extract build/target/extracted/dependencies/ ./
41+
COPY --from=extract build/target/extracted/spring-boot-loader/ ./
42+
COPY --from=extract build/target/extracted/snapshot-dependencies/ ./
43+
COPY --from=extract build/target/extracted/application/ ./
44+
45+
EXPOSE 80
46+
47+
ENTRYPOINT [ "java", "org.springframework.boot.loader.launch.JarLauncher" ]

spring-kafka-example/compose.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
services:
2+
server:
3+
build:
4+
context: .
5+
ports:
6+
- "80:80"
7+
environment:
8+
SERVER_PORT: "80"
9+
SPRING_PROFILES_ACTIVE: "default"
10+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
spring:
2+
3+
application:
4+
name: spring-kafka-example-dev
5+
6+
logging:
7+
8+
pattern:
9+
console: "%d{yyyy-MM-dd'T'HH:mm:ss} | ${spring.application.name} | %class{30} | %level | %m%n"

spring-kafka-example/src/main/resources/application.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
spring:
22

33
application:
4-
name: spring-kafka-example
4+
name: spring-kafka-example-prd
55

66
logging:
77

0 commit comments

Comments
 (0)