Drupal Staging Deployment v1.0
This solution provides automated staging deployment for Drupal applications using GitLab CI/CD and Docker Swarm with Traefik.
đ Quick Install
Online Install (Recommended):
curl -sSL https://stage-tools.tyche.q2.cz/drupal/v1.0/install.sh | bashDownload & Run:
curl -O https://stage-tools.tyche.q2.cz/drupal/v1.0/install.sh
chmod +x install.sh
./install.shWeb Interface:
Visit https://stage-tools.tyche.q2.cz for a full solution browser.
Features
- đ Optimized Docker builds with multi-stage building and composer caching
- đ Automated CI/CD with GitLab pipelines including database setup
- đ Traefik integration for automatic SSL and routing
- đī¸ Automatic database management with MariaDB
- đĻ Frontend build support with Node.js (optional)
- đĄī¸ Production-ready with security best practices
- đ§ Flexible PHP extensions (SQL Server, ImageMagick, etc.)
- Drupal project with
composer.json - GitLab repository with CI/CD enabled
- Docker Swarm cluster with Traefik
- GitLab runners with Docker support
- MariaDB/MySQL database server
- đ Interactive documentation with syntax highlighting
- đž Copy-paste installation commands for multiple methods
- đ Solution browser with status and features
- đ Template previews and configuration examples
Prerequisites
Installation
đ Web Interface (Recommended)
Visit the Stage Tools Web Interface to browse solutions and get installation commands:
https://stage-tools.tyche.q2.cz
The web interface provides:
Manual Installation
If you prefer command-line installation:
Manual Installation
If you prefer command-line installation:
Clone stage-tools repository
git clone git@gitlab.com:your-org/stage-tools.git /tmp/stage-tools
Run installer from your Drupal project root
cd /path/to/your/drupal/project
/tmp/stage-tools/drupal/default/v1.0/install.sh
Clean up
rm -rf /tmp/stage-toolsManual Installation
1. Download the install script:
wget https://gitlab.com/your-org/stage-tools/-/raw/main/drupal/default/v1.0/install.sh
chmod +x install.sh2. Run the interactive setup:
./install.shConfiguration
The script will ask for:
web, docroot, or publicGenerated Files
After installation, you'll have:
your-drupal-project/
âââ .gitlab-ci.yml # GitLab CI/CD pipeline
âââ .dockerignore # Docker build optimization
âââ .q2/
âââ staging/
âââ Dockerfile.stage # Optimized Drupal Dockerfile
âââ docker-entrypoint.sh # Container startup script
âââ generate-drupal-compose.sh # Dynamic compose generator
âââ deploy/
âââ ci/
âââ docker-compose.stage.yml # Docker Swarm configurationUsage
1. Create cron schedule file for your environment:
Create crontab-stage.txt
echo "0 /6 /usr/local/bin/drush cron" > crontab-stage.txt2. Configure GitLab CI/CD variables:
-
MYSQL_ROOT_PASSWORD - Database root password-
MYSQL_HOST - Database server address -
MYSQL_PORT - Database server port3. Set up .env file with basic configuration:
APP_ENV=local
DATABASE_URL=mysql://user:pass@localhost:3306/dbname4. Push to staging branch:
git push origin stage5. Monitor deployment in GitLab CI/CD pipelines
6. Access your application at:
https://[project-name].[domain-suffix]Pipeline Stages
The GitLab CI pipeline includes:
1. Prepare - Generate Docker configurations from DDEV setup
2. Build - Create optimized Docker image with caching
3. DB Setup - Create database and user automatically
4. Deploy - Deploy to Docker Swarm with health checks
Customization
PHP Extensions
The installer supports various PHP extensions:
Standard Drupal extensions:
mysqli, pdo_mysql - Database connectivitygd, intl, zip, xml - Core Drupal requirements opcache, bcmath, ftp - Performance and functionalityOptional extensions:
sqlsrv, pdo_sqlsrv)imagick)Frontend Build
If you have Node.js assets (themes, modules):
package.json and .ddev/config.yamlnpm run build or yarn build during image creationEnvironment Settings
The deployment creates:
settings.stage.php - Database and Drupal configurationservices.stage.yml - Caching and performance settingsDatabase Management
The pipeline automatically:
Advanced Configuration
Custom Dockerfile
To modify the Dockerfile generation, edit:
.q2/staging/generate-drupal-compose.shMultiple Environments
Create variants for different environments:
Copy and customize for production
cp crontab-stage.txt crontab-prod.txt
Modify schedule as needed
Database Import
To import existing database during deployment, place:
sql/stage.sql or sql/stage.sql.gz in your projectSQL_DUMP_URL GitLab variableTroubleshooting
Common Issues
1. "No composer.json found"
- Run the script from your Drupal project root
2. Database connection fails
- Check
MYSQL_HOST and MYSQL_PORT variables- Verify database server is accessible from GitLab runners
- Check
MYSQL_ROOT_PASSWORD is correct3. Build fails with PHP extensions
- Review the generated Dockerfile.stage
- Some extensions may need additional system packages
4. Deployment fails
- Check GitLab runner has Docker Swarm access
- Verify Traefik network exists and is accessible
- Check container logs:
docker service logs [service-name]Logs and Debugging
docker service logs [project-name]_appdb_setup stage outputhttps://yourdomain.com/health.phpSecurity Considerations
.env files with real credentialsPerformance Features
Migration from Existing Setup
If migrating from manual Docker/server setup:
1. Backup existing configuration
2. Run the installer in a test environment first
3. Compare generated files with your custom ones
4. Migrate custom settings to generated templates
5. Test thoroughly before production migration
Drupal-Specific Features
Support
docker build -f .q2/staging/Dockerfile.stage .