Skip to content
Open
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
10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.git
.github
target/
*.md
.gitignore
.idea/
*.iml
.vscode/
.DS_Store
docker-compose*.yml
37 changes: 37 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Stage 1 - Build
FROM eclipse-temurin:21-jdk-alpine AS build

WORKDIR /app

COPY mvnw .
COPY .mvn .mvn
COPY pom.xml .

RUN chmod +x mvnw && ./mvnw dependency:go-offline -B

COPY src src

RUN ./mvnw clean package -DskipTests -B

# Stage 2 - Runtime
FROM eclipse-temurin:21-jre-alpine AS runtime

LABEL maintainer="felipementel" \
description="CRUD de usuarios em Spring Boot com Ports and Adapters"

RUN addgroup -S appgroup && adduser -S appuser -G appgroup

WORKDIR /app

COPY --from=build /app/target/usuarios-api-java-0.1.0.jar app.jar
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

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

The runtime stage copies a version-pinned JAR name (usuarios-api-java-0.1.0.jar). This will break the Docker build whenever the project version changes or if the artifact name is customized. Consider producing a stable output name during the build (e.g., configure Maven finalName to app) and copy that, or otherwise avoid hard-coding the version in the Dockerfile.

Suggested change
COPY --from=build /app/target/usuarios-api-java-0.1.0.jar app.jar
COPY --from=build /app/target/*.jar app.jar

Copilot uses AI. Check for mistakes.

RUN chown appuser:appgroup app.jar

Comment on lines +26 to +29
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

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

You can avoid the extra layer from RUN chown ... by using COPY --chown=appuser:appgroup --from=build ... app.jar when copying the JAR into the runtime image. This keeps the image slightly smaller and the Dockerfile simpler.

Suggested change
COPY --from=build /app/target/usuarios-api-java-0.1.0.jar app.jar
RUN chown appuser:appgroup app.jar
COPY --chown=appuser:appgroup --from=build /app/target/usuarios-api-java-0.1.0.jar app.jar

Copilot uses AI. Check for mistakes.
USER appuser

EXPOSE 8080

HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/actuator/health || exit 1
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

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

The HEALTHCHECK targets /actuator/health, but this repo currently doesn't include spring-boot-starter-actuator (and the codebase already exposes /health/live and /health/ready). As written, containers will be marked unhealthy due to a 404. Update the HEALTHCHECK to hit an existing endpoint (e.g. /health/ready) or add Actuator and ensure the endpoint is enabled in config.

Suggested change
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/actuator/health || exit 1
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/health/ready || exit 1

Copilot uses AI. Check for mistakes.

ENTRYPOINT ["java", "-jar", "app.jar"]
Loading