-
Notifications
You must be signed in to change notification settings - Fork 31
Dockerize Admin API Application #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughA multi-stage Dockerfile was added to build and run a Java application using Maven and Eclipse Temurin JDK images. The Changes
Sequence Diagram(s)sequenceDiagram
participant Developer
participant Docker Build (Maven)
participant Docker Runtime (JRE)
participant Java App
Developer->>Docker Build (Maven): Build Docker image
Docker Build (Maven)->>Docker Build (Maven): Copy source, run Maven package
Docker Build (Maven)->>Docker Runtime (JRE): Copy WAR file
Docker Runtime (JRE)->>Java App: Start app with java -jar app.war
Poem
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. πͺ§ TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
π§Ή Nitpick comments (4)
Dockerfile (4)
1-7
: Optimize build layers & ensure tests run in CI.
- Use a
.dockerignore
(e.g., to excludetarget/
,.git/
, IDE files) to minimize the build context.- Separate dependency download into its own layer to leverage caching:
WORKDIR /app -COPY . . -RUN mvn clean package -DskipTests -Dgit.skip=true +COPY pom.xml mvnw* ./ +RUN mvn dependency:go-offline -B +COPY src ./src +RUN mvn clean package -DskipTests -Dgit.skip=true
- Note: skipping tests (
-DskipTests
) speeds up image builds but may mask regressions. Ensure your CI pipeline runs the full test suite.
12-13
: Review removal of default Tomcat applications.Deleting everything under
webapps/*
also removes management and monitoring apps (e.g.,manager
,host-manager
). If you only intend to clear the ROOT context, narrow the command:-RUN rm -rf /usr/local/tomcat/webapps/* +RUN rm -rf /usr/local/tomcat/webapps/ROOT
16-16
: Avoid hardcoding the WAR filename & enhance flexibility.Locking to
adminapi-v3.0.0.war
will break on version bumps. Switch to a wildcard or ARG:- COPY --from=build /app/target/adminapi-v3.0.0.war /usr/local/tomcat/webapps/ROOT.war + ARG WAR_FILE=adminapi-*.war + COPY --from=build /app/target/${WAR_FILE} /usr/local/tomcat/webapps/ROOT.war
18-21
: Enhance container security & observability.
- Run Tomcat as a non-root user (e.g.,
USER tomcat
) to reduce attack surface.- Add a
HEALTHCHECK
so orchestrators can detect unhealthy instances:HEALTHCHECK --interval=30s --timeout=5s \ CMD curl -f http://localhost:8080/ || exit 1
- Optionally declare
VOLUME /usr/local/tomcat/logs
to persist logs outside the container.
Looks fine mostly. Are you able to hit the API and see logs? |
Dockerfile
Outdated
WORKDIR /app | ||
COPY . . | ||
# Skip tests for faster build and skip git plugin issues | ||
RUN mvn clean package -DskipTests -Dgit.skip=true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please package this for CI profile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
noted.
Oh so, I mean I have researched about it and found So if we don't want the tomcat stack. we can do this: We can build a <packaging>jar</packaging> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
β»οΈ Duplicate comments (1)
Dockerfile (1)
9-10
: Ensure CI Maven profile is used
As previously requested, consider defining a dedicatedci
profile inpom.xml
or adding-Pci
to yourmvn
invocation to separate Docker-specific settings from CI builds.
π§Ή Nitpick comments (5)
Dockerfile (5)
1-3
: Optimize dependency caching by splitting COPY steps
To leverage Docker layer caching, copy only thepom.xml
first and run dependency resolution before copying the full source. This avoids redownloading all dependencies on every code change.-FROM maven:3.9.6-eclipse-temurin-17 AS build +FROM maven:3.9.6-eclipse-temurin-17 AS build WORKDIR /app -COPY . . +COPY pom.xml ./ +RUN --mount=type=cache,target=/root/.m2 mvn dependency:go-offline -DskipTests +COPY . .
4-7
: Add a .dockerignore to reduce build context
By introducing a.dockerignore
(excludingtarget/
,.git/
, IDE files, etc.), you can dramatically shrink the build context and speed up Docker builds.
8-11
: Require BuildKit for cache mounts
The--mount=type=cache
syntax relies on Docker BuildKit. Please document (e.g.,export DOCKER_BUILDKIT=1
) in your README or CI config to avoid unexplained build failures in non-BuildKit environments.
12-14
: Consider using a slimmer base image
You can further reduce runtime image size by switching to a distroless or Alpine-based JRE, such asgcr.io/distroless/java17-debian11
or similar minimal images.
20-22
: Enhance container health and operation
Consider adding:
- A
HEALTHCHECK
instruction (e.g.,curl --fail http://localhost:8080/actuator/health || exit 1
).- Using
CMD
instead ofENTRYPOINT
if you need to override at runtime.- Running the process as a non-root user for better security.
π Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
β Files ignored due to path filters (2)
logs/admin-api.log.json.2025-05-05.gz
is excluded by!**/*.gz
logs/admin-api.log.json.2025-05-06.gz
is excluded by!**/*.gz
π Files selected for processing (4)
Dockerfile
(1 hunks)pom.xml
(1 hunks)src/main/environment/admin_ci.properties
(1 hunks)src/main/environment/admin_docker.properties
(1 hunks)
β Files skipped from review due to trivial changes (3)
- pom.xml
- src/main/environment/admin_ci.properties
- src/main/environment/admin_docker.properties
π Additional comments (1)
Dockerfile (1)
15-19
: Verify executable WAR packaging and specify artifact name
Runningjava -jar app.war
only works if the WAR is built as an executable (embedded servlet) via the Spring Boot plugin. Confirm yourpom.xml
packaging (jar
vswar
) and plugin settings. Also avoid wildcards by copying the explicit filename:COPY --from=build /app/target/${project.artifactId}-${project.version}.war app.war
|
π Description
JIRA ID:
This PR introduces
Docker
support for theAdmin API
application, enabling consistent and containerized builds.This PR resolves issue PSMRI/AMRIT#59
β Type of Change
βΉοΈ Additional Information
Summary by CodeRabbit
New Features
Chores
Style