🔧 参数化实例配置并补充 preset env 示例
This commit is contained in:
parent
ac05621817
commit
a4d09c9063
|
|
@ -43,7 +43,7 @@ env:
|
|||
|
||||
# ===== 服务器配置 =====
|
||||
# Gitea 服务器地址(用于生成头像链接和 API 调用)
|
||||
GITEA_SERVER: "https://git.mytsl.cn"
|
||||
GITEA_SERVER: "${{ github.server_url }}"
|
||||
|
||||
# ===== CHANGELOG 配置 =====
|
||||
# CHANGELOG 变更列表标题
|
||||
|
|
|
|||
|
|
@ -59,13 +59,13 @@ env:
|
|||
# 平台类型: github 或 gitea
|
||||
PLATFORM: "gitea"
|
||||
# Git 服务器 URL(Gitea 示例: https://gitea.example.com)
|
||||
GIT_SERVER_URL: "https://git.mytsl.cn"
|
||||
GIT_SERVER_URL: "${{ github.server_url }}"
|
||||
# 仓库路径(格式: owner/repo)
|
||||
REPO_PATH: "${{ github.repository }}"
|
||||
# Raw 文件基础 URL
|
||||
# GitHub: https://raw.githubusercontent.com/{owner}/{repo}/{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'
|
||||
|
||||
# ==========================================
|
||||
# 🎨 语言分组配置
|
||||
|
|
|
|||
|
|
@ -18,3 +18,6 @@ Sessionx.vim
|
|||
tags
|
||||
# Persistent undo
|
||||
[._]*.un~
|
||||
|
||||
# Environment files
|
||||
.env
|
||||
|
|
|
|||
|
|
@ -118,7 +118,15 @@ docker-runner/
|
|||
cd docker-runner/presets/standard-ubuntu-22/
|
||||
```
|
||||
|
||||
#### 2. (可选)检查换行符
|
||||
#### 2. 准备实例配置
|
||||
|
||||
```bash
|
||||
cp .env.example .env
|
||||
```
|
||||
|
||||
按需编辑 `.env` 中的 `GITEA_INSTANCE` 和 `GITEA_TOKEN`。
|
||||
|
||||
#### 3. (可选)检查换行符
|
||||
|
||||
如果从 Windows 复制文件,建议检查换行符:
|
||||
|
||||
|
|
@ -126,14 +134,14 @@ cd docker-runner/presets/standard-ubuntu-22/
|
|||
../../common/check_crlf.sh
|
||||
```
|
||||
|
||||
#### 3. 构建并启动容器
|
||||
#### 4. 构建并启动容器
|
||||
|
||||
```bash
|
||||
docker compose build
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
#### 4. 安装 Runner
|
||||
#### 5. 安装 Runner
|
||||
|
||||
```bash
|
||||
docker compose exec gitea-runner /data/setup.sh
|
||||
|
|
@ -141,7 +149,7 @@ docker compose exec gitea-runner /data/setup.sh
|
|||
|
||||
脚本会自动探测最新 `act_runner` 版本作为默认值,然后提示你确认架构。
|
||||
|
||||
#### 5. 注册 Runner
|
||||
#### 6. 注册 Runner
|
||||
|
||||
```bash
|
||||
docker compose exec gitea-runner /data/register.sh
|
||||
|
|
@ -151,7 +159,7 @@ docker compose exec gitea-runner /data/register.sh
|
|||
|
||||
Runner 注册后会自动启动,无需重启容器。新注册的 runner 默认并发为 `4`。
|
||||
|
||||
#### 6. 验证运行状态
|
||||
#### 7. 验证运行状态
|
||||
|
||||
```bash
|
||||
# 查看容器日志
|
||||
|
|
@ -175,7 +183,15 @@ cd docker-runner/presets/buildx-ubuntu-22/
|
|||
cd docker-runner/presets/buildx-archlinux/
|
||||
```
|
||||
|
||||
#### 2. (可选)配置代理
|
||||
#### 2. 准备实例配置
|
||||
|
||||
```bash
|
||||
cp .env.example .env
|
||||
```
|
||||
|
||||
按需编辑 `.env` 中的 `GITEA_INSTANCE` 和 `GITEA_TOKEN`。
|
||||
|
||||
#### 3. (可选)配置代理
|
||||
|
||||
如果需要代理,编辑 `docker-compose.yml` 取消注释并修改代理地址:
|
||||
|
||||
|
|
@ -185,14 +201,14 @@ environment:
|
|||
- https_proxy=http://host.docker.internal:20122
|
||||
```
|
||||
|
||||
#### 3. 构建并启动
|
||||
#### 4. 构建并启动
|
||||
|
||||
```bash
|
||||
docker compose build
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
#### 4. 验证 Buildx 初始化
|
||||
#### 5. 验证 Buildx 初始化
|
||||
|
||||
```bash
|
||||
# 查看日志,应该看到:
|
||||
|
|
@ -207,7 +223,7 @@ docker compose exec gitea-runner docker buildx ls
|
|||
# 应该看到 gitea-multiarch builder
|
||||
```
|
||||
|
||||
#### 5. 安装和注册
|
||||
#### 6. 安装和注册
|
||||
|
||||
```bash
|
||||
docker compose exec gitea-runner /data/setup.sh
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
- 大仓库会缓存到 `/data/git-mirrors/<owner>/<repo>.git`
|
||||
- 每个 workflow job 使用独立临时目录 `/home/workspace/jobs/<owner>/<repo>/<job-identity>/repo`
|
||||
- job 结束后会自动清理临时工作目录,mirror 缓存保留在 `runner-data/`
|
||||
- 每个 preset 通过 `.env.example` 提供公司默认实例值,部署时复制为 `.env` 即可
|
||||
|
||||
## 📂 文档导航
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
GITEA_INSTANCE=https://git.mytsl.cn
|
||||
GITEA_TOKEN=
|
||||
|
|
@ -21,8 +21,8 @@ services:
|
|||
# Arch Linux Buildx 配置 - 使用 tonistiigi/binfmt
|
||||
- ENABLE_BUILDX=true
|
||||
- BINFMT_METHOD=tonistiigi
|
||||
- GITEA_INSTANCE=https://git.mytsl.cn
|
||||
- GITEA_TOKEN=
|
||||
- GITEA_INSTANCE=${GITEA_INSTANCE}
|
||||
- GITEA_TOKEN=${GITEA_TOKEN}
|
||||
- DEFAULT_RUNNER_NAME=buildx-archlinux
|
||||
- DEFAULT_RUNNER_LABEL=archlinux:host://archlinux:latest,company-server:host://archlinux:latest,buildx-archlinux:host://archlinux:latest
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
GITEA_INSTANCE=https://git.mytsl.cn
|
||||
GITEA_TOKEN=
|
||||
|
|
@ -20,8 +20,8 @@ services:
|
|||
|
||||
# Buildx 配置 - 启用多架构构建
|
||||
- ENABLE_BUILDX=true
|
||||
- GITEA_INSTANCE=https://git.mytsl.cn
|
||||
- GITEA_TOKEN=
|
||||
- GITEA_INSTANCE=${GITEA_INSTANCE}
|
||||
- GITEA_TOKEN=${GITEA_TOKEN}
|
||||
- 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
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
GITEA_INSTANCE=https://git.mytsl.cn
|
||||
GITEA_TOKEN=
|
||||
|
|
@ -18,8 +18,8 @@ services:
|
|||
|
||||
# Standard 配置 - 不启用 Buildx
|
||||
- ENABLE_BUILDX=false
|
||||
- GITEA_INSTANCE=https://git.mytsl.cn
|
||||
- GITEA_TOKEN=
|
||||
- GITEA_INSTANCE=${GITEA_INSTANCE}
|
||||
- GITEA_TOKEN=${GITEA_TOKEN}
|
||||
- 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
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
Loading…
Reference in New Issue