- Implement setuptools-scm for dynamic version management from git tags - Refactor CI/CD into separate build and deploy jobs with artifact sharing - Add versioned releases with timestamp-based deployment directories - Implement health checks and automatic rollback on deployment failure - Extract deployment logic into reusable shell scripts - Add Docker layer caching to speed up builds - Include version info in Django context and build args
44 lines
No EOL
1.3 KiB
Bash
44 lines
No EOL
1.3 KiB
Bash
#!/bin/bash
|
||
set -euo pipefail
|
||
|
||
# Prepare deployment by stopping containers
|
||
# Usage: ./prepare-deployment.sh REPO_PROJECT_PATH IS_PROD CURRENT_LINK_PATH
|
||
|
||
if [ $# -ne 3 ]; then
|
||
echo "Error: Invalid number of arguments"
|
||
echo "Usage: $0 REPO_PROJECT_PATH IS_PROD CURRENT_LINK_PATH"
|
||
exit 1
|
||
fi
|
||
|
||
REPO_PROJECT_PATH="$1"
|
||
IS_PROD="$2"
|
||
CURRENT_LINK_PATH="$3"
|
||
|
||
# Ensure base directory exists
|
||
if [ ! -d "$REPO_PROJECT_PATH" ]; then
|
||
echo "⚠️ Directory $REPO_PROJECT_PATH does not exist, creating it..."
|
||
mkdir -p "$REPO_PROJECT_PATH"
|
||
fi
|
||
|
||
# If current symlink exists, stop containers in that directory
|
||
if [ -L "$CURRENT_LINK_PATH" ] && [ -d "$CURRENT_LINK_PATH" ]; then
|
||
echo "🛑 Stopping containers in current deployment..."
|
||
cd "$CURRENT_LINK_PATH"
|
||
|
||
# Stop containers
|
||
if [ -f "docker-compose_web.yml" ]; then
|
||
docker compose -f docker-compose_web.yml down || true
|
||
fi
|
||
|
||
if [ "$IS_PROD" = "false" ] && [ -f "docker-compose_staging.yml" ]; then
|
||
docker compose -f docker-compose_staging.yml down || true
|
||
fi
|
||
|
||
if [ -f "docker-compose_core.yml" ]; then
|
||
docker compose -f docker-compose_core.yml down || true
|
||
fi
|
||
|
||
echo "✅ Containers stopped"
|
||
else
|
||
echo "ℹ️ No current deployment found (symlink doesn't exist or point to valid directory)"
|
||
fi |