# Gitea + Drone CI + Registry

> Complete self-hosted Git platform with CI/CD pipeline and container registry.

- Category: DevOps & CI/CD
- Difficulty: advanced
- Components: gitea, drone-server, drone-runner, registry
- Tags: git, ci-cd, registry, gitea, drone, containers
- Source: https://docker.recipes/devops/gitea-drone-registry

## Overview

Gitea is a lightweight, self-hosted Git service written in Go that provides GitHub-like functionality with minimal resource requirements. Originally forked from Gogs in 2016, Gitea has evolved into a full-featured Git platform offering repository hosting, issue tracking, pull requests, and built-in package registry support. Its philosophy centers on simplicity and performance, making it ideal for teams who want GitHub's features without the complexity of GitLab or dependency on external services.

This stack combines Gitea with Drone CI and a Docker Registry to create a complete DevOps pipeline. Drone CI acts as the continuous integration engine, automatically building and testing code when developers push to Gitea repositories. The Docker Registry stores the resulting container images, while Drone runners execute builds in isolated Docker containers. This integration creates an automated workflow where code commits trigger builds, tests run in consistent environments, and successful builds produce deployable artifacts stored in your private registry.

Development teams, DevOps engineers, and organizations prioritizing data sovereignty will find this stack particularly valuable. Unlike cloud-based solutions, this combination runs entirely on your infrastructure, ensuring code privacy and eliminating vendor lock-in. Small to medium teams benefit from Gitea's lightweight nature (requiring only 512MB RAM), while the Drone CI integration provides enterprise-grade automation without the licensing costs of Jenkins or GitLab CI. The included Docker Registry completes the picture by providing secure, private container image storage with configurable retention policies.

## Features

- GitHub-like web interface with pull requests, code review, and issue tracking
- PostgreSQL backend for both Gitea and Drone ensuring data consistency and reliability
- Drone CI pipeline automation with YAML-based configuration and Docker container execution
- Docker Registry v2 API compliance with image deletion and garbage collection support
- OAuth2 integration between Gitea and Drone for single sign-on authentication
- Multi-architecture container support through Drone's Docker runner capabilities
- Webhook-triggered builds automatically starting CI pipelines on Git push events
- Built-in package registry support in Gitea for npm, Docker, and Maven artifacts

## Use cases

- Private software development teams needing GitHub-like collaboration without SaaS dependencies
- Organizations with compliance requirements mandating on-premises code hosting and CI/CD
- Startups building containerized applications requiring integrated Git hosting and image registry
- Development teams migrating from GitHub/GitLab seeking cost-effective self-hosted alternatives
- Educational institutions teaching DevOps practices with complete pipeline visibility
- Open source projects requiring private development repositories with public release automation
- Consultancies managing multiple client codebases with isolated, branded Git platforms

## Prerequisites

- Docker host with minimum 2GB RAM (1GB for services, 1GB for build processes)
- Available ports 3000 (Gitea web), 222 (SSH), 8080 (Drone), and 5000 (Registry)
- Domain names or hostnames configured for Gitea and Drone with SSL certificates recommended
- Basic understanding of OAuth2 application setup for Gitea-Drone integration
- Familiarity with YAML syntax for creating Drone CI pipeline configurations
- PostgreSQL administration knowledge for database maintenance and backups

## docker-compose.yml

```yaml
services:
  gitea:
    image: gitea/gitea:latest
    container_name: gitea
    environment:
      - USER_UID=1000
      - USER_GID=1000
      - GITEA__database__DB_TYPE=postgres
      - GITEA__database__HOST=gitea-db:5432
      - GITEA__database__NAME=gitea
      - GITEA__database__USER=gitea
      - GITEA__database__PASSWD=${DB_PASSWORD}
      - GITEA__server__ROOT_URL=${GITEA_URL}
      - GITEA__server__SSH_DOMAIN=${GITEA_DOMAIN}
      - GITEA__server__SSH_PORT=222
    volumes:
      - gitea-data:/data
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    ports:
      - "3000:3000"
      - "222:22"
    depends_on:
      - gitea-db
    networks:
      - gitea-network
    restart: unless-stopped

  gitea-db:
    image: postgres:15-alpine
    container_name: gitea-db
    environment:
      - POSTGRES_USER=gitea
      - POSTGRES_PASSWORD=${DB_PASSWORD}
      - POSTGRES_DB=gitea
    volumes:
      - gitea-postgres:/var/lib/postgresql/data
    networks:
      - gitea-network
    restart: unless-stopped

  drone:
    image: drone/drone:2
    container_name: drone
    environment:
      - DRONE_GITEA_SERVER=${GITEA_URL}
      - 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=${DRONE_HOST}
      - DRONE_SERVER_PROTO=https
      - DRONE_DATABASE_DRIVER=postgres
      - DRONE_DATABASE_DATASOURCE=postgres://drone:${DRONE_DB_PASSWORD}@drone-db:5432/drone?sslmode=disable
    volumes:
      - drone-data:/data
    ports:
      - "8080:80"
    depends_on:
      - drone-db
    networks:
      - gitea-network
    restart: unless-stopped

  drone-db:
    image: postgres:15-alpine
    container_name: drone-db
    environment:
      - POSTGRES_USER=drone
      - POSTGRES_PASSWORD=${DRONE_DB_PASSWORD}
      - POSTGRES_DB=drone
    volumes:
      - drone-postgres:/var/lib/postgresql/data
    networks:
      - gitea-network
    restart: unless-stopped

  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}
      - DRONE_RUNNER_CAPACITY=2
      - DRONE_RUNNER_NAME=docker-runner
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    depends_on:
      - drone
    networks:
      - gitea-network
    restart: unless-stopped

  registry:
    image: registry:2
    container_name: registry
    environment:
      - REGISTRY_HTTP_SECRET=${REGISTRY_SECRET}
      - REGISTRY_STORAGE_DELETE_ENABLED=true
    volumes:
      - registry-data:/var/lib/registry
    ports:
      - "5000:5000"
    networks:
      - gitea-network
    restart: unless-stopped

volumes:
  gitea-data:
  gitea-postgres:
  drone-data:
  drone-postgres:
  registry-data:

networks:
  gitea-network:
    driver: bridge
```

## .env

```bash
# Gitea + Drone CI + Registry
DB_PASSWORD=secure_gitea_password
GITEA_URL=http://localhost:3000
GITEA_DOMAIN=localhost

# Drone CI
DRONE_GITEA_CLIENT_ID=your_oauth_client_id
DRONE_GITEA_CLIENT_SECRET=your_oauth_client_secret
DRONE_RPC_SECRET=super_secret_rpc_key
DRONE_HOST=localhost:8080
DRONE_DB_PASSWORD=secure_drone_password

# Registry
REGISTRY_SECRET=registry_http_secret
```

## Usage notes

- Gitea at http://localhost:3000
- Drone CI at http://localhost:8080
- Registry at http://localhost:5000
- Create OAuth app in Gitea for Drone
- Configure webhooks for CI triggers

## Troubleshooting

- Drone shows 'oauth2: cannot fetch token' error: Verify DRONE_GITEA_CLIENT_ID and CLIENT_SECRET match OAuth application created in Gitea settings
- Gitea SSH clone fails with permission denied: Check USER_UID/USER_GID environment variables match host user permissions on gitea-data volume
- Drone builds fail with 'Cannot connect to Docker daemon': Ensure /var/run/docker.sock is properly mounted and drone-runner has Docker socket access
- Registry push fails with 'unauthorized' error: Configure Docker daemon with insecure-registries for localhost:5000 or implement TLS certificates
- Gitea database connection errors on startup: Verify DB_PASSWORD environment variable matches between gitea and gitea-db services
- Drone runner shows 'server gave HTTP response to HTTPS client': Check DRONE_RPC_PROTO matches actual protocol used by Drone server

