Skip to content

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

Closed
igorcampos-dev wants to merge 2 commits intomasterfrom
feature/spring-kafka-example-improvements
Closed

chore(spring-kafka-example): add Docker support and split application…#11
igorcampos-dev wants to merge 2 commits intomasterfrom
feature/spring-kafka-example-improvements

Conversation

@igorcampos-dev
Copy link
Copy Markdown
Owner

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

….yml by environment

Summary by CodeRabbit

  • New Features

    • Added Docker support with a multi-stage Dockerfile and a Docker Compose configuration for containerized deployment.
    • Introduced a .dockerignore file to optimize Docker builds by excluding unnecessary files.
    • Added a development environment configuration file with custom logging and application naming.
  • Configuration

    • Updated the main application configuration to rename the application for the production environment.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jul 20, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

New Docker-related infrastructure has been introduced to the spring-kafka-example project, including a .dockerignore file, a multi-stage Dockerfile, and a Docker Compose configuration. Additionally, separate Spring Boot configuration files for development and production have been added or updated, mainly changing the application name and logging format. The GitHub Actions labeler workflow was updated to use a personal access token.

Changes

File(s) Change Summary
spring-kafka-example/.dockerignore Added file to exclude development, build, and environment-specific artifacts from Docker build context.
spring-kafka-example/Dockerfile Added multi-stage Dockerfile for building, layering, and running the Spring Kafka application as a container.
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 development-specific Spring Boot config with custom app name and logging pattern.
spring-kafka-example/src/main/resources/application.yml Changed spring.application.name from spring-kafka-example to spring-kafka-example-prd.
.github/workflows/label.yml Updated GitHub Actions labeler to use personal access token (PAT) instead of default GitHub token.

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
Loading

Poem

🐇
A Docker hop, a Compose skip,
Spring Boot configs on a new trip.
Dev and prod now know their name,
Logs with patterns, never the same.
With layers built and ports set free,
Kafka and Spring in harmony!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0808582 and 59efa77.

📒 Files selected for processing (1)
  • .github/workflows/label.yml (1 hunks)

🪧 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: 3

🧹 Nitpick comments (3)
spring-kafka-example/.dockerignore (1)

24-30: Potentially over-aggressive ignore pattern – any Helm charts will be omitted.

The pattern **/charts excludes every directory named charts, 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, or infra/charts) or documenting the intention.

spring-kafka-example/src/main/resources/application-dev.yml (1)

9-9: Add trailing newline to satisfy yamllint.

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=1 or docker buildx build.

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

🔇 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 EXPOSE to 8080 (or add setcap) once you address the compose issue – otherwise future newcomers will wonder why 80 is exposed but cannot be used.

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

Choose a reason for hiding this comment

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

⚠️ Potential issue

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_SERVICE

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

Comment on lines +8 to +9
SERVER_PORT: "80"
SPRING_PROFILES_ACTIVE: "default"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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 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
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ 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.

@igorcampos-dev igorcampos-dev deleted the feature/spring-kafka-example-improvements branch July 21, 2025 00:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant