🔧 参数化实例配置并补充 preset env 示例

This commit is contained in:
csh 2026-05-22 09:45:35 +08:00
parent ac05621817
commit a4d09c9063
12 changed files with 90 additions and 18 deletions

View File

@ -43,7 +43,7 @@ env:
# ===== 服务器配置 ===== # ===== 服务器配置 =====
# Gitea 服务器地址(用于生成头像链接和 API 调用) # Gitea 服务器地址(用于生成头像链接和 API 调用)
GITEA_SERVER: "https://git.mytsl.cn" GITEA_SERVER: "${{ github.server_url }}"
# ===== CHANGELOG 配置 ===== # ===== CHANGELOG 配置 =====
# CHANGELOG 变更列表标题 # CHANGELOG 变更列表标题

View File

@ -59,13 +59,13 @@ env:
# 平台类型: github 或 gitea # 平台类型: github 或 gitea
PLATFORM: "gitea" PLATFORM: "gitea"
# Git 服务器 URLGitea 示例: https://gitea.example.com # Git 服务器 URLGitea 示例: https://gitea.example.com
GIT_SERVER_URL: "https://git.mytsl.cn" GIT_SERVER_URL: "${{ github.server_url }}"
# 仓库路径(格式: owner/repo # 仓库路径(格式: owner/repo
REPO_PATH: "${{ github.repository }}" REPO_PATH: "${{ github.repository }}"
# Raw 文件基础 URL # Raw 文件基础 URL
# GitHub: https://raw.githubusercontent.com/{owner}/{repo}/{branch}/{path} # GitHub: https://raw.githubusercontent.com/{owner}/{repo}/{branch}/{path}
# Gitea: https://gitea.example.com/{owner}/{repo}/raw/branch/{branch}/{path} # Gitea: https://gitea.example.com/{owner}/{repo}/raw/branch/{branch}/{path}
RAW_URL_BASE: 'https://git.mytsl.cn/${{ github.repository }}/raw/branch' RAW_URL_BASE: '${{ github.server_url }}/${{ github.repository }}/raw/branch'
# ========================================== # ==========================================
# 🎨 语言分组配置 # 🎨 语言分组配置

3
.gitignore vendored
View File

@ -18,3 +18,6 @@ Sessionx.vim
tags tags
# Persistent undo # Persistent undo
[._]*.un~ [._]*.un~
# Environment files
.env

View File

@ -118,7 +118,15 @@ docker-runner/
cd docker-runner/presets/standard-ubuntu-22/ cd docker-runner/presets/standard-ubuntu-22/
``` ```
#### 2. (可选)检查换行符 #### 2. 准备实例配置
```bash
cp .env.example .env
```
按需编辑 `.env` 中的 `GITEA_INSTANCE``GITEA_TOKEN`
#### 3. (可选)检查换行符
如果从 Windows 复制文件,建议检查换行符: 如果从 Windows 复制文件,建议检查换行符:
@ -126,14 +134,14 @@ cd docker-runner/presets/standard-ubuntu-22/
../../common/check_crlf.sh ../../common/check_crlf.sh
``` ```
#### 3. 构建并启动容器 #### 4. 构建并启动容器
```bash ```bash
docker compose build docker compose build
docker compose up -d docker compose up -d
``` ```
#### 4. 安装 Runner #### 5. 安装 Runner
```bash ```bash
docker compose exec gitea-runner /data/setup.sh docker compose exec gitea-runner /data/setup.sh
@ -141,7 +149,7 @@ docker compose exec gitea-runner /data/setup.sh
脚本会自动探测最新 `act_runner` 版本作为默认值,然后提示你确认架构。 脚本会自动探测最新 `act_runner` 版本作为默认值,然后提示你确认架构。
#### 5. 注册 Runner #### 6. 注册 Runner
```bash ```bash
docker compose exec gitea-runner /data/register.sh docker compose exec gitea-runner /data/register.sh
@ -151,7 +159,7 @@ docker compose exec gitea-runner /data/register.sh
Runner 注册后会自动启动,无需重启容器。新注册的 runner 默认并发为 `4` Runner 注册后会自动启动,无需重启容器。新注册的 runner 默认并发为 `4`
#### 6. 验证运行状态 #### 7. 验证运行状态
```bash ```bash
# 查看容器日志 # 查看容器日志
@ -175,7 +183,15 @@ cd docker-runner/presets/buildx-ubuntu-22/
cd docker-runner/presets/buildx-archlinux/ cd docker-runner/presets/buildx-archlinux/
``` ```
#### 2. (可选)配置代理 #### 2. 准备实例配置
```bash
cp .env.example .env
```
按需编辑 `.env` 中的 `GITEA_INSTANCE``GITEA_TOKEN`
#### 3. (可选)配置代理
如果需要代理,编辑 `docker-compose.yml` 取消注释并修改代理地址: 如果需要代理,编辑 `docker-compose.yml` 取消注释并修改代理地址:
@ -185,14 +201,14 @@ environment:
- https_proxy=http://host.docker.internal:20122 - https_proxy=http://host.docker.internal:20122
``` ```
#### 3. 构建并启动 #### 4. 构建并启动
```bash ```bash
docker compose build docker compose build
docker compose up -d docker compose up -d
``` ```
#### 4. 验证 Buildx 初始化 #### 5. 验证 Buildx 初始化
```bash ```bash
# 查看日志,应该看到: # 查看日志,应该看到:
@ -207,7 +223,7 @@ docker compose exec gitea-runner docker buildx ls
# 应该看到 gitea-multiarch builder # 应该看到 gitea-multiarch builder
``` ```
#### 5. 安装和注册 #### 6. 安装和注册
```bash ```bash
docker compose exec gitea-runner /data/setup.sh docker compose exec gitea-runner /data/setup.sh

View File

@ -19,6 +19,7 @@
- 大仓库会缓存到 `/data/git-mirrors/<owner>/<repo>.git` - 大仓库会缓存到 `/data/git-mirrors/<owner>/<repo>.git`
- 每个 workflow job 使用独立临时目录 `/home/workspace/jobs/<owner>/<repo>/<job-identity>/repo` - 每个 workflow job 使用独立临时目录 `/home/workspace/jobs/<owner>/<repo>/<job-identity>/repo`
- job 结束后会自动清理临时工作目录mirror 缓存保留在 `runner-data/` - job 结束后会自动清理临时工作目录mirror 缓存保留在 `runner-data/`
- 每个 preset 通过 `.env.example` 提供公司默认实例值,部署时复制为 `.env` 即可
## 📂 文档导航 ## 📂 文档导航

View File

@ -0,0 +1,2 @@
GITEA_INSTANCE=https://git.mytsl.cn
GITEA_TOKEN=

View File

@ -21,8 +21,8 @@ services:
# Arch Linux Buildx 配置 - 使用 tonistiigi/binfmt # Arch Linux Buildx 配置 - 使用 tonistiigi/binfmt
- ENABLE_BUILDX=true - ENABLE_BUILDX=true
- BINFMT_METHOD=tonistiigi - BINFMT_METHOD=tonistiigi
- GITEA_INSTANCE=https://git.mytsl.cn - GITEA_INSTANCE=${GITEA_INSTANCE}
- GITEA_TOKEN= - GITEA_TOKEN=${GITEA_TOKEN}
- DEFAULT_RUNNER_NAME=buildx-archlinux - DEFAULT_RUNNER_NAME=buildx-archlinux
- DEFAULT_RUNNER_LABEL=archlinux:host://archlinux:latest,company-server:host://archlinux:latest,buildx-archlinux:host://archlinux:latest - DEFAULT_RUNNER_LABEL=archlinux:host://archlinux:latest,company-server:host://archlinux:latest,buildx-archlinux:host://archlinux:latest

View File

@ -0,0 +1,2 @@
GITEA_INSTANCE=https://git.mytsl.cn
GITEA_TOKEN=

View File

@ -20,8 +20,8 @@ services:
# Buildx 配置 - 启用多架构构建 # Buildx 配置 - 启用多架构构建
- ENABLE_BUILDX=true - ENABLE_BUILDX=true
- GITEA_INSTANCE=https://git.mytsl.cn - GITEA_INSTANCE=${GITEA_INSTANCE}
- GITEA_TOKEN= - GITEA_TOKEN=${GITEA_TOKEN}
- DEFAULT_RUNNER_NAME=buildx-ubuntu-22 - DEFAULT_RUNNER_NAME=buildx-ubuntu-22
- DEFAULT_RUNNER_LABEL=ubuntu-22.04:host://ubuntu:22.04,company-server:host://ubuntu:22.04,buildx-ubuntu-22:host://ubuntu:22.04 - DEFAULT_RUNNER_LABEL=ubuntu-22.04:host://ubuntu:22.04,company-server:host://ubuntu:22.04,buildx-ubuntu-22:host://ubuntu:22.04

View File

@ -0,0 +1,2 @@
GITEA_INSTANCE=https://git.mytsl.cn
GITEA_TOKEN=

View File

@ -18,8 +18,8 @@ services:
# Standard 配置 - 不启用 Buildx # Standard 配置 - 不启用 Buildx
- ENABLE_BUILDX=false - ENABLE_BUILDX=false
- GITEA_INSTANCE=https://git.mytsl.cn - GITEA_INSTANCE=${GITEA_INSTANCE}
- GITEA_TOKEN= - GITEA_TOKEN=${GITEA_TOKEN}
- DEFAULT_RUNNER_NAME=standard-ubuntu-22 - DEFAULT_RUNNER_NAME=standard-ubuntu-22
- DEFAULT_RUNNER_LABEL=ubuntu-22.04:host://ubuntu:22.04,company-server:host://ubuntu:22.04,standard-ubuntu-22:host://ubuntu:22.04 - DEFAULT_RUNNER_LABEL=ubuntu-22.04:host://ubuntu:22.04,company-server:host://ubuntu:22.04,standard-ubuntu-22:host://ubuntu:22.04

View File

@ -0,0 +1,46 @@
#!/bin/bash
set -euo pipefail
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
REPO_ROOT=$(cd "${SCRIPT_DIR}/.." && pwd)
fail() {
echo "FAIL: $*" >&2
exit 1
}
test_preset_compose_uses_env_for_instance() {
local file
for file in \
"${REPO_ROOT}/docker-runner/presets/standard-ubuntu-22/docker-compose.yml" \
"${REPO_ROOT}/docker-runner/presets/buildx-ubuntu-22/docker-compose.yml" \
"${REPO_ROOT}/docker-runner/presets/buildx-archlinux/docker-compose.yml"; do
grep -q 'GITEA_INSTANCE=${GITEA_INSTANCE}' "${file}" || fail "${file} should read GITEA_INSTANCE from env"
grep -q 'GITEA_TOKEN=${GITEA_TOKEN}' "${file}" || fail "${file} should read GITEA_TOKEN from env"
done
}
test_workflows_do_not_hardcode_company_server() {
! rg -q 'https://git\.mytsl\.cn' "${REPO_ROOT}/.gitea/workflows/changelog_and_release.yml" || fail "changelog workflow should not hardcode company server"
! rg -q 'https://git\.mytsl\.cn' "${REPO_ROOT}/.gitea/workflows/update_stats_badge.yaml" || fail "stats workflow should not hardcode company server"
}
test_preset_env_examples_exist() {
local file
for file in \
"${REPO_ROOT}/docker-runner/presets/standard-ubuntu-22/.env.example" \
"${REPO_ROOT}/docker-runner/presets/buildx-ubuntu-22/.env.example" \
"${REPO_ROOT}/docker-runner/presets/buildx-archlinux/.env.example"; do
test -f "${file}" || fail "missing env example: ${file}"
grep -q '^GITEA_INSTANCE=https://git.mytsl.cn$' "${file}" || fail "${file} should include company default instance"
grep -q '^GITEA_TOKEN=$' "${file}" || fail "${file} should include empty token placeholder"
done
}
test_preset_compose_uses_env_for_instance
test_workflows_do_not_hardcode_company_server
test_preset_env_examples_exist
echo "template_defaults_test.sh: PASS"