drone組成:
1、drone-server 主服務,對接git server的 webhook ,解析流水線配置yml,web管理界面,路由並管理runner
2、drone-runner 運行流水線,有多種runner,docker,裸機,k8s
3、drone-plugin 插件,改變默認的運行方式
drone部署:
1、drone-server 需要配置好對接的git server
2、drone-runner 需要配置好對接的drone-serve
3、drone-plugin 可選非必須
a、一種是配合runner,server的,需要在部署的時候和runner對應,在docker-compose寫好配置即可
b、一種是在流水線運行的時候調用,直接在流水線里用即可
drone流水線:
step 步驟
每個步驟調用一個docker鏡像
比如:
- name: test # 步驟名稱 必須
image: daocloud.io/xxxxx/php7.2:1.0.0 # 使用的鏡像 必須
environment: # 設置環境變量 可選
GOOS: windows
CGO_ENABLED:0
GOOS:linux
GOARCH:amd64
commands: # 命令 必須
- go build
when: # 簡單的邏輯條件 可選
event:
- tag
drone插件:
drone秘鑰管理:
在dron里拉鏡像是內置的,推鏡像是插件提供的,所以要配置兩個秘鑰
1、拉秘鑰
兩種管理方式,推薦使用第二種方式
一、每個倉庫設置一次
先在本機docker login,會有一個config.json, cat ~/.docker/config.json,
在drone的管理界面把config.json的內容填入,並勾選allow如圖:

在.drone.yml里最后添加下面的配置
image_pull_secrets:
- dockerconfig # 和在web界面配置的一樣
二、全局設置,使用 drone/registry-plugin
在部署dorne的時候配置好
drone-registry-plugin:
image: drone/registry-plugin
container_name: drone-registry-plugin
ports:
- 3030:3000
environment:
- DRONE_DEBUG=true
- DRONE_SECRET=bea26a2221fd8090ea38720fc445eca6
- DRONE_CONFIG_FILE=/etc/registry_config.yml
volumes:
- /data/test/drone/registry_config.yml:/etc/registry_config.yml
其中registry_config.yml的配置如下,可以配置多項
- address: daocloud.io
username: xxxxx
password: xxxxxx
2、推秘鑰
drone流水線並不內置docker鏡像打包的操作,而是使用插件 plugins/docker ,默認是推送到docker.io
推送到自定義倉庫設置如下:
- name: docker
image: plugins/docker
settings:
username: xxxx@qq.com
password:
from_secret: aliyun_pwd
repo: registry.cn-hangzhou.aliyuncs.com/xxx/abcd
registry: registry.cn-hangzhou.aliyuncs.com
auto_tag: true
dockerfile: Dockerfile
mirror: https://xxxx.mirror.aliyuncs.com
這個使用秘鑰的方式如下:

drone緩存:
使用volume,必須在部署drone-runner的時候,就配置好。
在drone-runner的environment添加
- DRONE_RUNNER_VOLUMES=/data/test/drone/cache:/data/cache # 宿主機目錄,用於緩存
在.drone.yml里最后添加
volumes:
- name: cache
host:
path: /tmp/cache/golang
使用方法:
- name: build
image: golang:1.13
# pull: false
commands:
- export GOPROXY="http://mirrors.aliyun.com/goproxy/"
- env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build main.go
volumes:
- name: cache
path: /go
其它設置
-
鏡像拉取方式 pull: if-not-exists
-
clone 深度,加快大倉庫的構建
clone: depth: 10
