1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-09-05 18:40:59 +00:00

fix: use a unique random name to derive network and volumes for a job

When a reusable workflow is called twice in the same workflow in
parallel, it may require a dedicated network to run (for instance if
it spawns services) and will always require unique volumes to mount
the workdir and the env.

There really is no way to guarantee a unique name derived from the
job name etc. Instead, a random name is set and used as a base for
both the internal volumes and the dedicated network (if any).
This commit is contained in:
Earl Warren 2025-08-14 11:21:51 +02:00
parent 10c26c53a3
commit c85eb0e647
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00

View file

@ -126,11 +126,13 @@ func (rc *RunContext) getInternalVolumeNames(ctx context.Context) []string {
}
func (rc *RunContext) getInternalVolumeWorkdir(ctx context.Context) string {
return rc.jobContainerName()
rc.ensureRandomName(ctx)
return rc.randomName
}
func (rc *RunContext) getInternalVolumeEnv(ctx context.Context) string {
return fmt.Sprintf("%s-env", rc.jobContainerName())
rc.ensureRandomName(ctx)
return fmt.Sprintf("%s-env", rc.randomName)
}
// Returns the binds and mounts for the container, resolving paths as appopriate
@ -423,9 +425,10 @@ func (rc *RunContext) getNetworkName(ctx context.Context) string {
func (rc *RunContext) ensureNetworkName(ctx context.Context) {
if rc.networkName == "" {
rc.ensureRandomName(ctx)
rc.networkName = string(rc.Config.ContainerNetworkMode)
if len(rc.Run.Job().Services) > 0 || rc.networkName == "" {
rc.networkName = fmt.Sprintf("%s-%s-network", rc.jobContainerName(), rc.Run.JobID)
rc.networkName = fmt.Sprintf("WORKFLOW-%s", rc.randomName)
rc.networkCreated = true
}
}