# Drone CI

> Container-native CI/CD platform with Gitea integration.

- Category: DevOps & CI/CD
- Difficulty: intermediate
- Components: drone, gitea
- Tags: drone, ci-cd, container, gitea
- Source: https://docker.recipes/devops/drone-ci

## Overview

Drone is a container-native continuous integration and continuous deployment (CI/CD) platform that was created by Brad Rydzewski and open-sourced in 2014. Unlike traditional CI/CD systems that require complex server setups and agent management, Drone executes build pipelines inside ephemeral Docker containers, making it naturally scalable and consistent across different environments. Each pipeline step runs in isolation with exactly the resources and dependencies it needs, eliminating the 'works on my machine' problem that plagues many CI/CD implementations.

This stack combines Drone with Gitea to create a completely self-hosted development workflow that rivals GitHub Actions or GitLab CI. Gitea serves as the lightweight Git repository host, providing pull requests, issue tracking, and user management, while Drone handles the automated testing, building, and deployment pipelines. The integration works through OAuth2 authentication and webhooks, so when developers push code to Gitea repositories, Drone automatically triggers the appropriate build pipelines defined in .drone.yml files.

This combination is particularly valuable for teams that want complete control over their source code and CI/CD infrastructure without the complexity of GitLab or the cost of hosted solutions. Small to medium development teams, organizations with strict data sovereignty requirements, and companies building internal developer platforms will find this stack provides enterprise-grade CI/CD capabilities while running on minimal hardware resources.

## Features

- Container-native pipeline execution with each step running in isolated Docker containers
- Native Gitea integration through OAuth2 with automatic webhook configuration for push and pull request triggers
- Declarative pipeline configuration using simple YAML syntax in .drone.yml files
- Docker-in-Docker build capabilities for building and pushing container images within pipelines
- Parallel step execution and matrix builds for testing across multiple environments simultaneously
- Built-in secret management with encrypted environment variables and external secret providers
- Conditional pipeline execution based on branch, tag, or file change patterns
- Plugin ecosystem with over 100 pre-built plugins for deployment, notifications, and integrations

## Use cases

- Small development teams needing self-hosted CI/CD without GitHub or GitLab dependencies
- Organizations with data sovereignty requirements that cannot use cloud-based CI/CD services
- Container-first development workflows where all applications are built and deployed as Docker images
- Internal developer platforms providing standardized CI/CD across multiple development teams
- Educational environments teaching DevOps practices with real CI/CD tooling
- Hybrid cloud deployments where code stays on-premises but deploys to multiple cloud providers
- Open source projects requiring free, unlimited private repository hosting with automated testing

## Prerequisites

- Docker Engine 20.03+ with docker-compose or Docker Desktop with at least 2GB available RAM
- Minimum 4GB system RAM (Gitea requires 512MB, Drone server 1GB, runner containers variable)
- Available ports 3000 (Gitea web), 2222 (Gitea SSH), and 8080 (Drone web interface)
- Basic understanding of Git workflows, Docker containers, and YAML configuration syntax
- Access to Docker Hub or container registry for pulling pipeline images and pushing built artifacts
- SSL certificate and domain name for production deployments with webhook callbacks

## docker-compose.yml

```yaml
services:
  gitea:
    image: gitea/gitea:latest
    container_name: gitea
    environment:
      USER_UID: 1000
      USER_GID: 1000
    volumes:
      - gitea_data:/data
    ports:
      - "3000:3000"
      - "2222:22"
    networks:
      - drone

  drone:
    image: drone/drone:2
    container_name: drone
    environment:
      DRONE_GITEA_SERVER: http://gitea:3000
      DRONE_GITEA_CLIENT_ID: ${DRONE_GITEA_CLIENT_ID}
      DRONE_GITEA_CLIENT_SECRET: ${DRONE_GITEA_CLIENT_SECRET}
      DRONE_RPC_SECRET: ${DRONE_RPC_SECRET}
      DRONE_SERVER_HOST: localhost:8080
      DRONE_SERVER_PROTO: http
    volumes:
      - drone_data:/data
    ports:
      - "8080:80"
    depends_on:
      - gitea
    networks:
      - drone

  drone-runner:
    image: drone/drone-runner-docker:1
    container_name: drone-runner
    environment:
      DRONE_RPC_PROTO: http
      DRONE_RPC_HOST: drone
      DRONE_RPC_SECRET: ${DRONE_RPC_SECRET}
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    depends_on:
      - drone
    networks:
      - drone

volumes:
  gitea_data:
  drone_data:

networks:
  drone:
    driver: bridge
```

## .env

```bash
DRONE_GITEA_CLIENT_ID=your-client-id
DRONE_GITEA_CLIENT_SECRET=your-client-secret
DRONE_RPC_SECRET=your-rpc-secret
```

## Usage notes

- Docs: https://docs.drone.io/
- Setup Gitea first at http://localhost:3000
- Create OAuth2 app in Gitea: Settings > Applications
- Drone at http://localhost:8080
- Generate RPC secret: openssl rand -hex 16
- Pipeline config in .drone.yml in repository root

## Troubleshooting

- Drone shows 'failed to find or parse .drone.yml': Ensure .drone.yml file exists in repository root with valid YAML syntax and proper indentation
- Build fails with 'Cannot connect to the Docker daemon': Verify /var/run/docker.sock is mounted in drone-runner and Docker daemon is accessible
- Gitea OAuth2 authentication fails: Check DRONE_GITEA_CLIENT_ID and CLIENT_SECRET match the OAuth2 application created in Gitea settings
- Pipeline builds never trigger: Confirm webhook delivery in Gitea repository settings and verify DRONE_SERVER_HOST matches accessible Drone URL
- Runner shows 'x509: certificate signed by unknown authority': Set DRONE_RPC_SKIP_VERIFY=true for self-signed certificates or add CA certificate to runner
- Builds timeout or hang indefinitely: Increase Docker daemon resources or add timeout limits to individual pipeline steps

