Skip to content

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

Suraj-kumar00
Copy link

@Suraj-kumar00 Suraj-kumar00 commented Apr 23, 2025

πŸ“‹ Description

JIRA ID:

This PR introduces Docker support for the Admin API application, enabling consistent and containerized builds.
This PR resolves issue PSMRI/AMRIT#59


βœ… Type of Change

  • 🐞 Bug fix (non-breaking change which resolves an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • πŸ”₯ Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • πŸ›  Refactor (change that is neither a fix nor a new feature)
  • βš™οΈ Config change (configuration file or build script updates)
  • πŸ“š Documentation (updates to docs or readme)
  • πŸ§ͺ Tests (adding new or updating existing tests)
  • 🎨 UI/UX (changes that affect the user interface)
  • πŸš€ Performance (improves performance)
  • 🧹 Chore (miscellaneous changes that don't modify src or test files)

ℹ️ Additional Information

image
image

Summary by CodeRabbit

  • Chores
    • Introduced a new multi-stage Dockerfile to streamline building and running the Java web application with Maven and Tomcat.
    • Improved container efficiency by removing default Tomcat applications and deploying the built application as the root web app.

Copy link

coderabbitai bot commented Apr 23, 2025

Walkthrough

A new multi-stage Dockerfile has been added to build and deploy a Java web application. The first stage uses a Maven image with OpenJDK 17 to compile the application and package it as a WAR file, skipping tests and some plugins for efficiency. The second stage uses a Tomcat 9.0 image with OpenJDK 17, removes default web applications, and deploys the built WAR file as the root web application. The container exposes port 8080 and starts Tomcat upon launch.

Changes

File(s) Change Summary
Dockerfile Added a multi-stage Dockerfile for building with Maven and deploying to Tomcat using OpenJDK 17.

Poem

In a Docker warren, neat and bright,
Java code takes flight at night.
Maven builds with nimble paws,
Tomcat welcomes with open jaws.
Port 8080, ready to runβ€”
Hop in, web app, your journey’s begun!
πŸ‡βœ¨


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.

❀️ Share
πŸͺ§ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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

@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: 0

🧹 Nitpick comments (4)
Dockerfile (4)

1-7: Optimize build layers & ensure tests run in CI.

  • Use a .dockerignore (e.g., to exclude target/, .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.
πŸ“œ Review details

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

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 0bf8de9 and 26b46bf.

πŸ“’ Files selected for processing (1)
  • Dockerfile (1 hunks)

@drtechie
Copy link
Member

Looks fine mostly.
We haven't had tomcat in the stack before.

Are you able to hit the API and see logs?
Does /swagger-ui.html work?

WORKDIR /app
COPY . .
# Skip tests for faster build and skip git plugin issues
RUN mvn clean package -DskipTests -Dgit.skip=true
Copy link
Member

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

Copy link
Author

Choose a reason for hiding this comment

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

noted.

@Suraj-kumar00
Copy link
Author

Looks fine mostly. We haven't had tomcat in the stack before.

Are you able to hit the API and see logs? Does /swagger-ui.html work?

Oh so, I mean I have researched about it and found .war files are designed to be deployed on a servlet container like Tomcat, Jetty, or WildFly.

So if we don't want the tomcat stack. we can do this:

We can build a .jar instead of .war
In pom.xml, change:

<packaging>jar</packaging>

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.

2 participants