最近研究了一下drone,尝试将drone和gitlab集合在一起,做CI服务。drone官方是有说明文档,支持gitlab的,见drone server的安装文档。我个人安装过程中碰了一些坑,在这里记下安装过程。
安装docker-compose
直接下载官方二进制文件安装
1
| curl -L "https://github.com/docker/compose/releases/download/1.17.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && chmod +x /usr/local/bin/docker-compose
|
获取gitlab授权
这里省略gitlab的安装,gitlab地址:172.16.0.189
首先需要登录gitlab管理员账号,创建一个名为”drone”的应用
http://172.16.0.123:8080 是drone server的服务地址,创建完成后记得保存CLIENT_ID和CLIENT_SECRET
然后打开gitlab的网络限制 - 允许来自钩子和服务对本地网络的请求
安装drone 1.0
使用docker-compose的方式启动一个drone server和一个drone agent
docker-compose.yml 如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| version: "2" services: drone-server: image: drone/drone:latest container_name: drone-server ports: - "8080:80" - "9000:9000" volumes: - /var/run/docker.sock:/var/run/docker.sock - ./drone/:/data/ extra_hosts: - "git.rhel.cc:172.16.0.189" environment: - TZ=Asia/Shanghai - DRONE_GITLAB_SERVER=http://172.16.0.189 - DRONE_USER_CREATE=username:zane,admin:true - DRONE_GITLAB_CLIENT_ID=af829bc7075cbe79603b79086f0d71654ecfde7092ba9b928d4327868e57e610 - DRONE_GITLAB_CLIENT_SECRET=a5eedb2a1fcb21c33b0610125cd9743db2ab0d99e7931f2ba1603cf9717ea668 - DRONE_GIT_ALWAYS_AUTH=false - DRONE_RUNNER_CAPACITY=2 - DRONE_SERVER_HOST=172.16.0.123:8080 - DRONE_SERVER_PROTO=http - DRONE_RPC_SECRET=secret - DRONE_TLS_AUTOCERT=false - DRONE_LOGS_DEBUG=true - DRONE_LOGS_COLOR=true restart: always networks: - default
drone-agent: image: drone/agent:latest container_name: drone-agent command: agent depends_on: - drone-server volumes: - /var/run/docker.sock:/var/run/docker.sock extra_hosts: - "git.rhel.cc:172.16.0.189" environment: - TZ=Asia/Shanghai - DRONE_RPC_SERVER=drone-server:9000 - DRONE_RPC_SECRET=secret - DRONE_RUNNER_CAPACITY=2 - DRONE_RUNNER_NAME=172.16.0.123 - DRONE_LOGS_DEBUG=true - DRONE_LOGS_COLOR=true restart: always networks: - default
networks: default:
|
登录drone,项目配置设为Trusted
编写.drone.yml文件,测试使用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| workspace: base: /go path: src/github.com/chenzihaojie/test-drone
clone: git: image: plugins/git extra_hosts: - "git.rhel.cc:172.16.0.189"
pipeline: build: image: golang environment: TZ: Asia/Shanghai volumes: - /root/.ssh/:/root/.ssh/ commands: - make - scp test-drone [email protected]:/tmp/test-drone extra_hosts: - "git.rhel.cc:172.16.0.189"
|