mirror of
https://gitea.com/gitea/act_runner.git
synced 2026-08-02 12:53:08 +00:00
1. Docker rejects two mounts on one target, so a `container.volumes:` or `--volume` aimed at `/opt/hostedtoolcache` failed the job with `Duplicate mount point`. Job and service volumes now displace the mount on the same path, and `name:/target:ro` no longer mounts read-write at the literal path `/target:ro`.
1. Setting `RUNNER_TOOL_CACHE` only changed what the variable said, the cache stayed where it was, so tools writing to it landed outside the mount and `${{ runner.tool_cache }}` disagreed with the variable. It now relocates the cache. Leaving it unset behaves as before.
1. Unknown `config.yaml` keys now warn instead of being dropped without a trace.
Fixes https://gitea.com/gitea/runner/issues/813
---------
Co-authored-by: bircni <bircni@icloud.com>
Reviewed-on: https://gitea.com/gitea/runner/pulls/1122
Reviewed-by: bircni <bircni@icloud.com>
Co-authored-by: silverwind <me@silverwind.io>
84 lines
2.6 KiB
Go
84 lines
2.6 KiB
Go
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// Copyright 2022 The nektos/act Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package container
|
|
|
|
import (
|
|
"context"
|
|
"path/filepath"
|
|
"regexp"
|
|
"runtime"
|
|
"strings"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
type LinuxContainerEnvironmentExtensions struct{}
|
|
|
|
// Resolves the equivalent host path inside the container
|
|
// This is required for windows and WSL 2 to translate things like C:\Users\Myproject to /mnt/users/Myproject
|
|
// For use in docker volumes and binds
|
|
func (*LinuxContainerEnvironmentExtensions) ToContainerPath(path string) string {
|
|
if runtime.GOOS == "windows" && strings.Contains(path, "/") {
|
|
log.Error("You cannot specify linux style local paths (/mnt/etc) on Windows as it does not understand them.")
|
|
return ""
|
|
}
|
|
|
|
abspath, err := filepath.Abs(path)
|
|
if err != nil {
|
|
log.Error(err)
|
|
return ""
|
|
}
|
|
|
|
// Test if the path is a windows path
|
|
windowsPathRegex := regexp.MustCompile(`^([a-zA-Z]):\\(.+)$`)
|
|
windowsPathComponents := windowsPathRegex.FindStringSubmatch(abspath)
|
|
|
|
// Return as-is if no match
|
|
if windowsPathComponents == nil {
|
|
return abspath
|
|
}
|
|
|
|
// Convert to WSL2-compatible path if it is a windows path
|
|
// NOTE: Cannot use filepath because it will use the wrong path separators assuming we want the path to be windows
|
|
// based if running on Windows, and because we are feeding this to Docker, GoLang auto-path-translate doesn't work.
|
|
driveLetter := strings.ToLower(windowsPathComponents[1])
|
|
translatedPath := strings.ReplaceAll(windowsPathComponents[2], `\`, `/`)
|
|
// Should make something like /mnt/c/Users/person/My Folder/MyActProject
|
|
result := strings.Join([]string{"/mnt", driveLetter, translatedPath}, `/`)
|
|
return result
|
|
}
|
|
|
|
func (*LinuxContainerEnvironmentExtensions) GetActPath() string {
|
|
return "/var/run/act"
|
|
}
|
|
|
|
func (*LinuxContainerEnvironmentExtensions) GetPathVariableName() string {
|
|
return "PATH"
|
|
}
|
|
|
|
func (*LinuxContainerEnvironmentExtensions) DefaultPathVariable() string {
|
|
return "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
|
}
|
|
|
|
func (*LinuxContainerEnvironmentExtensions) JoinPathVariable(paths ...string) string {
|
|
return strings.Join(paths, ":")
|
|
}
|
|
|
|
// DefaultToolCache is where the runner mounts the tool cache inside job containers.
|
|
const DefaultToolCache = "/opt/hostedtoolcache"
|
|
|
|
func (*LinuxContainerEnvironmentExtensions) GetRunnerContext(ctx context.Context) map[string]any {
|
|
return map[string]any{
|
|
"os": "Linux",
|
|
"arch": RunnerArch(ctx),
|
|
"temp": "/tmp",
|
|
"tool_cache": DefaultToolCache,
|
|
}
|
|
}
|
|
|
|
func (*LinuxContainerEnvironmentExtensions) IsEnvironmentCaseInsensitive() bool {
|
|
return false
|
|
}
|