Config for container network (#96)

Fix #66

Reviewed-on: https://gitea.com/gitea/act_runner/pulls/96
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
pull/23/head
Jason Song 2023-04-04 14:32:01 +08:00 committed by Earl Warren
parent c817236aa4
commit 7c1801b302
No known key found for this signature in database
GPG Key ID: 0579CB2928A78A00
5 changed files with 15 additions and 3 deletions

View File

@ -71,6 +71,7 @@ func runDaemon(ctx context.Context, configFile *string) func(cmd *cobra.Command,
ForgeInstance: reg.Address, ForgeInstance: reg.Address,
Environ: cfg.Runner.Envs, Environ: cfg.Runner.Envs,
Labels: reg.Labels, Labels: reg.Labels,
Network: cfg.Container.Network,
Version: version, Version: version,
} }

View File

@ -36,3 +36,7 @@ cache:
# The port of the cache server. # The port of the cache server.
# 0 means to use a random available port. # 0 means to use a random available port.
port: 0 port: 0
container:
# Which network to use for the job containers.
network: bridge

View File

@ -28,6 +28,9 @@ type Config struct {
Host string `yaml:"host"` Host string `yaml:"host"`
Port uint16 `yaml:"port"` Port uint16 `yaml:"port"`
} `yaml:"cache"` } `yaml:"cache"`
Container struct {
Network string `yaml:"network"`
}
} }
// LoadDefault returns the default configuration. // LoadDefault returns the default configuration.
@ -81,6 +84,9 @@ func LoadDefault(file string) (*Config, error) {
cfg.Cache.Dir = filepath.Join(home, ".cache", "actcache") cfg.Cache.Dir = filepath.Join(home, ".cache", "actcache")
} }
} }
if cfg.Container.Network == "" {
cfg.Container.Network = "bridge"
}
return cfg, nil return cfg, nil
} }

View File

@ -18,6 +18,7 @@ type Runner struct {
Environ map[string]string Environ map[string]string
Client client.Client Client client.Client
Labels []string Labels []string
Network string
CacheHandler *artifactcache.Handler CacheHandler *artifactcache.Handler
} }
@ -30,7 +31,7 @@ func (s *Runner) Run(ctx context.Context, task *runnerv1.Task) error {
if s.CacheHandler != nil { if s.CacheHandler != nil {
env["ACTIONS_CACHE_URL"] = s.CacheHandler.ExternalURL() + "/" env["ACTIONS_CACHE_URL"] = s.CacheHandler.ExternalURL() + "/"
} }
return NewTask(s.ForgeInstance, task.Id, s.Client, env, s.platformPicker).Run(ctx, task, s.Machine, s.Version) return NewTask(task.Id, s.Client, env, s.Network, s.platformPicker).Run(ctx, task, s.Machine, s.Version)
} }
func (s *Runner) platformPicker(labels []string) string { func (s *Runner) platformPicker(labels []string) string {

View File

@ -71,11 +71,11 @@ type Task struct {
} }
// NewTask creates a new task // NewTask creates a new task
func NewTask(forgeInstance string, buildID int64, client client.Client, runnerEnvs map[string]string, picker func([]string) string) *Task { func NewTask(buildID int64, client client.Client, runnerEnvs map[string]string, network string, picker func([]string) string) *Task {
task := &Task{ task := &Task{
Input: &TaskInput{ Input: &TaskInput{
envs: runnerEnvs, envs: runnerEnvs,
containerNetworkMode: "bridge", // TODO should be configurable containerNetworkMode: network,
}, },
BuildID: buildID, BuildID: buildID,