InkSoul/content/stuff/drone部署和与gitea的集成.md

80 lines
2.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

---
title: "Drone部署和与gitea的集成"
date: 2023-08-07T19:09:08+08:00
---
原本的博客是直接使用的非开发模式的hugo server但随着博客内容增多内存占用巨大经历昨晚内存溢出至交换区使服务器超高磁盘IO所有服务无响应后决定将静态页面直接由原有反向代理的nginx直接托管
为了便于专注创作在gitea上引入drone CI来做简单的持续集成变得有所必要毕竟每次提交后都要手动pull和构建远远不够优雅D
本文记录drone CI的docker-compose 方式部署并与已经完成部署的gitea docker集成官方文档不推荐此种方式部署也不建议gitea和drone部署在一台服务器上预算不足暂出此策
首先需要在gitea上创建OAth2应用令牌并设置应用的重定向URL
![](../../static/images/%E6%9D%82%E7%89%A9/Drone%E9%83%A8%E7%BD%B2%E5%92%8C%E4%B8%8Egitea%E7%9A%84%E9%9B%86%E6%88%90/OAth2.png)
生成用于Drone的server和runner间通信的通信密钥
```bash
openssl rand -hex 16
```
drone-server的docker-compose文件
```yaml
version: "3"
services:
drone-server:
image: drone/drone:2.13.0
container_name: drone-server
restart: always
ports:
- "7500:80"
volumes:
- ./data:/data
environment:
- DRONE_GITEA_SERVER= Gitea 服务器地址,例如 https://gitea.inksoul.top。注意填写准确的 http(s) 协议,否则你会看到来自 Gitea 的错误报告unsupported protocol scheme
- DRONE_GITEA_CLIENT_ID=Gitea OAuth 客户端ID
- DRONE_GITEA_CLIENT_SECRET=Gitea OAuth 客户端密钥
- DRONE_RPC_SECRET=在准备工作中使用 openssl rand -hex 16 生成的共享密钥。这个密钥用于验证 Drone Server 和 Runner 之间的 RPC 连接。因此,在 Server 和 Runner 上都必须使用相同的密钥
- DRONE_SERVER_HOST=访问 Drone 时所用的域名或 IP 地址。如果使用 IP 地址,还应该包含端口
- DRONE_SERVER_PROTO=设置服务器的协议使用http 或 https。 默认为 https
- DRONE_USER_CREATE=管理员配置这里的管理员用户名是Git仓库的用户名不一定是Git仓库的管理员只要是Git仓库的用户即可例如 username:inksoul,admin:true
```
在完成域名解析绑定和nginx中反向代理设定后就可以拉取容器并启用了
nignx反向代理则在官方文档中有指出
```conf
location / {
proxy_pass http://localhost:port/;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_http_version 1.1;
proxy_buffering off;
proxy_pass_request_headers on;
}
```
完成准备后即可运行启动drone-server
```bash
docker-compose up -d
```
随后可以安装负责流水线的droen-runner
```
```