Fix container network issue #56

Merged
wolfogre merged 18 commits from sillyguodong/act:feature/network into main 2023-05-16 06:03:55 +00:00
2 changed files with 4 additions and 4 deletions
Showing only changes of commit 0b4a948958 - Show all commits

@ -125,7 +125,7 @@ func newJobExecutor(info jobInfo, sf stepFactory, rc *RunContext) common.Executo
logger := common.Logger(ctx)
logger.Infof("Cleaning up services for job %s", rc.JobName)
if err := rc.stopServiceContainers(networkName, true)(ctx); err != nil {
if err := rc.stopServiceContainers(networkName, !rc.Config.IsNetworkModeHost())(ctx); err != nil {
logger.Errorf("Error while cleaning services: %v", err)
}

@ -502,13 +502,13 @@ func (rc *RunContext) startServiceContainers(networkName string) common.Executor
}
}
func (rc *RunContext) stopServiceContainers(networkName string, notInitial bool) common.Executor {
func (rc *RunContext) stopServiceContainers(networkName string, disconnectNetwork bool) common.Executor {
return func(ctx context.Context) error {
execs := []common.Executor{}
for _, c := range rc.ServiceContainers {
execs = append(execs, common.NewPipelineExecutor(
c.DisconnectFromNetwork(networkName).IfBool(notInitial),
c.Remove(),
// container cannot be disconnected from host network
c.DisconnectFromNetwork(networkName).IfBool(disconnectNetwork).Finally(c.Remove()),
))
}
return common.NewParallelExecutor(len(execs), execs...)(ctx)