Skip to content
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ jobs:
steps:
- uses: actions/labeler@v5
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
repo-token: "${{ secrets.PAT }}"
sync-labels: true
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" ]
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 +5 to +9
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
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.


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


logging:

Expand Down