Skip to content

Commit 1a9eb85

Browse files
committed
fix: docker images build
1 parent a06a92f commit 1a9eb85

File tree

24 files changed

+859
-169
lines changed

24 files changed

+859
-169
lines changed

.dockerignore

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,22 @@
44
!README.md
55
.gitignore
66
.dockerignore
7-
runner-manager
8-
runner-agent
7+
/runner-manager
8+
/runner-agent
99
*.exe
1010
runners
1111
config.yaml
1212
.env
1313
*.test
1414
*.out
1515
.DS_Store
16+
17+
# Runner/Manager 镜像构建必须包含的路径(显式包含,避免被后续规则排除)
18+
!cmd
19+
!cmd/**
20+
# Manager 镜像还需 internal、配置与脚本
21+
!internal
22+
!internal/**
23+
!config.yaml.example
24+
!scripts
25+
!scripts/**

.env.example

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
# 宿主机映射端口,默认 8080
1111
# MANAGER_PORT=8080
1212
#
13-
# Job 内 Docker 使用 DinD(仅非容器模式时有效):取消下一行注释
13+
# Job 内 Docker 使用 DinD(仅非容器模式时有效)。容器模式下请勿设置此项,Manager 必须用宿主机 socket
1414
# DOCKER_HOST=tcp://runner-dind:2375
1515
#
1616
# 容器模式且 Manager 在容器内时,config.yaml 中 runners.volume_host_path 需为宿主机 runners 的绝对路径,例如:
1717
# realpath runners
1818
# echo "$(cd . && pwd)/runners"
19+
#
20+
# 容器模式:Manager 需访问宿主机 Docker(创建/启停 Runner 容器)。宿主机 docker 组 GID 与 999 不同时在此设置,例如:
21+
# DOCKER_GID=113
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# detect-go-module-root
2+
3+
Composite action:在仓库根或子目录中查找包含 `go.mod``cmd/runner-manager` 的 Go 模块根目录。
4+
5+
- **Input**`working_dir`(默认 `.`),优先检查该目录下是否有 `cmd/runner-manager`
6+
- **Output**`root`(模块根路径)、`found``true`/`false`)。
7+
8+
`ci-manager.yml``ci-agent.yml` 等复用,便于单仓或 monorepo 共用同一套 CI。
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# 检测 Go 模块根目录(含 go.mod 与 cmd/runner-manager 的目录),便于单仓或 monorepo 复用。
2+
# 使用方通过 env.WORKING_DIR 传入期望根目录(默认 .),若该目录下无 cmd/runner-manager 则自动查找。
3+
name: Detect Go module root
4+
description: 输出模块根路径 root 与是否找到 found (true/false)
5+
6+
inputs:
7+
working_dir:
8+
description: 期望的模块根目录,如 . 或子目录
9+
required: false
10+
default: .
11+
12+
outputs:
13+
root:
14+
description: 模块根目录路径
15+
value: ${{ steps.detect.outputs.root }}
16+
found:
17+
description: 是否找到 (true/false)
18+
value: ${{ steps.detect.outputs.found }}
19+
20+
runs:
21+
using: composite
22+
steps:
23+
- id: detect
24+
shell: bash
25+
run: |
26+
set -e
27+
cd "$GITHUB_WORKSPACE"
28+
WORKING_DIR="${{ inputs.working_dir }}"
29+
ROOT=""
30+
if [ -d "$GITHUB_WORKSPACE/${WORKING_DIR}/cmd/runner-manager" ]; then
31+
ROOT="${WORKING_DIR}"
32+
fi
33+
if [ -z "$ROOT" ]; then
34+
ROOT=$(find . -name go.mod 2>/dev/null | while IFS= read -r f; do
35+
d=$(dirname "$f")
36+
if [ -d "$d/cmd/runner-manager" ]; then echo "$d"; break; fi
37+
done | head -1)
38+
fi
39+
if [ -z "$ROOT" ]; then
40+
FOUND_DIR=$(find . -type d -path '*/cmd/runner-manager' 2>/dev/null | head -1)
41+
if [ -n "$FOUND_DIR" ]; then
42+
ROOT=$(dirname "$(dirname "$FOUND_DIR")")
43+
fi
44+
fi
45+
if [ -n "$ROOT" ]; then
46+
echo "root=$ROOT" >> $GITHUB_OUTPUT
47+
echo "found=true" >> $GITHUB_OUTPUT
48+
echo "Using Go module root: $ROOT"
49+
else
50+
echo "root=." >> $GITHUB_OUTPUT
51+
echo "found=false" >> $GITHUB_OUTPUT
52+
echo "::notice::No go.mod + cmd/runner-manager found, skipping."
53+
fi

.github/workflows/build.yml

Lines changed: 0 additions & 77 deletions
This file was deleted.

.github/workflows/ci-agent.yml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# CI:Runner Agent 的测试与构建
2+
name: CI (Agent)
3+
4+
on:
5+
push:
6+
branches: [main, master, develop]
7+
pull_request:
8+
branches: [main, master, develop]
9+
10+
env:
11+
GO_VERSION: "1.26.0"
12+
WORKING_DIR: .
13+
14+
jobs:
15+
test:
16+
name: Test
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v6
21+
22+
- name: Detect Go module root
23+
id: modroot
24+
uses: ./.github/actions/detect-go-module-root
25+
with:
26+
working_dir: ${{ env.WORKING_DIR }}
27+
28+
- name: Set up Go
29+
if: steps.modroot.outputs.found == 'true'
30+
uses: actions/setup-go@v6
31+
with:
32+
go-version: ${{ env.GO_VERSION }}
33+
cache-dependency-path: ${{ steps.modroot.outputs.root }}/go.sum
34+
35+
- name: Vet
36+
if: steps.modroot.outputs.found == 'true'
37+
run: go vet ./cmd/runner-agent/... ./internal/...
38+
working-directory: ${{ steps.modroot.outputs.root }}
39+
40+
- name: Lint
41+
if: steps.modroot.outputs.found == 'true'
42+
uses: golangci/golangci-lint-action@v9
43+
with:
44+
version: latest
45+
args: --max-same-issues=100000 ./cmd/runner-agent/... ./internal/...
46+
working-directory: ${{ steps.modroot.outputs.root }}
47+
48+
- name: Run tests
49+
if: steps.modroot.outputs.found == 'true'
50+
run: go test -v ./cmd/runner-agent/... ./internal/...
51+
working-directory: ${{ steps.modroot.outputs.root }}
52+
53+
- name: Skip (no project structure)
54+
if: steps.modroot.outputs.found != 'true'
55+
run: 'echo "Skipped: no go.mod + cmd/runner-agent in this repo."'
56+
57+
build:
58+
name: Build
59+
runs-on: ubuntu-latest
60+
needs: [test]
61+
timeout-minutes: 10
62+
steps:
63+
- name: Checkout code
64+
uses: actions/checkout@v6
65+
66+
- name: Detect Go module root
67+
id: modroot
68+
uses: ./.github/actions/detect-go-module-root
69+
with:
70+
working_dir: ${{ env.WORKING_DIR }}
71+
72+
- name: Set up Go
73+
if: steps.modroot.outputs.found == 'true'
74+
uses: actions/setup-go@v6
75+
with:
76+
go-version: ${{ env.GO_VERSION }}
77+
cache-dependency-path: ${{ steps.modroot.outputs.root }}/go.sum
78+
79+
- name: Build Runner Agent
80+
if: steps.modroot.outputs.found == 'true'
81+
run: go build -o runner-agent ./cmd/runner-agent
82+
working-directory: ${{ steps.modroot.outputs.root }}
83+
84+
- name: Verify binary
85+
if: steps.modroot.outputs.found == 'true'
86+
run: test -x runner-agent && ls -la runner-agent
87+
working-directory: ${{ steps.modroot.outputs.root }}
88+
89+
- name: Skip (no project structure)
90+
if: steps.modroot.outputs.found != 'true'
91+
run: 'echo "Skipped: no go.mod + cmd/runner-agent in this repo."'

.github/workflows/ci-manager.yml

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# CI:Runner Manager 的测试与构建
2+
name: CI (Manager)
3+
4+
on:
5+
push:
6+
branches: [main, master, develop]
7+
pull_request:
8+
branches: [main, master, develop]
9+
10+
env:
11+
GO_VERSION: "1.26.0"
12+
WORKING_DIR: .
13+
14+
jobs:
15+
test:
16+
name: Test
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v6
21+
22+
- name: Detect Go module root
23+
id: modroot
24+
uses: ./.github/actions/detect-go-module-root
25+
with:
26+
working_dir: ${{ env.WORKING_DIR }}
27+
28+
- name: Set up Go
29+
if: steps.modroot.outputs.found == 'true'
30+
uses: actions/setup-go@v6
31+
with:
32+
go-version: ${{ env.GO_VERSION }}
33+
cache-dependency-path: ${{ steps.modroot.outputs.root }}/go.sum
34+
35+
- name: Vet
36+
if: steps.modroot.outputs.found == 'true'
37+
run: go vet ./cmd/runner-manager/... ./internal/...
38+
working-directory: ${{ steps.modroot.outputs.root }}
39+
40+
- name: Lint
41+
if: steps.modroot.outputs.found == 'true'
42+
uses: golangci/golangci-lint-action@v9
43+
with:
44+
version: latest
45+
args: --max-same-issues=100000 ./cmd/runner-manager/... ./internal/...
46+
working-directory: ${{ steps.modroot.outputs.root }}
47+
48+
- name: Run tests
49+
if: steps.modroot.outputs.found == 'true'
50+
run: go test -v ./cmd/runner-manager/... ./internal/...
51+
working-directory: ${{ steps.modroot.outputs.root }}
52+
53+
- name: Skip (no project structure)
54+
if: steps.modroot.outputs.found != 'true'
55+
run: 'echo "Skipped: no go.mod + cmd/runner-manager in this repo."'
56+
57+
build:
58+
name: Build
59+
runs-on: ubuntu-latest
60+
needs: [test]
61+
timeout-minutes: 15
62+
steps:
63+
- name: Checkout code
64+
uses: actions/checkout@v6
65+
66+
- name: Detect Go module root
67+
id: modroot
68+
uses: ./.github/actions/detect-go-module-root
69+
with:
70+
working_dir: ${{ env.WORKING_DIR }}
71+
72+
- name: Set up Go
73+
if: steps.modroot.outputs.found == 'true'
74+
uses: actions/setup-go@v6
75+
with:
76+
go-version: ${{ env.GO_VERSION }}
77+
cache-dependency-path: ${{ steps.modroot.outputs.root }}/go.sum
78+
79+
- name: Get version information
80+
if: steps.modroot.outputs.found == 'true'
81+
id: version
82+
run: |
83+
VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "dev-$(git rev-parse --short HEAD)")
84+
echo "version=$VERSION" >> $GITHUB_OUTPUT
85+
86+
- name: Build Manager
87+
if: steps.modroot.outputs.found == 'true'
88+
run: |
89+
go build -ldflags "-s -w -X main.Version=${{ steps.version.outputs.version }}" -o runner-manager ./cmd/runner-manager
90+
working-directory: ${{ steps.modroot.outputs.root }}
91+
92+
- name: Init example config
93+
if: steps.modroot.outputs.found == 'true'
94+
run: cp config.yaml.example config.yaml
95+
working-directory: ${{ steps.modroot.outputs.root }}
96+
97+
- name: Verify binary
98+
if: steps.modroot.outputs.found == 'true'
99+
run: |
100+
./runner-manager -version
101+
./runner-manager -config config.yaml &
102+
PID=$!
103+
trap "kill $PID 2>/dev/null || true; wait $PID 2>/dev/null || true" EXIT
104+
for i in 1 2 3 4 5; do sleep 1; curl -sf http://localhost:8080/health | grep -q '"status":"ok"' && break; done
105+
curl -sf http://localhost:8080/health | grep -q '"status":"ok"' || (echo "health check failed"; exit 1)
106+
kill $PID 2>/dev/null || true
107+
wait $PID 2>/dev/null || true
108+
working-directory: ${{ steps.modroot.outputs.root }}
109+
110+
- name: Skip (no project structure)
111+
if: steps.modroot.outputs.found != 'true'
112+
run: 'echo "Skipped: no go.mod + cmd/runner-manager in this repo."'

0 commit comments

Comments
 (0)