chore(spring-kafka-example): add Docker support and split application…#11
chore(spring-kafka-example): add Docker support and split application…#11igorcampos-dev wants to merge 2 commits intomasterfrom
Conversation
….yml by environment
|
Caution Review failedThe pull request is closed. WalkthroughNew Docker-related infrastructure has been introduced to the Changes
Sequence Diagram(s)sequenceDiagram
participant Developer
participant Docker
participant App
participant Kafka
Developer->>Docker: Build image (Dockerfile)
Docker->>App: Prepare and package Spring Boot app
Docker->>App: Extract layers (dependencies, loader, app code)
Docker->>App: Run app as non-root user
App->>Kafka: Connect and produce/consume messages
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🪧 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: 3
🧹 Nitpick comments (3)
spring-kafka-example/.dockerignore (1)
24-30: Potentially over-aggressive ignore pattern – any Helm charts will be omitted.The pattern
**/chartsexcludes every directory namedcharts, which is fine for most projects but will also drop Helm charts if you ever decide to ship Kubernetes manifests together with the source.
Consider tightening the pattern (/charts/**in the module root, orinfra/charts) or documenting the intention.spring-kafka-example/src/main/resources/application-dev.yml (1)
9-9: Add trailing newline to satisfyyamllint.A missing newline is harmless at runtime but keeps linters and CI green.
- console: "%d{yyyy-MM-dd'T'HH:mm:ss} | ${spring.application.name} | %class{30} | %level | %m%n" +\tconsole: "%d{yyyy-MM-dd'T'HH:mm:ss} | ${spring.application.name} | %class{30} | %level | %m%n" +spring-kafka-example/Dockerfile (1)
8-10: Requires BuildKit – document or enable it.
RUN --mount=type=bind ...only works with BuildKit. Builders using classic Docker engine will fail.Add a comment to the Dockerfile header or CI docs telling users to build with
DOCKER_BUILDKIT=1ordocker buildx build.
📜 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)
🔇 Additional comments (1)
spring-kafka-example/Dockerfile (1)
27-47: Port mismatch vs. non-root user – align with compose change.Expose/entrypoint are fine, but remember to update
EXPOSEto 8080 (or addsetcap) once you address the compose issue – otherwise future newcomers will wonder why 80 is exposed but cannot be used.
| ports: | ||
| - "80:80" | ||
| environment: | ||
| SERVER_PORT: "80" | ||
| SPRING_PROFILES_ACTIVE: "default" |
There was a problem hiding this comment.
Container will fail to start – non-root user cannot bind to port 80.
Dockerfile switches to UID 10001 (non-root) while compose.yaml maps container port 80 and sets SERVER_PORT=80.
Ports < 1024 require the CAP_NET_BIND_SERVICE capability or root. The JVM will throw “Permission denied: bind”.
Quick fixes (pick one):
- - "80:80"
- SERVER_PORT: "80"
+ - "8080:8080"
+ SERVER_PORT: "8080"or
cap_add:
- NET_BIND_SERVICEbut the first option keeps the image simpler.
🤖 Prompt for AI Agents
In spring-kafka-example/compose.yaml around lines 5 to 9, the container tries to
bind to port 80, which requires root privileges or the NET_BIND_SERVICE
capability, but the Dockerfile switches to a non-root user (UID 10001). To fix
this, either change the SERVER_PORT environment variable and port mapping to a
port above 1024 (e.g., 8080) or add the cap_add section with NET_BIND_SERVICE
capability to allow binding to port 80 without root. Choose one of these options
to ensure the container starts successfully.
| SERVER_PORT: "80" | ||
| SPRING_PROFILES_ACTIVE: "default" |
There was a problem hiding this comment.
🛠️ 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 application-dev.yml is picked up automatically.
🤖 Prompt for AI Agents
In spring-kafka-example/compose.yaml at lines 8 to 9, the SPRING_PROFILES_ACTIVE
environment variable is set to "default", but for local development it should be
set to "dev" to automatically pick up the application-dev.yml configuration.
Change the value of SPRING_PROFILES_ACTIVE from "default" to "dev" to activate
the correct Spring profile for local runs.
|
|
||
| application: | ||
| name: spring-kafka-example | ||
| name: spring-kafka-example-prd |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Keep the logical environment suffix in sync with SPRING_PROFILES_ACTIVE.
application.yml now carries the suffix -prd, which is great, but the compose.yaml still activates the default profile (see line 9 there). This means the production naming will be used even when you spin the app locally, which is probably not what you intend.
🤖 Prompt for AI Agents
In spring-kafka-example/src/main/resources/application.yml at line 4, the
environment suffix is set to '-prd' but the compose.yaml file still activates
the 'default' profile. To fix this, update the SPRING_PROFILES_ACTIVE setting in
compose.yaml (around line 9) to match the '-prd' suffix by setting it to 'prd'
so that the profile and environment suffix are consistent and the correct
configuration is used when running the app.
….yml by environment
Summary by CodeRabbit
New Features
.dockerignorefile to optimize Docker builds by excluding unnecessary files.Configuration