Skip to content

Commit 545802b

Browse files
Zettat123wolfogre
authored andcommitted
Fix the error when removing network in self-hosted mode (#69)
Fixes https://gitea.com/gitea/act_runner/issues/255 Reviewed-on: https://gitea.com/gitea/act/pulls/69 Co-authored-by: Zettat123 <[email protected]> Co-committed-by: Zettat123 <[email protected]>
1 parent 515c2c4 commit 545802b

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
lines changed

pkg/runner/job_executor.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"time"
77

88
"github.com/nektos/act/pkg/common"
9+
"github.com/nektos/act/pkg/container"
910
"github.com/nektos/act/pkg/model"
1011
)
1112

@@ -125,12 +126,13 @@ func newJobExecutor(info jobInfo, sf stepFactory, rc *RunContext) common.Executo
125126
if err = info.stopContainer()(ctx); err != nil {
126127
logger.Errorf("Error while stop job container: %v", err)
127128
}
128-
if rc.Config.ContainerNetworkMode == "" {
129+
if !rc.IsHostEnv(ctx) && rc.Config.ContainerNetworkMode == "" {
130+
// clean network in docker mode only
129131
// if the value of `ContainerNetworkMode` is empty string,
130132
// it means that the network to which containers are connecting is created by `act_runner`,
131133
// so, we should remove the network at last.
132134
logger.Infof("Cleaning up network for job %s, and network name is: %s", rc.JobName, rc.networkName())
133-
if err := rc.removeNetwork(rc.networkName())(ctx); err != nil {
135+
if err := container.NewDockerNetworkRemoveExecutor(rc.networkName())(ctx); err != nil {
134136
logger.Errorf("Error while cleaning network: %v", err)
135137
}
136138
}

pkg/runner/run_context.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ func (rc *RunContext) startJobContainer() common.Executor {
375375
return common.NewPipelineExecutor(
376376
rc.pullServicesImages(rc.Config.ForcePull),
377377
rc.JobContainer.Pull(rc.Config.ForcePull),
378-
rc.createNetwork(networkName).IfBool(rc.Config.ContainerNetworkMode == ""), // if the value of `ContainerNetworkMode` is empty string, then will create a new network for containers.
378+
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.
379379
rc.startServiceContainers(networkName),
380380
rc.JobContainer.Create(rc.Config.ContainerCapAdd, rc.Config.ContainerCapDrop),
381381
rc.JobContainer.Start(false),
@@ -392,18 +392,6 @@ func (rc *RunContext) startJobContainer() common.Executor {
392392
}
393393
}
394394

395-
func (rc *RunContext) createNetwork(name string) common.Executor {
396-
return func(ctx context.Context) error {
397-
return container.NewDockerNetworkCreateExecutor(name)(ctx)
398-
}
399-
}
400-
401-
func (rc *RunContext) removeNetwork(name string) common.Executor {
402-
return func(ctx context.Context) error {
403-
return container.NewDockerNetworkRemoveExecutor(name)(ctx)
404-
}
405-
}
406-
407395
func (rc *RunContext) execJobContainer(cmd []string, env map[string]string, user, workdir string) common.Executor {
408396
return func(ctx context.Context) error {
409397
return rc.JobContainer.Exec(cmd, env, user, workdir)(ctx)

0 commit comments

Comments
 (0)