Skip to content

chore(spring-kafka-example): add Docker support and split application…#13

Merged
igorcampos-dev merged 1 commit intomasterfrom
feature/spring-kafka-example-improvements
Jul 21, 2025
Merged

chore(spring-kafka-example): add Docker support and split application…#13
igorcampos-dev merged 1 commit intomasterfrom
feature/spring-kafka-example-improvements

Conversation

@igorcampos-dev
Copy link
Copy Markdown
Owner

@igorcampos-dev igorcampos-dev commented Jul 21, 2025

….yml by environment

Summary by CodeRabbit

  • New Features

    • Added Docker support with a multi-stage Dockerfile for efficient building and running of the Spring Kafka example application.
    • Introduced a Docker Compose configuration for simplified container orchestration.
    • Added environment-specific configuration files, including a development YAML file with customized logging patterns.
  • Chores

    • Added a .dockerignore file to optimize Docker builds by excluding unnecessary files.
  • Style

    • Updated the application name in the main configuration to reflect the production environment.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jul 21, 2025

Walkthrough

Several foundational files were added to the spring-kafka-example project, including a .dockerignore, a multi-stage Dockerfile, a compose.yaml for Docker Compose, and an environment-specific application-dev.yml. The main application.yml was also updated to reflect a new application name for the production profile.

Changes

File(s) Change Summary
spring-kafka-example/.dockerignore Added to exclude unnecessary files and directories from Docker build context.
spring-kafka-example/Dockerfile Added a multi-stage Dockerfile for building, layering, and running the Spring Kafka app using Eclipse Temurin JDK/JRE.
spring-kafka-example/compose.yaml Added Docker Compose file defining a server service with environment variables and port mapping.
spring-kafka-example/src/main/resources/application-dev.yml Added a development-specific YAML config with custom logging and a dev application name.
spring-kafka-example/src/main/resources/application.yml Updated the spring.application.name to spring-kafka-example-prd.

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
Loading

Poem

🐇
In Docker’s warren, files now hide,
Compose and configs side by side.
A dev log’s pattern, crisp and neat,
New names for prod, a tidy feat!
With layers stacked and ports set free,
Spring Kafka hops—deploy with glee!


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.yml is loaded for every profile unless overridden. Encoding -prd directly in spring.application.name forces 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 in application-prd.yml, mirroring what you did for application-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"\n
spring-kafka-example/.dockerignore (1)

27-29: Re-evaluate ignoring Dockerfile / compose descriptors
The patterns **/Dockerfile* and **/compose.y*ml exclude these files from the build context.
While the Docker CLI still sends the primary Dockerfile (specified via -f or 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
Prepending build/… works, but the leading segment is redundant because the working directory of the extract stage 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

📥 Commits

Reviewing files that changed from the base of the PR and between 143de6b and 0808582.

📒 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)

Comment on lines +6 to +9
- "80:80"
environment:
SERVER_PORT: "80"
SPRING_PROFILES_ACTIVE: "default"
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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:

  1. Expose/bind an unprivileged port (e.g. 8080) inside the container and keep host port 80, or
  2. 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.

Suggested change
- "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.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using port 80 in docker does not cause issues

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Comment thread spring-kafka-example/Dockerfile
@igorcampos-dev igorcampos-dev merged commit 99a5ea1 into master Jul 21, 2025
5 of 10 checks passed
@igorcampos-dev igorcampos-dev deleted the feature/spring-kafka-example-improvements branch July 21, 2025 00:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant