feat(deploy): Add selective service rebuild and --no-migrate option
- Add support for specifying services to rebuild (e.g., ./deploy.sh traefik) - Add --no-migrate flag to skip migrations for config-only changes - Reduce wait time from 10s to 5s Usage examples: ./deploy.sh # Build all, run migrations ./deploy.sh traefik --no-migrate # Only rebuild traefik, skip migrations ./deploy.sh django nginx # Build django and nginx, run migrations 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
68
deploy.sh
68
deploy.sh
@@ -1,7 +1,12 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# SmoothSchedule Production Deployment Script
|
# SmoothSchedule Production Deployment Script
|
||||||
# Usage: ./deploy.sh [server_user@server_host]
|
# Usage: ./deploy.sh [server_user@server_host] [services...]
|
||||||
# Example: ./deploy.sh poduck@smoothschedule.com
|
# Example: ./deploy.sh poduck@smoothschedule.com # Build all
|
||||||
|
# Example: ./deploy.sh poduck@smoothschedule.com traefik # Build only traefik
|
||||||
|
# Example: ./deploy.sh poduck@smoothschedule.com django nginx # Build django and nginx
|
||||||
|
#
|
||||||
|
# Available services: django, traefik, nginx, postgres, celeryworker, celerybeat, flower, awscli
|
||||||
|
# Use --no-migrate to skip migrations (useful for config-only changes like traefik)
|
||||||
#
|
#
|
||||||
# This script deploys from git repository, not local files.
|
# This script deploys from git repository, not local files.
|
||||||
# Changes must be committed and pushed before deploying.
|
# Changes must be committed and pushed before deploying.
|
||||||
@@ -14,7 +19,23 @@ GREEN='\033[0;32m'
|
|||||||
YELLOW='\033[1;33m'
|
YELLOW='\033[1;33m'
|
||||||
NC='\033[0m' # No Color
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
SERVER=${1:-"poduck@smoothschedule.com"}
|
# Parse arguments
|
||||||
|
SERVER=""
|
||||||
|
SERVICES=""
|
||||||
|
SKIP_MIGRATE=false
|
||||||
|
|
||||||
|
for arg in "$@"; do
|
||||||
|
if [[ "$arg" == "--no-migrate" ]]; then
|
||||||
|
SKIP_MIGRATE=true
|
||||||
|
elif [[ -z "$SERVER" ]]; then
|
||||||
|
SERVER="$arg"
|
||||||
|
else
|
||||||
|
SERVICES="$SERVICES $arg"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
SERVER=${SERVER:-"poduck@smoothschedule.com"}
|
||||||
|
SERVICES=$(echo "$SERVICES" | xargs) # Trim whitespace
|
||||||
REPO_URL="https://git.talova.net/poduck/smoothschedule.git"
|
REPO_URL="https://git.talova.net/poduck/smoothschedule.git"
|
||||||
REMOTE_DIR="/home/poduck/smoothschedule"
|
REMOTE_DIR="/home/poduck/smoothschedule"
|
||||||
|
|
||||||
@@ -22,6 +43,14 @@ echo -e "${GREEN}==================================="
|
|||||||
echo "SmoothSchedule Deployment"
|
echo "SmoothSchedule Deployment"
|
||||||
echo "===================================${NC}"
|
echo "===================================${NC}"
|
||||||
echo "Target server: $SERVER"
|
echo "Target server: $SERVER"
|
||||||
|
if [[ -n "$SERVICES" ]]; then
|
||||||
|
echo "Services to rebuild: $SERVICES"
|
||||||
|
else
|
||||||
|
echo "Services to rebuild: ALL"
|
||||||
|
fi
|
||||||
|
if [[ "$SKIP_MIGRATE" == "true" ]]; then
|
||||||
|
echo "Migrations: SKIPPED"
|
||||||
|
fi
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# Function to print status
|
# Function to print status
|
||||||
@@ -128,24 +157,33 @@ fi
|
|||||||
echo ">>> Current commit:"
|
echo ">>> Current commit:"
|
||||||
git log -1 --oneline
|
git log -1 --oneline
|
||||||
|
|
||||||
echo ">>> Building Docker images..."
|
|
||||||
cd smoothschedule
|
cd smoothschedule
|
||||||
docker compose -f docker-compose.production.yml build
|
|
||||||
|
# Build images (all or specific services)
|
||||||
|
if [[ -n "$SERVICES" ]]; then
|
||||||
|
echo ">>> Building Docker images: $SERVICES..."
|
||||||
|
docker compose -f docker-compose.production.yml build $SERVICES
|
||||||
|
else
|
||||||
|
echo ">>> Building all Docker images..."
|
||||||
|
docker compose -f docker-compose.production.yml build
|
||||||
|
fi
|
||||||
|
|
||||||
echo ">>> Starting containers..."
|
echo ">>> Starting containers..."
|
||||||
docker compose -f docker-compose.production.yml up -d
|
docker compose -f docker-compose.production.yml up -d
|
||||||
|
|
||||||
echo ">>> Waiting for containers to start..."
|
echo ">>> Waiting for containers to start..."
|
||||||
sleep 10
|
sleep 5
|
||||||
|
|
||||||
echo ">>> Running database migrations..."
|
# Run migrations unless skipped
|
||||||
docker compose -f docker-compose.production.yml exec -T django sh -c 'export DATABASE_URL=postgres://\${POSTGRES_USER}:\${POSTGRES_PASSWORD}@\${POSTGRES_HOST}:\${POSTGRES_PORT}/\${POSTGRES_DB} && python manage.py migrate'
|
if [[ "$SKIP_MIGRATE" != "true" ]]; then
|
||||||
|
echo ">>> Running database migrations..."
|
||||||
|
docker compose -f docker-compose.production.yml exec -T django sh -c 'export DATABASE_URL=postgres://\${POSTGRES_USER}:\${POSTGRES_PASSWORD}@\${POSTGRES_HOST}:\${POSTGRES_PORT}/\${POSTGRES_DB} && python manage.py migrate'
|
||||||
|
|
||||||
echo ">>> Collecting static files..."
|
echo ">>> Collecting static files..."
|
||||||
docker compose -f docker-compose.production.yml exec -T django sh -c 'export DATABASE_URL=postgres://\${POSTGRES_USER}:\${POSTGRES_PASSWORD}@\${POSTGRES_HOST}:\${POSTGRES_PORT}/\${POSTGRES_DB} && python manage.py collectstatic --noinput'
|
docker compose -f docker-compose.production.yml exec -T django sh -c 'export DATABASE_URL=postgres://\${POSTGRES_USER}:\${POSTGRES_PASSWORD}@\${POSTGRES_HOST}:\${POSTGRES_PORT}/\${POSTGRES_DB} && python manage.py collectstatic --noinput'
|
||||||
|
|
||||||
echo ">>> Seeding/updating platform plugins for all tenants..."
|
echo ">>> Seeding/updating platform plugins for all tenants..."
|
||||||
docker compose -f docker-compose.production.yml exec -T django python -c "
|
docker compose -f docker-compose.production.yml exec -T django python -c "
|
||||||
from django_tenants.utils import get_tenant_model
|
from django_tenants.utils import get_tenant_model
|
||||||
from django.core.management import call_command
|
from django.core.management import call_command
|
||||||
Tenant = get_tenant_model()
|
Tenant = get_tenant_model()
|
||||||
@@ -154,9 +192,9 @@ for tenant in Tenant.objects.exclude(schema_name='public'):
|
|||||||
call_command('tenant_command', 'seed_platform_plugins', schema=tenant.schema_name, verbosity=0)
|
call_command('tenant_command', 'seed_platform_plugins', schema=tenant.schema_name, verbosity=0)
|
||||||
print(' Done!')
|
print(' Done!')
|
||||||
"
|
"
|
||||||
|
else
|
||||||
echo ">>> Checking container status..."
|
echo ">>> Skipping migrations (--no-migrate flag used)"
|
||||||
docker compose -f docker-compose.production.yml ps
|
fi
|
||||||
|
|
||||||
echo ">>> Deployment complete!"
|
echo ">>> Deployment complete!"
|
||||||
ENDSSH
|
ENDSSH
|
||||||
|
|||||||
Reference in New Issue
Block a user