From 1a6c8dfec6181b28f4ad6a99a53459b7511604dd Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 24 Sep 2024 22:49:36 +0200 Subject: [PATCH] Ensure cli exec has by default not the same prefix (#4132) --- cli/exec/exec.go | 10 ++++++---- cli/exec/flags.go | 7 ------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/cli/exec/exec.go b/cli/exec/exec.go index 59bbe47e6..f532208cf 100644 --- a/cli/exec/exec.go +++ b/cli/exec/exec.go @@ -25,6 +25,7 @@ import ( "strings" "github.com/drone/envsubst" + "github.com/oklog/ulid/v2" "github.com/rs/zerolog/log" "github.com/urfave/cli/v3" @@ -170,6 +171,9 @@ func execWithAxis(ctx context.Context, c *cli.Command, file, repoPath string, ax return err } + // emulate server behavior https://github.com/woodpecker-ci/woodpecker/blob/eebaa10d104cbc3fa7ce4c0e344b0b7978405135/server/pipeline/stepbuilder/stepBuilder.go#L289-L295 + prefix := "wp_" + ulid.Make().String() + // configure volumes for local execution volumes := c.StringSlice("volumes") if c.Bool("local") { @@ -184,7 +188,7 @@ func execWithAxis(ctx context.Context, c *cli.Command, file, repoPath string, ax workspacePath = c.String("workspace-path") } - volumes = append(volumes, c.String("prefix")+"_default:"+workspaceBase) + volumes = append(volumes, prefix+"_default:"+workspaceBase) volumes = append(volumes, repoPath+":"+path.Join(workspaceBase, workspacePath)) } @@ -221,9 +225,7 @@ func execWithAxis(ctx context.Context, c *cli.Command, file, repoPath string, ax compiler.WithNetworks( c.StringSlice("network")..., ), - compiler.WithPrefix( - c.String("prefix"), - ), + compiler.WithPrefix(prefix), compiler.WithProxy(compiler.ProxyOptions{ NoProxy: c.String("backend-no-proxy"), HTTPProxy: c.String("backend-http-proxy"), diff --git a/cli/exec/flags.go b/cli/exec/flags.go index 2bb54fdb8..c7a985d69 100644 --- a/cli/exec/flags.go +++ b/cli/exec/flags.go @@ -48,13 +48,6 @@ var flags = []cli.Flag{ Name: "network", Usage: "external networks", }, - &cli.StringFlag{ - Sources: cli.EnvVars("WOODPECKER_PREFIX"), - Name: "prefix", - Value: "woodpecker", - Usage: "prefix used for containers, volumes, networks, ... created by woodpecker", - Hidden: true, - }, &cli.StringSliceFlag{ Sources: cli.EnvVars("WOODPECKER_PLUGINS_PRIVILEGED"), Name: "plugins-privileged",