From dce2af53953bdf03790d42c022818d09e61f6b08 Mon Sep 17 00:00:00 2001 From: sillyguodong Date: Mon, 3 Jul 2023 15:46:41 +0800 Subject: [PATCH 1/3] add configration item --- go.mod | 4 +++- internal/app/run/runner.go | 1 + internal/pkg/config/config.example.yaml | 4 ++++ internal/pkg/config/config.go | 31 +++++++++++++++++++------ 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index 9e0c5b8..d7f4234 100644 --- a/go.mod +++ b/go.mod @@ -89,4 +89,6 @@ require ( gopkg.in/yaml.v2 v2.4.0 // indirect ) -replace github.com/nektos/act => gitea.com/gitea/act v0.246.1 +// replace github.com/nektos/act => gitea.com/gitea/act v0.246.1 + +replace github.com/nektos/act => ../act diff --git a/internal/app/run/runner.go b/internal/app/run/runner.go index abbfd34..224492e 100644 --- a/internal/app/run/runner.go +++ b/internal/app/run/runner.go @@ -201,6 +201,7 @@ func (r *Runner) run(ctx context.Context, task *runnerv1.Task, reporter *report. PlatformPicker: r.labels.PickPlatform, Vars: task.Vars, ValidVolumes: r.cfg.Container.ValidVolumes, + InheritDiverOpts: r.cfg.Container.InheritDiverOpts, } rr, err := runner.New(runnerConfig) diff --git a/internal/pkg/config/config.example.yaml b/internal/pkg/config/config.example.yaml index 773fd20..35473db 100644 --- a/internal/pkg/config/config.example.yaml +++ b/internal/pkg/config/config.example.yaml @@ -51,6 +51,10 @@ container: # Could be host, bridge or the name of a custom network. # If it's empty, act_runner will create a network automatically. network: "" + # This configuration item only takes effect when container.network is empty. + # The network automatically created by act_runner will inherit the dirver options of the default bridge network. + # Valid value see: https://docs.docker.com/engine/reference/commandline/network_create/#bridge-driver-options, except "com.docker.network.bridge.name" + inherit_driver_opts: [] # Whether to use privileged mode or not when launching task containers (privileged mode is required for Docker-in-Docker). privileged: false # And other options to be used when the container is started (eg, --add-host=my.gitea.url:host-gateway). diff --git a/internal/pkg/config/config.go b/internal/pkg/config/config.go index 8f81cc8..bc2b13d 100644 --- a/internal/pkg/config/config.go +++ b/internal/pkg/config/config.go @@ -42,13 +42,14 @@ type Cache struct { // Container represents the configuration for the container. type Container struct { - Network string `yaml:"network"` // Network specifies the network for the container. - NetworkMode string `yaml:"network_mode"` // Deprecated: use Network instead. Could be removed after Gitea 1.20 - Privileged bool `yaml:"privileged"` // Privileged indicates whether the container runs in privileged mode. - Options string `yaml:"options"` // Options specifies additional options for the container. - WorkdirParent string `yaml:"workdir_parent"` // WorkdirParent specifies the parent directory for the container's working directory. - ValidVolumes []string `yaml:"valid_volumes"` // ValidVolumes specifies the volumes (including bind mounts) can be mounted to containers. - DockerHost string `yaml:"docker_host"` // DockerHost specifies the Docker host. It overrides the value specified in environment variable DOCKER_HOST. + Network string `yaml:"network"` // Network specifies the network for the container. + InheritDiverOpts []string `yaml:"inherit_driver_opts"` // InheritDiverOpts indicates the network created by act_runner whether inherit the dirver options of the default bridge network. + NetworkMode string `yaml:"network_mode"` // Deprecated: use Network instead. Could be removed after Gitea 1.20 + Privileged bool `yaml:"privileged"` // Privileged indicates whether the container runs in privileged mode. + Options string `yaml:"options"` // Options specifies additional options for the container. + WorkdirParent string `yaml:"workdir_parent"` // WorkdirParent specifies the parent directory for the container's working directory. + ValidVolumes []string `yaml:"valid_volumes"` // ValidVolumes specifies the volumes (including bind mounts) can be mounted to containers. + DockerHost string `yaml:"docker_host"` // DockerHost specifies the Docker host. It overrides the value specified in environment variable DOCKER_HOST. } // Host represents the configuration for the host. @@ -141,5 +142,21 @@ func LoadDefault(file string) (*Config, error) { } } + var cleanDriverOptKeys []string + for _, key := range cfg.Container.InheritDiverOpts { + if _, ok := validDriverOptKeysMap[key]; ok { + cleanDriverOptKeys = append(cleanDriverOptKeys, key) + } + } + cfg.Container.InheritDiverOpts = cleanDriverOptKeys + return cfg, nil } + +var validDriverOptKeysMap = map[string]bool{ + "com.docker.network.bridge.enable_ip_masquerade": true, + "com.docker.network.bridge.enable_icc": true, + "com.docker.network.bridge.host_binding_ipv4": true, + "com.docker.network.driver.mtu": true, + "com.docker.network.container_iface_prefix": true, +} -- 2.50.1 From ebde5995ffd954bdbb747ca2a353f966788aa990 Mon Sep 17 00:00:00 2001 From: sillyguodong Date: Tue, 4 Jul 2023 14:32:41 +0800 Subject: [PATCH 2/3] fix --- go.mod | 3 ++- internal/app/run/runner.go | 2 +- internal/pkg/config/config.go | 20 ++++++++++---------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 04d5e54..3d8340d 100644 --- a/go.mod +++ b/go.mod @@ -89,4 +89,5 @@ require ( gopkg.in/yaml.v2 v2.4.0 // indirect ) -replace github.com/nektos/act => gitea.com/gitea/act v0.246.2-0.20230703034344-3813f40cba18 +// replace github.com/nektos/act => gitea.com/gitea/act v0.246.2-0.20230703034344-3813f40cba18 +replace github.com/nektos/act => ../act diff --git a/internal/app/run/runner.go b/internal/app/run/runner.go index 224492e..abdb081 100644 --- a/internal/app/run/runner.go +++ b/internal/app/run/runner.go @@ -201,7 +201,7 @@ func (r *Runner) run(ctx context.Context, task *runnerv1.Task, reporter *report. PlatformPicker: r.labels.PickPlatform, Vars: task.Vars, ValidVolumes: r.cfg.Container.ValidVolumes, - InheritDiverOpts: r.cfg.Container.InheritDiverOpts, + InheritDriverOpts: r.cfg.Container.InheritDriverOpts, } rr, err := runner.New(runnerConfig) diff --git a/internal/pkg/config/config.go b/internal/pkg/config/config.go index bc2b13d..225a45c 100644 --- a/internal/pkg/config/config.go +++ b/internal/pkg/config/config.go @@ -42,14 +42,14 @@ type Cache struct { // Container represents the configuration for the container. type Container struct { - Network string `yaml:"network"` // Network specifies the network for the container. - InheritDiverOpts []string `yaml:"inherit_driver_opts"` // InheritDiverOpts indicates the network created by act_runner whether inherit the dirver options of the default bridge network. - NetworkMode string `yaml:"network_mode"` // Deprecated: use Network instead. Could be removed after Gitea 1.20 - Privileged bool `yaml:"privileged"` // Privileged indicates whether the container runs in privileged mode. - Options string `yaml:"options"` // Options specifies additional options for the container. - WorkdirParent string `yaml:"workdir_parent"` // WorkdirParent specifies the parent directory for the container's working directory. - ValidVolumes []string `yaml:"valid_volumes"` // ValidVolumes specifies the volumes (including bind mounts) can be mounted to containers. - DockerHost string `yaml:"docker_host"` // DockerHost specifies the Docker host. It overrides the value specified in environment variable DOCKER_HOST. + Network string `yaml:"network"` // Network specifies the network for the container. + InheritDriverOpts []string `yaml:"inherit_driver_opts"` // InheritDiverOpts indicates the network created by act_runner whether inherit the dirver options of the default bridge network. + NetworkMode string `yaml:"network_mode"` // Deprecated: use Network instead. Could be removed after Gitea 1.20 + Privileged bool `yaml:"privileged"` // Privileged indicates whether the container runs in privileged mode. + Options string `yaml:"options"` // Options specifies additional options for the container. + WorkdirParent string `yaml:"workdir_parent"` // WorkdirParent specifies the parent directory for the container's working directory. + ValidVolumes []string `yaml:"valid_volumes"` // ValidVolumes specifies the volumes (including bind mounts) can be mounted to containers. + DockerHost string `yaml:"docker_host"` // DockerHost specifies the Docker host. It overrides the value specified in environment variable DOCKER_HOST. } // Host represents the configuration for the host. @@ -143,12 +143,12 @@ func LoadDefault(file string) (*Config, error) { } var cleanDriverOptKeys []string - for _, key := range cfg.Container.InheritDiverOpts { + for _, key := range cfg.Container.InheritDriverOpts { if _, ok := validDriverOptKeysMap[key]; ok { cleanDriverOptKeys = append(cleanDriverOptKeys, key) } } - cfg.Container.InheritDiverOpts = cleanDriverOptKeys + cfg.Container.InheritDriverOpts = cleanDriverOptKeys return cfg, nil } -- 2.50.1 From e6886fdd427d958526661f08c26f48210c8b0c02 Mon Sep 17 00:00:00 2001 From: sillyguodong Date: Tue, 4 Jul 2023 14:45:28 +0800 Subject: [PATCH 3/3] fix --- go.mod | 3 +-- internal/pkg/config/config.go | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 3d8340d..04d5e54 100644 --- a/go.mod +++ b/go.mod @@ -89,5 +89,4 @@ require ( gopkg.in/yaml.v2 v2.4.0 // indirect ) -// replace github.com/nektos/act => gitea.com/gitea/act v0.246.2-0.20230703034344-3813f40cba18 -replace github.com/nektos/act => ../act +replace github.com/nektos/act => gitea.com/gitea/act v0.246.2-0.20230703034344-3813f40cba18 diff --git a/internal/pkg/config/config.go b/internal/pkg/config/config.go index 225a45c..06c4510 100644 --- a/internal/pkg/config/config.go +++ b/internal/pkg/config/config.go @@ -43,7 +43,7 @@ type Cache struct { // Container represents the configuration for the container. type Container struct { Network string `yaml:"network"` // Network specifies the network for the container. - InheritDriverOpts []string `yaml:"inherit_driver_opts"` // InheritDiverOpts indicates the network created by act_runner whether inherit the dirver options of the default bridge network. + InheritDriverOpts []string `yaml:"inherit_driver_opts"` // InheritDiverOpts specifies which default bridge network driver options will be inherited by the network created by act_runner. NetworkMode string `yaml:"network_mode"` // Deprecated: use Network instead. Could be removed after Gitea 1.20 Privileged bool `yaml:"privileged"` // Privileged indicates whether the container runs in privileged mode. Options string `yaml:"options"` // Options specifies additional options for the container. -- 2.50.1