Skip to content

Post-Deployment Scripts with quant-entrypoint.d

Quant Cloud provides a powerful mechanism for running custom scripts automatically after your container starts using the /quant-entrypoint.d/ directory. This allows you to execute initialization tasks, database migrations, cache warming, or any other post-deployment operations.

When your container starts, Quant Cloud automatically detects and executes all shell scripts located in the /quant-entrypoint.d/ directory:

  • Location: /quant-entrypoint.d/*.sh
  • Execution Order: Scripts are executed in alphabetical order
  • Timing: Runs after container start but before your main application process begins
  • Automatic Detection: No configuration needed - just add your scripts to the directory

Database Migrations Run database schema updates or data migrations automatically on deployment:

/quant-entrypoint.d/10-migrate-database.sh
#!/bin/bash
echo "Running database migrations..."
php artisan migrate --force

Cache Warming Pre-populate caches to improve initial response times:

/quant-entrypoint.d/20-warm-cache.sh
#!/bin/bash
echo "Warming application cache..."
php artisan cache:warm

Configuration Generation Generate runtime configuration files based on environment variables:

/quant-entrypoint.d/05-generate-config.sh
#!/bin/bash
echo "Generating application configuration..."
envsubst < /app/config.template > /app/config.yml

Asset Compilation Build or optimize assets if not done during image build:

/quant-entrypoint.d/15-compile-assets.sh
#!/bin/bash
echo "Compiling frontend assets..."
npm run build:production

Create shell scripts in your application’s /quant-entrypoint.d/ directory within your Docker image:

# Dockerfile
FROM php:8.2-fpm
# Create the entrypoint directory
RUN mkdir -p /quant-entrypoint.d
# Copy your post-deployment scripts
COPY deploy-scripts/*.sh /quant-entrypoint.d/
# Make scripts executable
RUN chmod +x /quant-entrypoint.d/*.sh
# Rest of your Dockerfile...

Use numeric prefixes to control execution order:

/quant-entrypoint.d/
├── 05-check-dependencies.sh
├── 10-run-migrations.sh
├── 20-warm-cache.sh
├── 30-register-services.sh
└── 99-cleanup.sh

Scripts are executed in alphabetical order, so 05-check-dependencies.sh runs before 10-run-migrations.sh, etc.

All scripts must:

  • Have a .sh extension
  • Be executable (chmod +x)
  • Use proper shebang (#!/bin/bash or #!/bin/sh)
  • Handle errors appropriately

Keep Scripts Idempotent Scripts should be safe to run multiple times without causing issues:

#!/bin/bash
# Check if migration is needed before running
if [ ! -f /app/.migrated ]; then
php artisan migrate --force
touch /app/.migrated
fi

Add Logging Include clear logging to help with debugging:

#!/bin/bash
echo "[$(date)] Starting database migration..."
php artisan migrate --force
echo "[$(date)] Migration completed successfully"

Handle Failures Gracefully Decide whether failures should be fatal or just warnings:

#!/bin/bash
# Continue even if cache warming fails
if ! php artisan cache:warm; then
echo "Warning: Cache warming failed, continuing anyway..."
fi

Use Environment Variables Leverage environment variables for configuration:

#!/bin/bash
if [ "$RUN_MIGRATIONS" = "true" ]; then
echo "Running migrations..."
php artisan migrate --force
else
echo "Skipping migrations (RUN_MIGRATIONS not set)"
fi

Post-deployment script output is captured in your container logs. You can view the execution results:

  1. Navigate to your environment in the Quant Cloud dashboard
  2. Go to the Logs tab
  3. Filter for startup logs to see script output
  4. Look for your script’s echo statements and any errors

Example: Complete Laravel Migration Script

Section titled “Example: Complete Laravel Migration Script”
/quant-entrypoint.d/10-laravel-setup.sh
#!/bin/bash
set -e # Exit on error
echo "[SETUP] Starting Laravel post-deployment tasks..."
# Wait for database to be ready
echo "[SETUP] Checking database connectivity..."
php artisan db:ping --wait=30
# Run database migrations
echo "[SETUP] Running database migrations..."
php artisan migrate --force --no-interaction
# Clear and rebuild cache
echo "[SETUP] Rebuilding application cache..."
php artisan config:cache
php artisan route:cache
php artisan view:cache
# Run any pending queue jobs (if applicable)
if [ "$PROCESS_QUEUED_JOBS" = "true" ]; then
echo "[SETUP] Processing queued jobs..."
php artisan queue:work --stop-when-empty
fi
echo "[SETUP] Post-deployment setup completed successfully"

Scripts Not Executing

  • Verify scripts are in /quant-entrypoint.d/ (not a subdirectory)
  • Ensure scripts have .sh extension
  • Check that scripts are executable (chmod +x)
  • Confirm proper shebang line is present

Container Fails to Start

  • Check logs for script error messages
  • Test scripts locally before deployment
  • Add set -x to scripts for detailed debugging output
  • Consider making non-critical scripts fail gracefully

Scripts Run Too Long

  • Optimize long-running tasks
  • Consider moving heavy operations to cron jobs
  • Add timeouts to prevent hanging
  • Log progress for visibility