背景
2021-07-08我成功搭建了drone+gitea,当时也想尝试直接集成drone+gitee,但发现gitee修改了配置的获取用户信息的接口路径(/api/user)为/api/v5/user,当时我给gitee提了一个issue建议支持Drone CI,但很长时间内没有结果。后来也就一直使用着自建gitea+自建drone。
搭建
昨天(即2022-05-25)看了一下drone官方文档,发现已经支持gitee。接着就尝试了一下,按照官方页面创建docker就行。
我在使用时出现两个问题。
问题一:“source code management system not configured”
(备注:图片复制自github)
发现自己是配置了GITEE_相关环境变量的。网上搜索一下,没有结果。
后来查看使用的dokcer的镜像是drone/drone:2,问题就出在这里。
因为我去年搭建drone+gitea时用的是 drone/drone:2,使用drone+gitee时并没有修改版本。当时意识到是本地没有拉取最新的镜像。
去hub.docker.com中查看,最新版本是2.12。直接修改镜像版本,正常启动drone。
问题二:拉取项目时提示“linter: untrusted repositories cannot mount host volume”
原因是当前登录用户不是超级管理员,只有超级管理员才能对项目设置trusted。
启动drone-server时添加环境变量
DRONE_USER_CREATE=xxx,machine:false,admin:true,token:${your_token}
将xxx修改成你在gitee.com的用户名即可(若你的个人页面为https://gitee.com/ABCD
,则此处应该填写ABCD)
注意事项
-
使用gitee的webhooks测试推送一直失败。但是手动在代码中添加一个空行再推送到gitee就能触发drone构建应用(怀疑是gitee在git的基础上做了改动,使用gitea时能正常使用测试推送功能)。
-
gitee中创建第三方应用的步骤为: 登录gitee -> 点击右上角个人头像 -> 设置 -> 页面搜索“第三方应用” 并点击 -> 点击 “创建应用”
- 应用主页填服务地址
- 应用回调地址填“应用主页/login”即可
- 权限,注意此时最少要勾选projects、pull_requests、hook(user_info默认必选),不然访问drone时登录会失败。错误截图如下:
贴上我使用的docker-compose.yml。可修改处以【】
明确提醒。
version: "3"
services:
drone:
image: drone/drone:2.12
container_name: drone
restart: always
ports:
- "3080:80"
- "3443:443"
environment:
- TZ=Asia/Shanghai
- LANG=en_US.utf8
- DRONE_AGENTS_ENABLED=true
- DRONE_GITEE_CLIENT_ID=【在gitee里创建第三方应用,里面有client_id】
- DRONE_GITEE_CLIENT_SECRET=【在gitee里创建第三方应用,里面有client_secret】
- DRONE_SERVER_HOST=【xxx(drone服务的域名或ip,我没试过ip)】
- DRONE_SERVER_PROTO=【http】
- DRONE_GITEE_SERVER=https://gitee.com
- DRONE_GITEE_API_SERVER=https://gitee.com/api/v5
- DRONE_RPC_SECRET=abc24eb3d61ef6ac5esed550178638db
- DRONE_USER_CREATE=username:【在gitee下的账号,作为管理员,有配置项目trusted的权限】,machine:false,admin:true,token:【用户token,随意修改】
volumes:
- /opt/docker_data/drone:/data
extra_hosts:
# 【定义一个别名,注意修改ip】
- aliyun:172.23.116.235
drone-runner-docker:
image: drone/drone-runner-docker:1
container_name: drone-runner-docker
restart: always
environment:
- TZ=Asia/Shanghai
- LANG=en_US.utf8
- DRONE_RPC_HOST=aliyun:3080
- DRONE_RPC_SECRET=abc24eb3d61ef6ac5esed550178638db
- DRONE_RPC_PROTO=http
- DRONE_RUNNER_NAME=drone-runner-docker
- DRONE_RUNNER_CAPACITY=2
volumes:
- /var/run/docker.sock:/var/run/docker.sock
extra_hosts:
# 【定义一个别名,注意修改ip】
- aliyun:172.23.116.235
问题
- 不建议使用gitee+drone,因为gitee提供的第三方应用中每日仅支持1万次调用。当超过时登录drone会报“401 Unauthorized: Application has exceeded the rate limit”。
附录
附上相关地址:
- drone: https://drone.io/
- gitea: https://gitea.io/
- gitea搭建及简单使用
- gitee: https://gitee.com/
- drone自v2.6.0已支持gitee。