docker 持续集成
大约 126 分钟
Docker-Gitea+Drone指南
本文是Docker-Gitea+Drone的一个快速指南。
什么是Gitea?
Gitea 是一个自己托管的Git服务程序。他和GitHub, Bitbucket or Gitlab等比较类似。他是从 Gogs 发展而来,不过我们已经Fork并且命名为Gitea。对于我们Fork的原因可以看。
什么是Drone?
Drone by Harness™ 是一个现代持续集成平台,使忙碌的团队能够使用强大的云原生管道引擎自动执行其构建、测试和发布工作流。
开始配置
准备Ubuntu一台配置docker compose具体可以看Docker-compose指南篇章
sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg lsb-release
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin docker-compose
docker compose version
先上图
启动
ip:3000配置gitea
配置OAuth2生成
配置.evn文件
ip:3080配置drone
创建test仓库配置webhook测试
通过Docker Compose快速搭建Gitea+Drone
.env变量配置文件
# 时区
TZ=Asia/Shanghai
# 主机
HOST=192.168.0.108 # ip/域名
# Drone-server
DRONE_SERVER_HOST=192.168.0.108:3080 # ip/域名
DRONE_SERVER_PROTO=http # http/https
DRONE_RPC_SECRET=cd984341d2a3c961790376b75b53d453 # openssh共享密钥
# Gitea
DRONE_GITEA_CLIENT_ID=a8844d3c-ad81-42fa-8221-a8bb37698e41 # OAuth2 客户端id
DRONE_GITEA_CLIENT_SECRET=gto_vjcf65wdjfcbzk4sfgbyhs6hxt4bdvusptbn7a6c76nlw4467sba # OAuth2 客户端密钥
DRONE_GITEA_SERVER=http://192.168.0.108:3000/ # ip/域名
DRONE_DATABASE_DATASOURCE=root:gitea@tcp(mysql:3306)/gitea # 数据库
DRONE_DATABASE_DRIVER=mysql # 数据库驱动
# Drone-runner-docker
DRONE_RPC_PROTO=http # http/https
DRONE_RUNNER_CAPACITY=2
DRONE_RUNNER_NAME=docker-runner
docker-compose.yml
version: "3.7"
services:
mysql:
container_name: mysql
image: mysql:5.7.27
restart: always
ports:
- "3306:3306"
volumes:
- ./mysql/data:/var/lib/mysql:rw
- ./mysql/logs:/var/log/mysql:rw
environment:
- TZ=${TZ}
- MYSQL_ROOT_PASSWORD=gitea
- MYSQL_USER=gitea
- MYSQL_PASSWORD=gitea
- MYSQL_DATABASE=gitea
gitea:
container_name: gitea
image: gitea/gitea:latest
restart: always
ports:
- "3000:3000"
- "3022:22"
environment:
- TZ=${TZ}
- USER_UID=1000
- USER_GID=1000
- DB_TYPE=mysql
- DB_HOST=${HOST}:3306
- DB_NAME=gitea
- DB_USER=gitea
volumes:
- ./gitea:/data
drone-server:
container_name: drone-server
image: drone/drone:latest
restart: always
ports:
- "3080:80"
volumes:
- ./drone:/var/lib/drone/
- /var/run/docker.sock:/var/run/docker.sock
environment:
- TZ=${TZ}
- DRONE_SERVER_HOST=${DRONE_SERVER_HOST}
- DRONE_SERVER_PROTO=${DRONE_SERVER_PROTO}
- DRONE_RPC_SECRET=${DRONE_RPC_SECRET}
# Gitea Config
- DRONE_GITEA_CLIENT_ID=${DRONE_GITEA_CLIENT_ID}
- DRONE_GITEA_CLIENT_SECRET=${DRONE_GITEA_CLIENT_SECRET}
- DRONE_GITEA_SERVER=${DRONE_GITEA_SERVER}
- DRONE_DATABASE_DATASOURCE=${DRONE_DATABASE_DATASOURCE}
- DRONE_DATABASE_DRIVER=${DRONE_DATABASE_DRIVER}
- DRONE_USER_CREATE=username:gitea,admin:true #username是管理员账号
drone-runner-docker:
container_name: drone-runner-docker
image: drone/drone-runner-docker:latest
restart: always
depends_on:
- drone-server
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
- TZ=${TZ}
- DRONE_RPC_HOST=drone-server
- DRONE_RPC_PROTO=${DRONE_RPC_PROTO}
- DRONE_RPC_SECRET=${DRONE_RPC_SECRET}
- DRONE_RUNNER_CAPACITY=${DRONE_RUNNER_CAPACITY}
- DRONE_RUNNER_NAME=${DRONE_RUNNER_NAME}
修改 Gitea 容器内的 conf/app.ini
[webhook]
ALLOWED_HOST_LIST = *
创建共享密钥给DRONE_RPC_SECRET
openssl rand -hex 16
.drone.yml测试
kind: pipeline
name: default
steps:
- name: Hello World
image: centos
commands:
- echo Hello World