Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c7dfd1c149 | ||
|
|
9d0b60643c | ||
|
|
8fab783aa9 |
17
Dockerfile.custom
Normal file
17
Dockerfile.custom
Normal file
@@ -0,0 +1,17 @@
|
||||
FROM debian:bookworm-slim
|
||||
|
||||
# 安装必要的工具
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates curl git && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# 复制自定义编译的 act_runner
|
||||
# 注意:构建前需要先确保当前目录下有编译好的 act_runner 二进制文件
|
||||
COPY act_runner /usr/local/bin/act_runner
|
||||
RUN chmod +x /usr/local/bin/act_runner
|
||||
|
||||
# 创建数据目录
|
||||
RUN mkdir -p /data/cache
|
||||
|
||||
WORKDIR /data
|
||||
|
||||
ENTRYPOINT ["/usr/local/bin/act_runner"]
|
||||
CMD ["daemon", "--config", "/config.yaml"]
|
||||
@@ -24,11 +24,12 @@ type cacheServerArgs struct {
|
||||
|
||||
func runCacheServer(ctx context.Context, configFile *string, cacheArgs *cacheServerArgs) func(cmd *cobra.Command, args []string) error {
|
||||
return func(cmd *cobra.Command, args []string) error {
|
||||
fmt.Println("cache1")
|
||||
cfg, err := config.LoadDefault(*configFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid configuration: %w", err)
|
||||
}
|
||||
|
||||
fmt.Println("cache2")
|
||||
initLogging(cfg)
|
||||
|
||||
var (
|
||||
@@ -47,7 +48,7 @@ func runCacheServer(ctx context.Context, configFile *string, cacheArgs *cacheSer
|
||||
if cacheArgs.Port != 0 {
|
||||
port = cacheArgs.Port
|
||||
}
|
||||
|
||||
fmt.Println("cache2")
|
||||
cacheHandler, err := artifactcache.StartHandler(
|
||||
dir,
|
||||
host,
|
||||
|
||||
@@ -15,6 +15,8 @@ import (
|
||||
)
|
||||
|
||||
func Execute(ctx context.Context) {
|
||||
configFile := ""
|
||||
|
||||
// ./act_runner
|
||||
rootCmd := &cobra.Command{
|
||||
Use: "act_runner [event name to run]\nIf no event name passed, will default to \"on: push\"",
|
||||
@@ -22,8 +24,16 @@ func Execute(ctx context.Context) {
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
Version: ver.Version(),
|
||||
SilenceUsage: true,
|
||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
// Auto-detect config.yaml if not specified
|
||||
if configFile == "" {
|
||||
if _, err := os.Stat("config.yaml"); err == nil {
|
||||
configFile = "config.yaml"
|
||||
}
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
configFile := ""
|
||||
rootCmd.PersistentFlags().StringVarP(&configFile, "config", "c", "", "Config file path")
|
||||
|
||||
// ./act_runner register
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -38,6 +39,8 @@ type Runner struct {
|
||||
labels labels.Labels
|
||||
envs map[string]string
|
||||
|
||||
useHostDockerInternal bool
|
||||
|
||||
runningTasks sync.Map
|
||||
}
|
||||
|
||||
@@ -52,9 +55,14 @@ func NewRunner(cfg *config.Config, reg *config.Registration, cli client.Client)
|
||||
for k, v := range cfg.Runner.Envs {
|
||||
envs[k] = v
|
||||
}
|
||||
// Setup cache
|
||||
useHostDockerInternal := false
|
||||
if cfg.Cache.Enabled == nil || *cfg.Cache.Enabled {
|
||||
if cfg.Cache.ExternalServer != "" {
|
||||
envs["ACTIONS_CACHE_URL"] = cfg.Cache.ExternalServer
|
||||
if strings.Contains(cfg.Cache.ExternalServer, "host.docker.internal") {
|
||||
useHostDockerInternal = true
|
||||
}
|
||||
} else {
|
||||
cacheHandler, err := artifactcache.StartHandler(
|
||||
cfg.Cache.Dir,
|
||||
@@ -66,7 +74,16 @@ func NewRunner(cfg *config.Config, reg *config.Registration, cli client.Client)
|
||||
log.Errorf("cannot init cache server, it will be disabled: %v", err)
|
||||
// go on
|
||||
} else {
|
||||
envs["ACTIONS_CACHE_URL"] = cacheHandler.ExternalURL() + "/"
|
||||
// Use host.docker.internal for container access
|
||||
externalURL := cacheHandler.ExternalURL()
|
||||
if parsedURL, err := url.Parse(externalURL); err == nil {
|
||||
parsedURL.Host = "host.docker.internal:" + parsedURL.Port()
|
||||
envs["ACTIONS_CACHE_URL"] = parsedURL.String() + "/"
|
||||
} else {
|
||||
envs["ACTIONS_CACHE_URL"] = externalURL + "/"
|
||||
}
|
||||
useHostDockerInternal = true
|
||||
log.Infof("Cache server started at %s, using host.docker.internal for container access", externalURL)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -81,11 +98,12 @@ func NewRunner(cfg *config.Config, reg *config.Registration, cli client.Client)
|
||||
envs["GITEA_ACTIONS_RUNNER_VERSION"] = ver.Version()
|
||||
|
||||
return &Runner{
|
||||
name: reg.Name,
|
||||
cfg: cfg,
|
||||
client: cli,
|
||||
labels: ls,
|
||||
envs: envs,
|
||||
name: reg.Name,
|
||||
cfg: cfg,
|
||||
client: cli,
|
||||
labels: ls,
|
||||
envs: envs,
|
||||
useHostDockerInternal: useHostDockerInternal,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,6 +215,17 @@ func (r *Runner) run(ctx context.Context, task *runnerv1.Task, reporter *report.
|
||||
maxLifetime = time.Until(deadline)
|
||||
}
|
||||
|
||||
// Auto-add host.docker.internal if cache is enabled
|
||||
containerOptions := r.cfg.Container.Options
|
||||
if r.useHostDockerInternal {
|
||||
if containerOptions == "" {
|
||||
containerOptions = "--add-host=host.docker.internal:host-gateway"
|
||||
} else if !strings.Contains(containerOptions, "--add-host=host.docker.internal") {
|
||||
containerOptions += " --add-host=host.docker.internal:host-gateway"
|
||||
}
|
||||
log.Infof("Auto-added host.docker.internal mapping for cache: %s", containerOptions)
|
||||
}
|
||||
|
||||
runnerConfig := &runner.Config{
|
||||
// On Linux, Workdir will be like "/<parent_directory>/<owner>/<repo>"
|
||||
// On Windows, Workdir will be like "\<parent_directory>\<owner>\<repo>"
|
||||
@@ -219,7 +248,7 @@ func (r *Runner) run(ctx context.Context, task *runnerv1.Task, reporter *report.
|
||||
ContainerNamePrefix: fmt.Sprintf("GITEA-ACTIONS-TASK-%d", task.Id),
|
||||
ContainerMaxLifetime: maxLifetime,
|
||||
ContainerNetworkMode: container.NetworkMode(r.cfg.Container.Network),
|
||||
ContainerOptions: r.cfg.Container.Options,
|
||||
ContainerOptions: containerOptions,
|
||||
ContainerDaemonSocket: r.cfg.Container.DockerHost,
|
||||
Privileged: r.cfg.Container.Privileged,
|
||||
DefaultActionInstance: r.getDefaultActionsURL(ctx, task),
|
||||
|
||||
Reference in New Issue
Block a user