Drone.io オンプレ版をCentOS7に30分でインストールする

環境

OS: CentOS Linux 7 (Core)
VCPU: 2
MEM: 2GB
Docker API Ver: 1.29

手順

1.Dockerをインストール
2.Drone.io Ver 0.7 のDockerイメージを取得
3.GitHubと連携
4.Drone.ioを起動
5.GitLabと連携
6.GitHub Enterpriseと連携

1.Dockerをインストール

Yumでインストール可能なDockerバージョンでは、古いので下記を参考Dockerをインストールする。

CentOS7にdockerとdocker-composeの最新版をインストールする

2.Drone.io Ver 0.7 のDockerイメージを取得

Dockerイメージを取得。

# docker pull drone/drone:0.7
0.7: Pulling from drone/drone
a3ed95caeb02: Pull complete
802d894958a2: Pull complete
64d43428256a: Pull complete
Digest: sha256:625a4f8db1c9c344517dc1de4519302f8be33b90b38b6dda58a796b8741e3fab
Status: Downloaded newer image for drone/drone:0.7

Dockerイメージの一覧を表示

# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
drone/drone         0.7                 c58de76939e9        3 weeks ago         25.7MB

3.GitHubと連携

まず、Developer applicationsで[Register a new application]を選択。

下記項目を設定。
x.x.x.xの部分は、Drone.ioをインストールしたサーバーIPアドレスまたはドメイン名を指定する。
登録完了後、[Client ID]と[Client Secret]が取得できる。

【Application name】Drone.io
【Homepage URL】http://x.x.x.x
【Authorization callback URL】http://x.x.x.x/authorize

.envを作成する。

# vim .env

内容

DRONE_SECRET=hogehgoe
DRONE_GITHUB_CLIENT=xx3ce1f35xxx0
DRONE_GITHUB_SECRET=45eaaae5103xxxxxxxxxxxxxx3d9b3eab3a79

docker-compose.ymlを作成する。

# vim docker-compose.yml

内容

version: '2'

services:
  drone-server:
    image: drone/drone:0.7
    ports:
      - 80:8000
    volumes:
      - ./drone:/var/lib/drone/
    restart: always
    environment:
      - DRONE_OPEN=true
      - DRONE_GITHUB=true
      - DRONE_GITHUB_CLIENT=${DRONE_GITHUB_CLIENT}
      - DRONE_GITHUB_SECRET=${DRONE_GITHUB_SECRET}
      - DRONE_SECRET=${DRONE_SECRET}

  drone-agent:
    image: drone/drone:0.7
    command: agent
    restart: always
    depends_on:
      - drone-server
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    environment:
      - DRONE_SERVER=ws://drone-server:8000/ws/broker
      - DRONE_SECRET=${DRONE_SECRET}

4.Drone.ioを起動

カレントディレクトリに.envdocker-compose.ymlがあるか確認します。

# tree -a
.
|-- .env
`-- docker-compose.yml

Docker ComposeでDrone.ioを起動する。

# docker-compose up -d
Creating droneio_drone-server_1 ...
Creating droneio_drone-server_1 ... done
Creating droneio_drone-agent_1 ...
Creating droneio_drone-agent_1 ... done

ブラウザからGitHubに登録した【Homepage URL】アクセスする。

http://x.x.x.x

5.GitLabと連携

まず、GitLabにSgin inして[User Settings]->[Applications]を選択。

下記項目を設定。
y.y.y.yの部分は、Drone.ioをインストールしたサーバーIPアドレスまたはドメイン名を指定する。
登録完了後、[Application Id]と[Secret]が取得できる。

【Name】Drone.io
【Redirect URI】http://y.y.y.y/authorize
【Scopes】api,read_userを選択

Applications

.envを作成する。
x.x.x.xは、GitLabをインストールしたサーバを指定する。

# vim .env

内容

DRONE_SECRET=hogehoge
DRONE_GITLAB_URL=http://x.x.x.x
DRONE_GITLAB_CLIENT=xxx69012cbfdae1c9e5e5050bfexxxxxxxxxxxxxxd87dadca1efade9cf54xxxx
DRONE_GITLAB_SECRET=xxxxx351601bxxxxxxxxxxxxxxxxx52b2339ed5608ee8ac3e4d57688xxxxxxxx

docker-compose.ymlを作成する。

# vim docker-compose.yml
version: '2'

services:
  drone-server:
    image: drone/drone:0.7
    ports:
      - 80:8000
    volumes:
      - ./drone:/var/lib/drone/
    restart: always
    environment:
      - DRONE_OPEN=true
      - DRONE_GITLAB=true
      - DRONE_GITLAB_URL=${DRONE_GITLAB_URL}
      - DRONE_GITLAB_CLIENT=${DRONE_GITLAB_CLIENT}
      - DRONE_GITLAB_SECRET=${DRONE_GITLAB_SECRET}
      - DRONE_SECRET=${DRONE_SECRET}

  drone-agent:
    image: drone/drone:0.7
    command: agent
    restart: always
    depends_on:
      - drone-server
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    environment:
      - DRONE_SERVER=ws://drone-server:8000/ws/broker
      - DRONE_SECRET=${DRONE_SECRET}

6.GitHub Enterpriseと連携

まず、GitLabにSgin inして[User Settings]->[Applications]を選択。

下記項目を設定。
y.y.y.yの部分は、Drone.ioをインストールしたサーバーIPアドレスまたはドメイン名を指定する。
登録完了後、[Application Id]と[Secret]が取得できる。

[Settings]->[OAuth applications]と進み、[Register a new application]を選択。

【Application name】Drone.io
【Homepage URL】http://y.y.y.y
【Authorization callback URL】http://y.y.y.y/authorize

.envを作成する。 x.x.x.xは、GitLabをインストールしたサーバを指定する。

# vim .env

内容

DRONE_SECRET=hogehoge
DRONE_GITHUB_URL=https://x.x.x.x
DRONE_GITHUB_CLIENT=xx1edeaa9c5xxxxd0x
DRONE_GITHUB_SECRET=xxxe2605exxxxxxxx0d551c6b8f1bbaxxxxx

docker-compose.ymlを作成する。

# vim docker-compose.yml
version: '2'

services:
  drone-server:
    image: drone/drone:0.7
    ports:
      - 80:8000
    volumes:
      - ./drone:/var/lib/drone/
    restart: always
    environment:
      - DRONE_OPEN=true
      - DRONE_GITHUB=true
      - DRONE_GITHUB_SKIP_VERIFY=true
      - DRONE_GITHUB_PRIVATE_MODE=false
      - DRONE_GITHUB_URL=${DRONE_GITHUB_URL}
      - DRONE_GITHUB_CLIENT=${DRONE_GITHUB_CLIENT}
      - DRONE_GITHUB_SECRET=${DRONE_GITHUB_SECRET}
      - DRONE_SECRET=${DRONE_SECRET}

  drone-agent:
    image: drone/drone:0.7
    command: agent
    restart: always
    depends_on:
      - drone-server
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    environment:
      - DRONE_SERVER=ws://drone-server:8000/ws/broker
      - DRONE_SECRET=${DRONE_SECRET}