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.
How It Works
Section titled “How It Works”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
Common Use Cases
Section titled “Common Use Cases”Database Migrations Run database schema updates or data migrations automatically on deployment:
#!/bin/bashecho "Running database migrations..."php artisan migrate --forceCache Warming Pre-populate caches to improve initial response times:
#!/bin/bashecho "Warming application cache..."php artisan cache:warmConfiguration Generation Generate runtime configuration files based on environment variables:
#!/bin/bashecho "Generating application configuration..."envsubst < /app/config.template > /app/config.ymlAsset Compilation Build or optimize assets if not done during image build:
#!/bin/bashecho "Compiling frontend assets..."npm run build:productionCreating Post-Deployment Scripts
Section titled “Creating Post-Deployment Scripts”Script Structure
Section titled “Script Structure”Create shell scripts in your application’s /quant-entrypoint.d/ directory within your Docker image:
# DockerfileFROM php:8.2-fpm
# Create the entrypoint directoryRUN mkdir -p /quant-entrypoint.d
# Copy your post-deployment scriptsCOPY deploy-scripts/*.sh /quant-entrypoint.d/
# Make scripts executableRUN chmod +x /quant-entrypoint.d/*.sh
# Rest of your Dockerfile...Naming Convention
Section titled “Naming Convention”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.shScripts are executed in alphabetical order, so 05-check-dependencies.sh runs before 10-run-migrations.sh, etc.
Script Requirements
Section titled “Script Requirements”All scripts must:
- Have a
.shextension - Be executable (
chmod +x) - Use proper shebang (
#!/bin/bashor#!/bin/sh) - Handle errors appropriately
Best Practices
Section titled “Best Practices”Keep Scripts Idempotent Scripts should be safe to run multiple times without causing issues:
#!/bin/bash# Check if migration is needed before runningif [ ! -f /app/.migrated ]; then php artisan migrate --force touch /app/.migratedfiAdd Logging Include clear logging to help with debugging:
#!/bin/bashecho "[$(date)] Starting database migration..."php artisan migrate --forceecho "[$(date)] Migration completed successfully"Handle Failures Gracefully Decide whether failures should be fatal or just warnings:
#!/bin/bash# Continue even if cache warming failsif ! php artisan cache:warm; then echo "Warning: Cache warming failed, continuing anyway..."fiUse Environment Variables Leverage environment variables for configuration:
#!/bin/bashif [ "$RUN_MIGRATIONS" = "true" ]; then echo "Running migrations..." php artisan migrate --forceelse echo "Skipping migrations (RUN_MIGRATIONS not set)"fiViewing Script Output
Section titled “Viewing Script Output”Post-deployment script output is captured in your container logs. You can view the execution results:
- Navigate to your environment in the Quant Cloud dashboard
- Go to the Logs tab
- Filter for startup logs to see script output
- Look for your script’s echo statements and any errors
Example: Complete Laravel Migration Script
Section titled “Example: Complete Laravel Migration Script”#!/bin/bashset -e # Exit on error
echo "[SETUP] Starting Laravel post-deployment tasks..."
# Wait for database to be readyecho "[SETUP] Checking database connectivity..."php artisan db:ping --wait=30
# Run database migrationsecho "[SETUP] Running database migrations..."php artisan migrate --force --no-interaction
# Clear and rebuild cacheecho "[SETUP] Rebuilding application cache..."php artisan config:cachephp artisan route:cachephp 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-emptyfi
echo "[SETUP] Post-deployment setup completed successfully"Troubleshooting
Section titled “Troubleshooting”Scripts Not Executing
- Verify scripts are in
/quant-entrypoint.d/(not a subdirectory) - Ensure scripts have
.shextension - 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 -xto 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
Next Steps
Section titled “Next Steps”- Configuring Cron Jobs - Schedule recurring tasks
- Accessing Logs - View script execution output
- Environment Variables - Configure script behavior