Skip to content

Conversation

@cfsmp3
Copy link
Contributor

@cfsmp3 cfsmp3 commented Dec 23, 2025

Summary

Adds deployment scripts that implement a safe deployment flow with automatic rollback on failure:

  • pre_deploy.sh - Validates environment, saves state for rollback
  • deploy.sh - Pulls code, installs deps, runs migrations, reloads service
  • post_deploy.sh - Health check with retries and fallback
  • rollback.sh - Restores previous commit/migration on failure

Deployment Flow

pre_deploy.sh  →  deploy.sh  →  post_deploy.sh
     ↓               ↓              ↓
 Validate        Update         Health check
 Save state      Deploy         Verify
     ↓               ↓              ↓
                                SUCCESS/FAILURE
                                    ↓
                              rollback.sh (on failure)

Features

  • Concurrent deployment protection: Lock file prevents overlapping deployments
  • Pre-flight validation: Config, database, disk space checks before deploying
  • State preservation: Saves commit and migration version for rollback
  • Health verification: Checks /health endpoint with 6 retries
  • Graceful fallback: Falls back to root endpoint if /health doesn't exist
  • Automatic rollback: Restores code, downgrades migrations, restarts service
  • Comprehensive logging: Clear status messages for debugging

Standalone Nature

These scripts can be merged independently:

Usage

Manual Testing

export INSTALL_FOLDER="/var/www/sample-platform"
export SAMPLE_REPOSITORY="/repository"

cd $INSTALL_FOLDER
sudo bash install/deploy/pre_deploy.sh && \
sudo bash install/deploy/deploy.sh && \
sudo bash install/deploy/post_deploy.sh || \
sudo bash install/deploy/rollback.sh

Environment Variables

Variable Default Description
INSTALL_FOLDER /var/www/sample-platform App directory
SAMPLE_REPOSITORY /repository Test data repo
DEPLOY_BRANCH master Branch to deploy
MAX_RETRIES 6 Health check retries
RETRY_DELAY 5 Seconds between retries

Test Plan

  • Verify scripts are executable
  • Test pre_deploy.sh validates config correctly
  • Test deploy.sh updates code and runs migrations
  • Test post_deploy.sh health check with retries
  • Test rollback.sh restores previous state
  • Verify CI passes (no Python code, just shell scripts)

Related PRs

🤖 Generated with Claude Code

@codecov
Copy link

codecov bot commented Dec 23, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.88%. Comparing base (53b3d7f) to head (9fb25bd).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #949   +/-   ##
=======================================
  Coverage   86.88%   86.88%           
=======================================
  Files          35       35           
  Lines        3759     3759           
  Branches      767      767           
=======================================
  Hits         3266     3266           
  Misses        355      355           
  Partials      138      138           
Flag Coverage Δ
unittests 86.88% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@cfsmp3 cfsmp3 force-pushed the feat/safe-deployment-scripts branch from 9fb25bd to 8397a14 Compare December 23, 2025 22:40
Add deployment scripts that implement a safe deployment flow:

- pre_deploy.sh: Validates environment, saves state for rollback
- deploy.sh: Pulls code, installs deps, runs migrations, reloads service
- post_deploy.sh: Health check with retries and fallback
- rollback.sh: Restores previous commit/migration on failure

Features:
- Concurrent deployment protection (lock file)
- Database connection validation before deploy
- Commit and migration version saved for rollback
- Health check with 6 retries, 5s delay
- Fallback to root endpoint if /health doesn't exist
- Automatic database migration downgrade on rollback
- Comprehensive logging and error messages

These scripts are designed to be used with GitHub Actions but can
also be run manually for testing or emergency deployments.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@canihavesomecoffee canihavesomecoffee force-pushed the feat/safe-deployment-scripts branch from 8397a14 to 5299632 Compare December 24, 2025 10:08
@sonarqubecloud
Copy link

@canihavesomecoffee canihavesomecoffee merged commit 09dc049 into master Dec 24, 2025
6 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.

3 participants