-
Notifications
You must be signed in to change notification settings - Fork 0
chore(spring-kafka-example): add Docker support and split application… #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| # Include any files or directories that you don't want to be copied to your | ||
| # container here (e.g., local build artifacts, temporary files, etc.). | ||
| # | ||
| # For more help, visit the .dockerignore file reference guide at | ||
| # https://docs.docker.com/go/build-context-dockerignore/ | ||
|
|
||
| **/.DS_Store | ||
| **/.classpath | ||
| **/.dockerignore | ||
| **/.env | ||
| **/.factorypath | ||
| **/.git | ||
| **/.gitignore | ||
| **/.idea | ||
| **/.project | ||
| **/.sts4-cache | ||
| **/.settings | ||
| **/.toolstarget | ||
| **/.vs | ||
| **/.vscode | ||
| **/.next | ||
| **/.cache | ||
| **/*.dbmdl | ||
| **/*.jfm | ||
| **/charts | ||
| **/docker-compose* | ||
| **/compose.y*ml | ||
| **/Dockerfile* | ||
| **/secrets.dev.yaml | ||
| **/values.dev.yaml | ||
| **/vendor | ||
| LICENSE | ||
| README.md | ||
| **/*.class | ||
| **/*.iml | ||
| **/*.ipr | ||
| **/*.iws | ||
| **/*.log | ||
| **/.apt_generated | ||
| **/.gradle | ||
| **/.gradletasknamecache | ||
| **/.nb-gradle | ||
| **/.springBeans | ||
| **/build | ||
| **/dist | ||
| **/gradle-app.setting | ||
| **/nbbuild | ||
| **/nbdist | ||
| **/nbproject/private | ||
| **/target | ||
| *.ctxt | ||
| .mtj.tmp | ||
| .mvn/timing.properties | ||
| buildNumber.properties | ||
| dependency-reduced-pom.xml | ||
| hs_err_pid* | ||
| pom.xml.next | ||
| pom.xml.releaseBackup | ||
| pom.xml.tag | ||
| pom.xml.versionsBackup | ||
| release.properties | ||
| replay_pid* |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| FROM eclipse-temurin:21-jdk-jammy as deps | ||
|
|
||
| WORKDIR /build | ||
|
|
||
| COPY --chmod=0755 mvnw mvnw | ||
| COPY .mvn/ .mvn/ | ||
|
|
||
| RUN --mount=type=bind,source=pom.xml,target=pom.xml \ | ||
| --mount=type=cache,target=/root/.m2 ./mvnw dependency:go-offline -DskipTests | ||
|
|
||
| FROM deps as package | ||
|
|
||
| WORKDIR /build | ||
|
|
||
| COPY ./src src/ | ||
| RUN --mount=type=bind,source=pom.xml,target=pom.xml \ | ||
| --mount=type=cache,target=/root/.m2 \ | ||
| ./mvnw package -DskipTests && \ | ||
| mv target/$(./mvnw help:evaluate -Dexpression=project.artifactId -q -DforceStdout)-$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout).jar target/app.jar | ||
|
|
||
| FROM package as extract | ||
|
|
||
| WORKDIR /build | ||
|
|
||
| RUN java -Djarmode=layertools -jar target/app.jar extract --destination target/extracted | ||
|
|
||
| FROM eclipse-temurin:21-jre-jammy AS final | ||
|
|
||
| ARG UID=10001 | ||
| RUN adduser \ | ||
| --disabled-password \ | ||
| --gecos "" \ | ||
| --home "/nonexistent" \ | ||
| --shell "/sbin/nologin" \ | ||
| --no-create-home \ | ||
| --uid "${UID}" \ | ||
| appuser | ||
| USER appuser | ||
|
|
||
| COPY --from=extract build/target/extracted/dependencies/ ./ | ||
| COPY --from=extract build/target/extracted/spring-boot-loader/ ./ | ||
| COPY --from=extract build/target/extracted/snapshot-dependencies/ ./ | ||
| COPY --from=extract build/target/extracted/application/ ./ | ||
|
|
||
| EXPOSE 80 | ||
|
|
||
| ENTRYPOINT [ "java", "org.springframework.boot.loader.launch.JarLauncher" ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| services: | ||
| server: | ||
| build: | ||
| context: . | ||
| ports: | ||
| - "80:80" | ||
| environment: | ||
| SERVER_PORT: "80" | ||
| SPRING_PROFILES_ACTIVE: "default" | ||
|
Comment on lines
+8
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Activate the correct Spring profile for local runs. If the goal is development convenience, set: - SPRING_PROFILES_ACTIVE: "default"
+ SPRING_PROFILES_ACTIVE: "dev"so the new 🤖 Prompt for AI Agents |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| spring: | ||
|
|
||
| application: | ||
| name: spring-kafka-example-dev | ||
|
|
||
| logging: | ||
|
|
||
| pattern: | ||
| console: "%d{yyyy-MM-dd'T'HH:mm:ss} | ${spring.application.name} | %class{30} | %level | %m%n" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| spring: | ||
|
|
||
| application: | ||
| name: spring-kafka-example | ||
| name: spring-kafka-example-prd | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Keep the logical environment suffix in sync with
🤖 Prompt for AI Agents |
||
|
|
||
| logging: | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Container will fail to start – non-root user cannot bind to port 80.
Dockerfileswitches to UID 10001 (non-root) whilecompose.yamlmaps container port 80 and setsSERVER_PORT=80.Ports < 1024 require the
CAP_NET_BIND_SERVICEcapability or root. The JVM will throw “Permission denied: bind”.Quick fixes (pick one):
or
but the first option keeps the image simpler.
🤖 Prompt for AI Agents