1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-09-15 18:57:01 +00:00

chore(cleanup): delete a network scheduled for deletion even if there is no service (#189)

In the current implementation, the network will only be created and be scheduled to be deleted when there is a service:

```go
func (rc *RunContext) networkName() (string, bool) {
	if len(rc.Run.Job().Services) > 0 || rc.Config.ContainerNetworkMode == "" {
		return fmt.Sprintf("%s-%s-network", rc.jobContainerName(), rc.Run.JobID), true
	}
	return string(rc.Config.ContainerNetworkMode), false
}
```

Therefore it does not currently make a difference. However, in case the network creation logic changes and a network is created even if a service is not present, it would be incorrect not to delete it.

Reviewed-on: https://code.forgejo.org/forgejo/act/pulls/189
Reviewed-by: Michael Kriese <michael.kriese@gmx.de>
Co-authored-by: Earl Warren <contact@earl-warren.org>
Co-committed-by: Earl Warren <contact@earl-warren.org>
This commit is contained in:
Earl Warren 2025-07-22 06:08:31 +00:00 committed by earl-warren
parent a157d24741
commit 4a8d6556c7

View file

@ -518,6 +518,7 @@ func (rc *RunContext) prepareJobContainer(ctx context.Context) error {
if err := rc.stopServiceContainers()(ctx); err != nil {
logger.Errorf("Error while cleaning services: %v", err)
}
}
if createAndDeleteNetwork {
// clean network if it has been created by act
// if using service containers
@ -528,7 +529,6 @@ func (rc *RunContext) prepareJobContainer(ctx context.Context) error {
logger.Errorf("Error while cleaning network: %v", err)
}
}
}
return nil
})(ctx)
}