Skip to content

Refactor deployment script to prevent unnecessary Jetty downtime#2066

Merged
jo-elimu merged 1 commit intoelimu-ai:mainfrom
ideal3147:#2040-Restart-Jetty-after-.war-download-completes
Mar 16, 2025
Merged

Refactor deployment script to prevent unnecessary Jetty downtime#2066
jo-elimu merged 1 commit intoelimu-ai:mainfrom
ideal3147:#2040-Restart-Jetty-after-.war-download-completes

Conversation

@ideal3147
Copy link
Copy Markdown
Contributor

Issue Number

Purpose

  • Prevents Jetty from being stopped before successfully downloading the WAR file.
  • Ensures a more reliable deployment process by handling download failures properly.
  • Improves script readability and maintainability.

Technical Details

  • The WAR file is now downloaded to a temporary directory (/tmp) instead of the webapps/ directory.
  • Jetty is only stopped after confirming that the WAR file has been successfully downloaded.
  • Error handling is added to prevent unnecessary Jetty downtime in case of download failure.
  • Comments in the script were updated to English for better readability.

Testing Instructions

  • Run the script with a valid version argument:
./deploy.sh 1.2.3
  • Check that the WAR file is downloaded to /tmp first before Jetty is stopped.
  • Verify that Jetty stops only after a successful download.
  • Ensure that Jetty restarts successfully after the deployment.
  • Test the script with an invalid version to confirm that Jetty is not stopped if the download fails.

@ideal3147 ideal3147 requested a review from a team as a code owner March 15, 2025 05:48
@ideal3147 ideal3147 requested review from alexander-kuruvilla, eymaal and jpatel3 and removed request for a team March 15, 2025 05:48
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 15, 2025

Walkthrough

The deployment script has been updated to improve robustness during the web application deployment process. The changes introduce enhanced error handling using set -e, a check to ensure the VERSION variable is provided, and a refined process for downloading the WAR file. The script downloads the WAR file to a temporary location with retry and timeout settings and then moves it to the final target location, updating deployment logs and process flow accordingly.

Changes

File(s) Change Summary
src/main/config/centos-stream-9/.../deploy-webapp.sh - Added set -e for immediate exit on error
- Introduced a check for the VERSION variable with error messaging
- Constructs WAR_FILE_URL variable and downloads using wget with retries and timeouts
- Moves the downloaded WAR file to the target location
- Added echo statements to indicate the progress of stopping, deploying, and restarting the service

Sequence Diagram(s)

sequenceDiagram
    participant Script as Deployment Script
    participant Repository as External Repository
    participant Server as Jetty Server

    Script->>Script: Check for VERSION variable
    alt VERSION provided
        Script->>Repository: Download WAR file with wget (with retries & timeout)
        alt Download successful
            Script->>Script: Move WAR file from temporary to target location
            Script->>Server: Stop Jetty
            Script->>Server: Deploy new WAR file
            Script->>Server: Start Jetty
            Script->>Script: Log success message
        else Download failed
            Script->>Script: Print error and exit
        end
    else VERSION missing
        Script->>Script: Print error message and exit
    end
Loading

Possibly related PRs

  • Add deployment script #1793: Introduced the initial version of the deployment script, which is now being further enhanced with improved error handling and control flow.

Suggested reviewers

  • jpatel3
  • venkatesh2k3
  • nya-elimu

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.
✨ Finishing Touches
  • 📝 Generate Docstrings

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

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 15.19%. Comparing base (71b84dd) to head (6151495).
Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #2066   +/-   ##
=========================================
  Coverage     15.19%   15.19%           
  Complexity      404      404           
=========================================
  Files           243      243           
  Lines          6672     6672           
  Branches        747      747           
=========================================
  Hits           1014     1014           
  Misses         5608     5608           
  Partials         50       50           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@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 (3)
src/main/config/centos-stream-9/~/.elimu-ai/deploy-webapp.sh (3)

28-29: Conditional shutdown of Jetty
Stopping Jetty only after a successful WAR file download is a significant improvement. However, consider implementing a trap or further error handling in the subsequent deployment steps to ensure that, if any later command fails, Jetty can be restarted to avoid prolonged downtime.


31-32: Deployment step for moving the WAR file
The mv -f command clearly moves the downloaded WAR file to its target location. Note that if this step fails after Jetty has been stopped, the system may remain in an unstable state. You might want to add error handling (or a recovery trap) to restart Jetty if the move fails.


34-35: Restarting Jetty and service confirmation
The script properly restarts Jetty after deploying the new WAR file. As an enhancement, you could add a service status check post-restart to verify that Jetty has started correctly.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ed7153a and 6151495.

📒 Files selected for processing (1)
  • src/main/config/centos-stream-9/~/.elimu-ai/deploy-webapp.sh (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: build (macos-latest, 17)
  • GitHub Check: build (windows-latest, 21)
  • GitHub Check: build (windows-latest, 17)
  • GitHub Check: build (ubuntu-latest, 17)
  • GitHub Check: build (ubuntu-latest, 21)
  • GitHub Check: build (macos-latest, 21)
  • GitHub Check: test_rest_ENG
  • GitHub Check: test_ui_ENG
🔇 Additional comments (4)
src/main/config/centos-stream-9/~/.elimu-ai/deploy-webapp.sh (4)

3-4: Enhancement with set -e
The addition of set -e ensures the script will immediately exit on any command failure, which is critical for a robust deployment process.


7-10: Validation for required VERSION parameter
The check for an empty VERSION variable is well implemented, ensuring that the script only proceeds if a valid version is provided. This prevents potential downstream errors.


14-16: Clear variable definitions for file paths and URL
Defining WAR_FILE_URL, TMP_WAR_FILE, and TARGET_WAR_FILE in this segment improves maintainability and readability. It makes future changes easier if the download location or target directory ever need updates.


21-24: Robust error handling during WAR file download
The use of wget with retries and timeout settings along with error checking ensures that the script exits before taking further action if the download fails. This avoids stopping Jetty unnecessarily.

Copy link
Copy Markdown
Member

@jo-elimu jo-elimu left a comment

Choose a reason for hiding this comment

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

@ideal3147 Tested the changes, and it worked perfectly 👍

# ~/.elimu-ai/deploy-webapp.sh 2.5.41
VERSION: 2.5.41
Downloading WAR file from https://jitpack.io/com/github/elimu-ai/webapp/webapp-2.5.41/webapp-webapp-2.5.41.war
--2025-03-16 06:37:03--  https://jitpack.io/com/github/elimu-ai/webapp/webapp-2.5.41/webapp-webapp-2.5.41.war
Resolving jitpack.io (jitpack.io)... 2606:4700:20::ac43:4881, 2606:4700:20::681a:963, 2606:4700:20::681a:863, ...
Connecting to jitpack.io (jitpack.io)|2606:4700:20::ac43:4881|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 88340052 (84M) [application/zip]
Saving to: ‘/tmp/webapp-2.5.41.war’

/tmp/webapp-2.5.41.war                 100%[============================================================================>]  84.25M  31.4MB/s    in 2.7s

Last-modified header invalid -- time-stamp ignored.
2025-03-16 06:37:07 (31.4 MB/s) - ‘/tmp/webapp-2.5.41.war’ saved [88340052/88340052]

Download completed successfully.
Stopping Jetty...
Deploying new WAR file...
Starting Jetty...
Deployment completed successfully.

@jo-elimu jo-elimu merged commit e7df071 into elimu-ai:main Mar 16, 2025
10 of 12 checks passed
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.

Restart Jetty after .war download completes

2 participants