Your cart is currently empty!
Simple Guide to Drone CI with Docker Compose: A Real-World Example
Here’s a streamlined guide based on our working implementation:
kind: pipeline
type: docker
name: production-deploy
# Only run on prod branch pushes or manual triggers
trigger:
branch:
- prod
event:
- push
- manual
steps:
# Step 1: Debug & Environment Check
- name: debug-info
image: docker:dind
volumes:
- name: docker-socket
path: /var/run/docker.sock
commands:
- pwd
- ls -la
- docker version
- docker info
- docker compose version
# Step 2: Deploy Application
- name: deploy
image: docker:dind
volumes:
- name: docker-socket
path: /var/run/docker.sock
commands:
# Show environment info
- echo "Current working directory and contents:"
- pwd
- ls -la
# Verify Docker setup
- docker version
- docker compose version
# Stop existing deployment
- docker compose down --timeout 30 --remove-orphans || true
# Deploy new version
- docker compose up -d --build --force-recreate
# Show deployment status
- docker compose ps -a
- docker compose logs --no-log-prefix
# Step 3: Tag Release
- name: publish-release
image: plugins/git
settings:
branch: prod
remote: origin
commands:
- git tag -f "production-$(date +%Y%m%d-%H%M)"
- git push origin --tags
# Required Docker socket access
volumes:
- name: docker-socket
host:
path: /var/run/docker.sock
Key Features Explained
- Simple Trigger System
- Runs on prod branch pushes
- Allows manual triggers for flexibility
- Three Clear Steps
- debug-info: Verifies environment
- deploy: Handles the actual deployment
- publish-release: Tags successful deployments
- Docker-in-Docker (dind)
- Uses docker:dind image for reliable Docker operations
- Mounts Docker socket for container management
- Safe Deployment Process
- Gracefully stops existing containers
- Forces fresh builds to avoid caching issues
- Shows logs for debugging
- Version Tracking
- Automatically tags successful deployments
- Uses timestamp-based tags for traceability
Usage
- Setup
- Place this .drone.yml in your repository root
- Ensure Docker Compose file is present
- Configure Drone CI with your repository
- Deployment
- Push to prod branch
- OR trigger manually from Drone UI
- Monitoring
- Watch build progress in Drone UI
- Check logs for detailed status
- Verify container status after deployment
This simplified approach gives you a robust deployment pipeline without unnecessary complexity. It’s production-tested and handles the essential needs of a Docker Compose-based deployment.
by
Tags:
Leave a Reply