synchronization

This commit is contained in:
2025-08-25 17:53:08 +08:00
commit c201eb5ef9
318 changed files with 23092 additions and 0 deletions

178
Helm/Helm部署Drone.md Normal file
View File

@@ -0,0 +1,178 @@
> 本文作者:丁辉
# Helm部署Drone
[官方文档](https://docs.drone.io/)
[官方中文文档](https://drone.cool/)
## 介绍
**Drone 是一个开源的持续集成和持续部署CI/CD平台广泛用于自动化代码构建、测试和发布流程**
## 开始部署
1. 添加 Drone Helm Chart 存储库
```bash
helm repo add drone https://charts.drone.io
helm repo update
```
2. 创建命名空间
```bash
kubectl create namespace drone
```
3. 部署 Postgres
```bash
kubectl apply -f https://gitee.com/offends/Kubernetes/raw/main/File/Yaml/drone-postgres.yaml
```
4. 生成密钥
```bash
openssl rand -hex 16
```
5. 进入 Github 创建 OAuth2 应用获取 `DRONE_GITHUB_CLIENT_ID` 和 `DRONE_GITHUB_CLIENT_SECRET`
6. 生成 Secret
> 对接 Gitea 参数替换如下:
>
> DRONE_GITEA_CLIENT_ID
>
> DRONE_GITEA_CLIENT_SECRET
```bash
kubectl create secret generic drone-secret \
--from-literal=DRONE_RPC_SECRET=填入密钥 \
--from-literal=DRONE_GITHUB_CLIENT_ID=填入Github-ID \
--from-literal=DRONE_GITHUB_CLIENT_SECRET=填入Github-SECRET \
--from-literal=DRONE_GIT_USERNAME=配置Github用户名 \
--from-literal=DRONE_GIT_PASSWORD=配置Github密码 \
--from-literal=DRONE_USER_CREATE=username:填入管理员用户名,admin:true \
-n drone
```
**参数解释**
| 参数 | 描述 |
| ----------------------------- | ------------------------------------------------------------ |
| `DRONE_RPC_SECRET=` | 将名为`DRONE_RPC_SECRET`的密钥添加到Secret中用于Drone CI/CD工具的RPC通信和验证。 |
| `DRONE_GITHUB_CLIENT_ID=` | 将GitHub OAuth应用程序的客户端ID添加到Secret中。 |
| `DRONE_GITHUB_CLIENT_SECRET=` | 将GitHub OAuth应用程序的客户端密钥添加到Secret中。 |
| `DRONE_GIT_USERNAME=` | 将GitHub用户名添加到Secret中用于访问GitHub仓库。 |
| `DRONE_GIT_PASSWORD=` | 将GitHub密码添加到Secret中用于访问GitHub仓库。 |
| `DRONE_USER_CREATE=username:` | 指定在Drone启动时创建的用户信息包括用户名和角色管理员。 |
7. 编写模版文件
> 对接 Gitea 参数替换如下:
>
> DRONE_GITEA_SERVER
```bash
vi drone-values.yaml
```
内容如下
```yaml
# 开启 ingress 对外访问
ingress:
enabled: true
className: "" # 指定 ingress 控制器, 不指定则需要集群内存在默认的 ingress 控制器
hosts:
- host: # 域名
paths:
- path: /
pathType: Prefix
tls:
- secretName: drone-tls
hosts:
- # 域名
env:
DRONE_GITHUB_SERVER: https://github.com #仓库地址
DRONE_SERVER_HOST: #域名
DRONE_SERVER_PROTO: https
DRONE_DATABASE_DRIVER: postgres
DRONE_DATABASE_DATASOURCE: postgres://postgres:postgres@drone-db:5432/drone?sslmode=disable
extraSecretNamesForEnvFrom:
- drone-secret
persistentVolume:
enabled: false
```
> 其他参数
>
> ```bash
> # oauth会验证gitlab证书如果验证不过需要打开
> DRONE_GITLAB_SKIP_VERIFY: true
> ```
8. 安装
```bash
helm install drone drone/drone -f drone-values.yaml -n drone
```
## 卸载
1. 卸载 drone
```bash
helm uninstall drone -n drone
```
2. 删除 secret
```bash
kubectl delete secret drone-secret -n drone
```
3. 删除命名空间
```bash
kubectl delete namespace drone
```
# 问题记录
> 2025-8-25遇到 Drone 对接 Gitea 时报错
>
> ```bash
> You will be redirected to your source control management system to authenticate
> ```
## 根本原因
- Gitea 将 Drone 的 OAuth2 应用识别为 **Public Client公开客户端**,默认要求 **PKCEProof Key for Code Exchange**。
- Drone 作为传统 CI/CD 工具不支持 PKCE因此在交换授权码时Gitea拒绝了请求返回 `invalid_request` 和 `PKCE is required for public clients`。
------
## 解决思路
1. 确认 Gitea 日志中报错 `PKCE is required for public clients`,确定是 Gitea OAuth2 客户端类型问题。
2. 将 Drone 在 Gitea 中注册的 OAuth2 应用改为 **Confidential Client机密客户端**,避免 PKCE 校验。
3. 更新 Drone 使用新的 Client ID / Secret确保 OAuth2 授权流程可用。
------
## 最终解决方案
1. **在 Gitea 中重新创建 OAuth2 应用**
- 登录 Gitea → `Settings` → `Applications` → `Manage OAuth2 Applications` → `New OAuth2 Application`
- **Redirect URI**`https://域名/login`
- **勾选 Confidential Client机密客户端**
- 保存并获取新的 **Client ID** 和 **Client Secret**。
2. **更新 Drone 配置**
- 在 Kubernetes Secret 中更新
- 重启 Drone 服务。
3. **重新访问 Drone**
- 打开 `https://域名/login` ,用 Gitea 登录授权,验证 OAuth2 流程正常完成。