chore(spring-kafka-example): add Docker support and split application…#13
Conversation
….yml by environment
WalkthroughSeveral foundational files were added to the Changes
Sequence Diagram(s)sequenceDiagram
participant Developer
participant Docker
participant Maven
participant SpringApp
Developer->>Docker: Build image (Dockerfile)
Docker->>Maven: Fetch dependencies (deps stage)
Docker->>Maven: Build JAR (package stage)
Docker->>SpringApp: Extract layers (extract stage)
Docker->>SpringApp: Run app with JarLauncher (final stage)
SpringApp->>Developer: Application runs on port 80
Poem
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (4)
spring-kafka-example/src/main/resources/application.yml (1)
4-4: Avoid hard-coding environment suffix in the default profile
application.ymlis loaded for every profile unless overridden. Encoding-prddirectly inspring.application.nameforces production naming even for dev/test runs where this file is still loaded (e.g. when the dev profile is layered on top). Prefer keeping the neutral name here and override it only inapplication-prd.yml, mirroring what you did forapplication-dev.yml.spring-kafka-example/src/main/resources/application-dev.yml (1)
1-9: Terminate file with a trailing newline
Many tooling chains (git, POSIX text utils, linters) expect a newline at EOF. YAMLlint already flags this.- console: "%d{yyyy-MM-dd'T'HH:mm:ss} | ${spring.application.name} | %class{30} | %level | %m%n" +\ console: "%d{yyyy-MM-dd'T'HH:mm:ss} | ${spring.application.name} | %class{30} | %level | %m%n"\nspring-kafka-example/.dockerignore (1)
27-29: Re-evaluate ignoring Dockerfile / compose descriptors
The patterns**/Dockerfile*and**/compose.y*mlexclude these files from the build context.
While the Docker CLI still sends the primaryDockerfile(specified via-for default), excluding it prevents multi-file copies during the build (COPY Dockerfile …) and makes debugging inside the image harder. Usually you keep these two files in context and rely on layer caching.spring-kafka-example/Dockerfile (1)
40-44: Use absolute paths in multi-stage COPY for clarity
Prependingbuild/…works, but the leading segment is redundant because the working directory of theextractstage is/build. Explicit absolute paths avoid confusion:-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/ ./ +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/ ./
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
spring-kafka-example/.dockerignore(1 hunks)spring-kafka-example/Dockerfile(1 hunks)spring-kafka-example/compose.yaml(1 hunks)spring-kafka-example/src/main/resources/application-dev.yml(1 hunks)spring-kafka-example/src/main/resources/application.yml(1 hunks)
🧰 Additional context used
🪛 YAMLlint (1.37.1)
spring-kafka-example/src/main/resources/application-dev.yml
[error] 9-9: no new line character at the end of file
(new-line-at-end-of-file)
| - "80:80" | ||
| environment: | ||
| SERVER_PORT: "80" | ||
| SPRING_PROFILES_ACTIVE: "default" |
There was a problem hiding this comment.
Non-root image cannot bind to port 80
Your Dockerfile switches to appuser (UID 10001). Binding to privileged ports (<1024) will fail without CAP_NET_BIND_SERVICE. Either:
- Expose/bind an unprivileged port (e.g. 8080) inside the container and keep host port 80, or
- Grant the extra capability.
Most teams adopt option 1 for least-privilege.
- - "80:80"
+ - "80:8080"
...
- SERVER_PORT: "80"
+ SERVER_PORT: "8080"📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| - "80:80" | |
| environment: | |
| SERVER_PORT: "80" | |
| SPRING_PROFILES_ACTIVE: "default" | |
| - "80:8080" | |
| environment: | |
| SERVER_PORT: "8080" | |
| SPRING_PROFILES_ACTIVE: "default" |
🤖 Prompt for AI Agents
In spring-kafka-example/compose.yaml around lines 6 to 9, the container is set
to bind the application to port 80, which is a privileged port and cannot be
bound by a non-root user (appuser with UID 10001). To fix this, change the
SERVER_PORT environment variable to an unprivileged port like 8080 and update
the port mapping to bind host port 80 to container port 8080 (e.g., "80:8080").
This avoids requiring extra capabilities and follows least-privilege best
practices.
There was a problem hiding this comment.
using port 80 in docker does not cause issues
There was a problem hiding this comment.
@igorcampos-dev Thank you for the clarification! I appreciate you sharing your experience with this configuration. If it's working in your environment without issues, then that's what matters most for your setup.
✏️ Learnings added
Learnt from: igorcampos-dev
PR: igorcampos-dev/spring-integrations-examples#13
File: spring-kafka-example/compose.yaml:6-9
Timestamp: 2025-07-21T00:47:12.429Z
Learning: In Docker containers, binding to port 80 with a non-root user may work in certain configurations or environments, despite port 80 being a privileged port. The user igorcampos-dev has confirmed that using port 80 in their Docker setup does not cause issues.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
….yml by environment
Summary by CodeRabbit
New Features
Chores
.dockerignorefile to optimize Docker builds by excluding unnecessary files.Style