Drone 是一个轻量级,为容器构建的强大的持续交付平台。

官方文档已经说得很清楚了,这里就简单介绍一下的折腾

安装之 docker-compose.yaml

支持对接 Github,Gogs等,现实需要对接 github.

在 GitHub 注册应用程序来获得 client id 和 secret。认证回调 URL(authorization callback URL)应与您的对应域名匹配,并以 /authorize 作为 URL 的路径(path)。👉注册地址

  drone:
    image: drone/drone:0.8
    container_name: drone
    volumes:
    - ./drone/lib/:/var/lib/drone/
    environment:
      - DRONE_OPEN=false
      - DRONE_HOST=https://ci.pt.spanda.io
      - DRONE_ORGS=SpandaCloudPlatform
      - DRONE_ADMIN=ysicing
      - DRONE_GITHUB=true
      - DRONE_GITHUB_CLIENT=<github_client>
      - DRONE_GITHUB_SECRET=<github_secret>
      - DRONE_SECRET=daechae2cheithei3looGhaishoh7tienoo0bahweinahmo6aePauji3akoht3ma
    ports:
      - 50080:8000
    restart: always

  drone-agent:
    image: drone/agent:0.8
    container_name: drone-agent
    command: agent
    depends_on:
      - drone
    restart: always
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    environment:
      - DRONE_SERVER=drone:9000
      - DRONE_SECRET=daechae2cheithei3looGhaishoh7tienoo0bahweinahmo6aePauji3akoht3ma

相关参数配置说明:

DRONE_OPEN=true #开放注册
DRONE_ORGS=SpandaCloudPlatform #配置允许白名单组织的成员注册和登录系统
或者
DRONE_OPEN=false #关闭注册
DRONE_ADMIN=ysicing #管理员用户,通过 cli 工具管理成员

DRONE_SECRET # 可以使用pwgen 64 1生成

安装之 Caddyfile

ci.pt.spanda.io {
    gzip {
        not /stream/
    }
    log / /var/log/caddy/ci.pt.log "{remote} {when} {method} {uri} {proto} {status} {size} {>User-Agent} {latency}" {
   	rotate_size 50
	rotate_age  90
	rotate_keep 20
	rotate_compress
    }
    tls root@ysicing.net
    header / {
    	Strict-Transport-Security "max-age=31536000;includeSubDomains;preload"
	    -Server
	}
    proxy / 127.0.0.1:50080 {
        transparent
        websocket
    }
}

需要启用 websocket upgrade.

编写 drone.yml

具体可以参考 SpandaCloudPlatform/hoto

pipeline:
  docker:
    image: plugins/docker
    repo: spanda/hoto
    secrets: [ docker_username, docker_password ]
    tags:
      - 0.1.0
      - latest

branches: master

安装 cli工具

brew tap drone/drone
brew install drone

通过https://ci.pt.spanda.io/account/token获取到相关的token

drone registry add -repository SpandaCloudPlatform/hoto -username <docker.io.username> -password <docker.io.passwd>

但是,通过这样配置,在 push 镜像时会提示没权限.通过如下:

drone secret add -repository SpandaCloudPlatform/hoto -name docker_password -image plugins/docker -value <docker.io.passwd>
drone secret add -repository SpandaCloudPlatform/hoto -name docker_username -image plugins/docker -value  <docker.io.username>

其他

为啥网络不是 host, 是因为9000端口被 minio 占用了…

细节推荐官方文档: DRONE docs