Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[replaced] Add heuristic func to set plugin workspace base for windows containers correctly #4286

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/docs/20-usage/20-workflow-syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,8 @@ The workspace can be customized using the workspace block in the YAML file:
```

:::note
Plugins will always have the workspace base at `/woodpecker`
Plugins will always have the workspace base at `/woodpecker`.
If windows is detected as container host os, it's `c:\woodpecker`.
:::

The base attribute defines a shared base volume available to all steps. This ensures your source code, dependencies and compiled binaries are persisted and shared between steps.
Expand Down
31 changes: 29 additions & 2 deletions pipeline/frontend/yaml/compiler/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"
"maps"
"path"
"regexp"
"strconv"
"strings"

Expand All @@ -33,10 +34,28 @@ import (
const (
// The pluginWorkspaceBase should not be changed, only if you are sure what you do.
pluginWorkspaceBase = "/woodpecker"
// The pluginWorkspaceBaseWindows is like pluginWorkspaceBase but used if we detect windows as container host target.
pluginWorkspaceBaseWindows = `c:\woodpecker`
// DefaultWorkspaceBase is set if not altered by the user.
DefaultWorkspaceBase = pluginWorkspaceBase
)

var workspaceHasWindowsPattern = regexp.MustCompile(`^[a-zA-Z]:\\`)

func (c *Compiler) checkRunOnWindowsHeuristics() bool {
// if user customized the workspace witch indicates it targets windows
if workspaceHasWindowsPattern.MatchString(c.workspaceBase) {
return true
}

// if the platform filter targets windows
if strings.HasPrefix(strings.ToLower(c.metadata.Sys.Platform), "windows") {
return true
}

return false
}

func (c *Compiler) createProcess(container *yaml_types.Container, stepType backend_types.StepType) (*backend_types.Step, error) {
var (
uuid = ulid.Make()
Expand All @@ -51,7 +70,11 @@ func (c *Compiler) createProcess(container *yaml_types.Container, stepType backe
workspaceBase := c.workspaceBase
if container.IsPlugin() {
// plugins have a predefined workspace base to not tamper with entrypoint executables
workspaceBase = pluginWorkspaceBase
if c.checkRunOnWindowsHeuristics() {
workspaceBase = pluginWorkspaceBaseWindows
} else {
workspaceBase = pluginWorkspaceBase
}
}
workspaceVolume := fmt.Sprintf("%s_default:%s", c.prefix, workspaceBase)

Expand Down Expand Up @@ -205,7 +228,11 @@ func (c *Compiler) stepWorkingDir(container *yaml_types.Container) string {
}
base := c.workspaceBase
if container.IsPlugin() {
base = pluginWorkspaceBase
if c.checkRunOnWindowsHeuristics() {
6543 marked this conversation as resolved.
Show resolved Hide resolved
base = pluginWorkspaceBaseWindows
} else {
base = pluginWorkspaceBase
}
}
return path.Join(base, c.workspacePath, container.Directory)
}
Expand Down