Setting Up CI/CD Pipelines for Drupal on Druvance
Learn how to automate your Drupal deployments with GitHub Actions, GitLab CI, and Druvance CLI.
Setting Up CI/CD Pipelines for Drupal on Druvance
Continuous Integration and Continuous Deployment (CI/CD) automate your development workflow, ensuring code quality and faster releases. This guide shows you how to set up CI/CD for Drupal on Druvance.
Why CI/CD Matters
Benefits
- **Faster Releases** - Deploy multiple times per day
- **Reduced Risk** - Smaller, incremental changes
- **Consistent Quality** - Automated testing catches issues early
- **Team Productivity** - Less manual work, more development
The Pipeline
Code Commit → Build → Test → Deploy to Staging → Approval → Deploy to ProductionGitHub Actions Setup
Basic Workflow
Create .github/workflows/deploy.yml:
name: Deploy to Druvance
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
- name: Install dependencies
run: composer install
- name: Run tests
run: ./vendor/bin/phpunit
deploy:
needs: test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v3
- name: Install Druvance CLI
run: npm install -g @druvance/cli
- name: Deploy to Staging
env:
DRUVANCE_API_KEY: ${{ secrets.DRUVANCE_API_KEY }}
run: |
druvance login --token $DRUVANCE_API_KEY
druvance deploy --site=my-site --env=stagingDatabase Updates
Include database updates in deployment:
- name: Run database updates
run: |
druvance ssh --site=my-site --env=staging -- "drush updb -y && drush cim -y && drush cr"Configuration Management
Export and commit configuration:
- name: Export configuration
run: |
drush cex -y
git add config/
git diff --staged --quiet || git commit -m "Export configuration"GitLab CI Setup
Pipeline Configuration
Create .gitlab-ci.yml:
stages:
- test
- build
- deploy
variables:
DRUVANCE_API_KEY: $DRUVANCE_API_KEY
test:
stage: test
image: php:8.2
script:
- composer install
- ./vendor/bin/phpunit
only:
- merge_requests
- main
deploy_staging:
stage: deploy
image: node:18
script:
- npm install -g @druvance/cli
- druvance login --token $DRUVANCE_API_KEY
- druvance deploy --site=my-site --env=staging
- druvance ssh --site=my-site --env=staging -- "drush updb -y && drush cim -y"
only:
- main
deploy_production:
stage: deploy
image: node:18
script:
- npm install -g @druvance/cli
- druvance login --token $DRUVANCE_API_KEY
- druvance deploy --site=my-site --env=production
- druvance ssh --site=my-site --env=production -- "drush updb -y && drush cim -y"
when: manual
only:
- mainAutomated Testing
PHPUnit Tests
Run unit and kernel tests:
- name: Run PHPUnit
run: |
./vendor/bin/phpunit --testsuite=unit,kernel --coverage-html=coverageCode Quality
Check code standards:
- name: Check coding standards
run: |
./vendor/bin/phpcs --standard=Drupal web/modules/custom web/themes/customStatic Analysis
Use PHPStan for static analysis:
- name: Run PHPStan
run: |
./vendor/bin/phpstan analyse web/modules/custom --level=8Advanced Patterns
Blue-Green Deployment
Zero-downtime deployments:
- name: Blue-Green Deploy
run: |
# Deploy to inactive environment
druvance deploy --site=my-site --env=green
# Run smoke tests
curl -f https://green.my-site.druvance.com/health
# Switch traffic
druvance switch --site=my-site --to=greenFeature Flags
Deploy with feature flags:
- name: Deploy with feature flags
run: |
druvance deploy --site=my-site --env=production
druvance feature:enable --site=my-site --flag=new-feature --percentage=10Database Migrations
Handle schema changes:
- name: Backup and migrate
run: |
# Create backup
druvance backup:create --site=my-site --env=production
# Run migrations
druvance ssh --site=my-site --env=production -- "drush updb -y"
# Verify
druvance ssh --site=my-site --env=production -- "drush status"Notifications
Slack Integration
Get deployment notifications:
- name: Notify Slack
uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
channel: '#deployments'
text: 'Deployed to production'
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}Rollback Strategy
Automatic Rollback
Roll back on failure:
- name: Deploy with rollback
run: |
druvance deploy --site=my-site --env=production || druvance rollback --site=my-site --env=productionManual Rollback
Create rollback workflow:
name: Rollback Production
on:
workflow_dispatch:
jobs:
rollback:
runs-on: ubuntu-latest
steps:
- name: Rollback
run: |
druvance login --token ${{ secrets.DRUVANCE_API_KEY }}
druvance rollback --site=my-site --env=productionSecurity Best Practices
Secrets Management
Store sensitive data securely:
- Use GitHub/GitLab secrets
- Never commit API keys
- Rotate credentials regularly
- Use environment-specific secrets
Deployment Keys
Use dedicated deployment keys:
# Generate deployment key
druvance key:create --name=ci-cd --scope=deploy
# Add to CI/CD secretsMonitoring Deployments
Deployment Tracking
Track every deployment:
- name: Track deployment
run: |
druvance deploy:track --site=my-site --version=${{ github.sha }} --author=${{ github.actor }}Post-Deployment Tests
Verify after deployment:
- name: Smoke tests
run: |
curl -f https://my-site.com/health
curl -f https://my-site.com/api/statusConclusion
CI/CD pipelines automate your Drupal deployment process, reducing manual work and deployment risk. With Druvance's CLI and API, integrating with your favorite CI/CD tools is straightforward.
Ready to automate your deployments? [Get started with Druvance CLI.](https://docs.druvance.com/cli)
Written by Jordan Lee
DevOps Engineer
Jordan Lee is part of the Druvance team, helping developers and organizations build better Drupal experiences. Follow for more insights on Drupal, web development, and cloud hosting.
Related Articles
Getting Started with Druvance: A Complete Guide for Beginners
Learn how to set up your first Drupal site on Druvance in under 10 minutes. This comprehensive guide covers everything from account creation to going live.
How AI is Revolutionizing Drupal Performance Optimization
Discover how Druvance uses artificial intelligence to automatically optimize your Drupal sites for peak performance.
Subscribe to our newsletter
Get the latest articles, tutorials, and updates delivered to your inbox.