如何使用 Docker 建置基礎的 Drone CI Server 與 Runner?

如果你想要使用 Docker 建置 Drone CI Server 與 Runner,你可以使用 docker-compose 來快速的建立相對應的環境

Drone CI Server 安裝

你可以依據以下的步驟準備 Drone CI Server 環境:

  1. 安裝 docker

    sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
  2. 安裝 docker-compose

    sudo apt-get update
    sudo apt-get install docker-compose-plugin
  3. 使用以下的 docker-compose-yaml 建立 Drone CI Server

    version: '3'
    services:
      drone-server:
        image: drone/drone:2.15.0
        ports:
          - "80:80"
          - "443:443"
        volumes:
          - ./drone:/var/lib/drone/
          - /var/run/docker.sock:/var/run/docker.sock
          - ./drone.key:/etc/drone.key
        environment:
          - DRONE_GIT_ALWAYS_AUTH=true
          - DRONE_GITLAB_SKIP_VERIFY=true
          - DRONE_GITLAB_SERVER=https://your-gitlab.com.tw
          - DRONE_GITLAB_CLIENT_ID=your-gitlab-client-id
          - DRONE_GITLAB_CLIENT_SECRET=your-gitlab-secret
          - DRONE_AGENTS_ENABLED=true
          - DRONE_RPC_SECRET=drone-rpc-secret
          - DRONE_SERVER_HOST=your-drone-server.host
          - DRONE_SERVER_PROTO=https
          - DRONE_TLS_AUTOCERT=true
          - DRONE_LICENSE=/etc/drone.key
          - AWS_ACCESS_KEY_ID=aws-key
          - AWS_SECRET_ACCESS_KEY=asw-secret
          - AWS_DEFAULT_REGION=ap-southeast-1
          - AWS_REGION=ap-southeast-1

Drone CI Runner 安裝

Drone 並沒有限制有多少個 Client,你可以根據你的需求建立對應的機器數量

  1. 安裝 docker

    sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
  2. 安裝 docker-compose

    sudo apt-get update
    sudo apt-get install docker-compose-plugin
  3. 使用以下的 docker-compose-yaml 建立 Drone CI Runner

    version: '3'
    services:
      drone-agent:
        image: drone/drone-runner-docker:1.8.2
        restart: always
        ports:
          - "3000:3000"
        volumes:
          - /var/run/docker.sock:/var/run/docker.sock
        environment:
          - DRONE_RPC_PROTO=https
          - DRONE_RPC_HOST=your_rpc_host.com
          - DRONE_RPC_SECRET=your_rpc_secret
          - DRONE_RUNNER_CAPACITY=10
          - DRONE_RUNNER_NAME=drone-agent-3