diff --git a/pkg/runner/job_executor.go b/pkg/runner/job_executor.go index 6d73bc2..090ed06 100644 --- a/pkg/runner/job_executor.go +++ b/pkg/runner/job_executor.go @@ -6,6 +6,7 @@ import ( "time" "github.com/nektos/act/pkg/common" + "github.com/nektos/act/pkg/container" "github.com/nektos/act/pkg/model" ) @@ -125,12 +126,13 @@ func newJobExecutor(info jobInfo, sf stepFactory, rc *RunContext) common.Executo if err = info.stopContainer()(ctx); err != nil { logger.Errorf("Error while stop job container: %v", err) } - if rc.Config.ContainerNetworkMode == "" { + if !rc.IsHostEnv(ctx) && rc.Config.ContainerNetworkMode == "" { + // clean network in docker mode only // if the value of `ContainerNetworkMode` is empty string, // it means that the network to which containers are connecting is created by `act_runner`, // so, we should remove the network at last. logger.Infof("Cleaning up network for job %s, and network name is: %s", rc.JobName, rc.networkName()) - if err := rc.removeNetwork(rc.networkName())(ctx); err != nil { + if err := container.NewDockerNetworkRemoveExecutor(rc.networkName())(ctx); err != nil { logger.Errorf("Error while cleaning network: %v", err) } } diff --git a/pkg/runner/run_context.go b/pkg/runner/run_context.go index b9ece35..fd3b23c 100644 --- a/pkg/runner/run_context.go +++ b/pkg/runner/run_context.go @@ -375,7 +375,7 @@ func (rc *RunContext) startJobContainer() common.Executor { return common.NewPipelineExecutor( rc.pullServicesImages(rc.Config.ForcePull), rc.JobContainer.Pull(rc.Config.ForcePull), - rc.createNetwork(networkName).IfBool(rc.Config.ContainerNetworkMode == ""), // if the value of `ContainerNetworkMode` is empty string, then will create a new network for containers. + container.NewDockerNetworkCreateExecutor(networkName).IfBool(!rc.IsHostEnv(ctx) && rc.Config.ContainerNetworkMode == ""), // if the value of `ContainerNetworkMode` is empty string, then will create a new network for containers. rc.startServiceContainers(networkName), rc.JobContainer.Create(rc.Config.ContainerCapAdd, rc.Config.ContainerCapDrop), rc.JobContainer.Start(false), @@ -392,18 +392,6 @@ func (rc *RunContext) startJobContainer() common.Executor { } } -func (rc *RunContext) createNetwork(name string) common.Executor { - return func(ctx context.Context) error { - return container.NewDockerNetworkCreateExecutor(name)(ctx) - } -} - -func (rc *RunContext) removeNetwork(name string) common.Executor { - return func(ctx context.Context) error { - return container.NewDockerNetworkRemoveExecutor(name)(ctx) - } -} - func (rc *RunContext) execJobContainer(cmd []string, env map[string]string, user, workdir string) common.Executor { return func(ctx context.Context) error { return rc.JobContainer.Exec(cmd, env, user, workdir)(ctx)