Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions spring-kafka-example/.dockerignore
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*
47 changes: 47 additions & 0 deletions spring-kafka-example/Dockerfile
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" ]
Comment thread
igorcampos-dev marked this conversation as resolved.
10 changes: 10 additions & 0 deletions spring-kafka-example/compose.yaml
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 +6 to +9
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.


9 changes: 9 additions & 0 deletions spring-kafka-example/src/main/resources/application-dev.yml
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"
2 changes: 1 addition & 1 deletion spring-kafka-example/src/main/resources/application.yml
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

logging:

Expand Down