mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-09-15 18:57:01 +00:00
fix: allow overriding RUNNER_TOOL_CACHE from the config file (#178)
- rc.getToolCache(ctx) is used to figure out RUNNER_TOOL_CACHE and returns RUNNER_TOOL_CACHE if it is found in the runner config, e.g. ```yaml container: env: RUNNER_TOOL_CACHE: /srv/toolcache ``` - store the value in the new `toolCache` data member for containers, in the same way it is done for host - GetRunnerContext for containers return `toolCache` instead of a hard coded string - add integration test Closes forgejo/runner#184 Reviewed-on: https://code.forgejo.org/forgejo/act/pulls/178 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:
parent
d2f668c880
commit
6620cc1d18
9 changed files with 39 additions and 9 deletions
|
@ -17,6 +17,7 @@ type NewContainerInput struct {
|
|||
Cmd []string
|
||||
WorkingDir string
|
||||
Env []string
|
||||
ToolCache string
|
||||
Binds []string
|
||||
Mounts map[string]string
|
||||
Name string
|
||||
|
|
|
@ -46,6 +46,7 @@ import (
|
|||
func NewContainer(input *NewContainerInput) ExecutionsEnvironment {
|
||||
cr := new(containerReference)
|
||||
cr.input = input
|
||||
cr.toolCache = input.ToolCache
|
||||
return cr
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,9 @@ import (
|
|||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type LinuxContainerEnvironmentExtensions struct{}
|
||||
type LinuxContainerEnvironmentExtensions struct {
|
||||
toolCache string
|
||||
}
|
||||
|
||||
// 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
|
||||
|
@ -74,12 +76,12 @@ func (*LinuxContainerEnvironmentExtensions) JoinPathVariable(paths ...string) st
|
|||
return strings.Join(paths, ":")
|
||||
}
|
||||
|
||||
func (*LinuxContainerEnvironmentExtensions) GetRunnerContext(ctx context.Context) map[string]interface{} {
|
||||
func (l *LinuxContainerEnvironmentExtensions) GetRunnerContext(ctx context.Context) map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"os": "Linux",
|
||||
"arch": RunnerArch(ctx),
|
||||
"temp": "/tmp",
|
||||
"tool_cache": "/opt/hostedtoolcache",
|
||||
"tool_cache": l.toolCache,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -419,7 +419,7 @@ func newStepContainer(ctx context.Context, step step, image string, cmd []string
|
|||
envList = append(envList, fmt.Sprintf("%s=%s", k, v))
|
||||
}
|
||||
|
||||
envList = append(envList, fmt.Sprintf("%s=%s", "RUNNER_TOOL_CACHE", "/opt/hostedtoolcache"))
|
||||
envList = append(envList, fmt.Sprintf("%s=%s", "RUNNER_TOOL_CACHE", rc.getToolCache(ctx)))
|
||||
envList = append(envList, fmt.Sprintf("%s=%s", "RUNNER_OS", "Linux"))
|
||||
envList = append(envList, fmt.Sprintf("%s=%s", "RUNNER_ARCH", container.RunnerArch(ctx)))
|
||||
envList = append(envList, fmt.Sprintf("%s=%s", "RUNNER_TEMP", "/tmp"))
|
||||
|
@ -438,6 +438,7 @@ func newStepContainer(ctx context.Context, step step, image string, cmd []string
|
|||
Password: rc.Config.Secrets["DOCKER_PASSWORD"],
|
||||
Name: createSimpleContainerName(rc.jobContainerName(), "STEP-"+stepModel.ID),
|
||||
Env: envList,
|
||||
ToolCache: rc.getToolCache(ctx),
|
||||
Mounts: mounts,
|
||||
NetworkMode: networkMode,
|
||||
Binds: binds,
|
||||
|
|
|
@ -300,13 +300,12 @@ func (rc *RunContext) startHostEnvironment() common.Executor {
|
|||
if err := os.MkdirAll(runnerTmp, 0o777); err != nil {
|
||||
return err
|
||||
}
|
||||
toolCache := filepath.Join(cacheDir, "tool_cache")
|
||||
rc.JobContainer = &container.HostEnvironment{
|
||||
Name: randName,
|
||||
Root: miscpath,
|
||||
Path: path,
|
||||
TmpDir: runnerTmp,
|
||||
ToolCache: toolCache,
|
||||
ToolCache: rc.getToolCache(ctx),
|
||||
Workdir: rc.Config.Workdir,
|
||||
ActPath: actPath,
|
||||
CleanUp: func() {
|
||||
|
@ -419,7 +418,7 @@ func (rc *RunContext) startJobContainer() common.Executor {
|
|||
|
||||
envList := make([]string, 0)
|
||||
|
||||
envList = append(envList, fmt.Sprintf("%s=%s", "RUNNER_TOOL_CACHE", "/opt/hostedtoolcache"))
|
||||
envList = append(envList, fmt.Sprintf("%s=%s", "RUNNER_TOOL_CACHE", rc.getToolCache(ctx)))
|
||||
envList = append(envList, fmt.Sprintf("%s=%s", "RUNNER_OS", "Linux"))
|
||||
envList = append(envList, fmt.Sprintf("%s=%s", "RUNNER_ARCH", container.RunnerArch(ctx)))
|
||||
envList = append(envList, fmt.Sprintf("%s=%s", "RUNNER_TEMP", "/tmp"))
|
||||
|
@ -481,6 +480,7 @@ func (rc *RunContext) startJobContainer() common.Executor {
|
|||
Password: password,
|
||||
Cmd: interpolatedCmd,
|
||||
Env: envs,
|
||||
ToolCache: rc.getToolCache(ctx),
|
||||
Mounts: serviceMounts,
|
||||
Binds: serviceBinds,
|
||||
Stdout: logWriter,
|
||||
|
@ -542,6 +542,7 @@ func (rc *RunContext) startJobContainer() common.Executor {
|
|||
Password: password,
|
||||
Name: name,
|
||||
Env: envList,
|
||||
ToolCache: rc.getToolCache(ctx),
|
||||
Mounts: mounts,
|
||||
NetworkMode: networkName,
|
||||
NetworkAliases: []string{rc.Name},
|
||||
|
@ -761,6 +762,16 @@ func (rc *RunContext) interpolateOutputs() common.Executor {
|
|||
}
|
||||
}
|
||||
|
||||
func (rc *RunContext) getToolCache(ctx context.Context) string {
|
||||
if value, ok := rc.Config.Env["RUNNER_TOOL_CACHE"]; ok {
|
||||
return value
|
||||
}
|
||||
if rc.IsHostEnv(ctx) {
|
||||
return filepath.Join(rc.ActionCacheDir(), "tool_cache")
|
||||
}
|
||||
return "/opt/hostedtoolcache"
|
||||
}
|
||||
|
||||
func (rc *RunContext) startContainer() common.Executor {
|
||||
return func(ctx context.Context) error {
|
||||
if rc.IsHostEnv(ctx) {
|
||||
|
|
|
@ -218,7 +218,8 @@ func (j *TestJobFileInfo) runTest(ctx context.Context, t *testing.T, cfg *Config
|
|||
}
|
||||
|
||||
type TestConfig struct {
|
||||
LocalRepositories map[string]string `yaml:"local-repositories"`
|
||||
LocalRepositories map[string]string `yaml:"local-repositories,omitempty"`
|
||||
Env map[string]string `yaml:"env,omitempty"`
|
||||
}
|
||||
|
||||
func TestRunEvent(t *testing.T) {
|
||||
|
@ -314,6 +315,7 @@ func TestRunEvent(t *testing.T) {
|
|||
{workdir, "set-env-step-env-override", "push", "", platforms, secrets},
|
||||
{workdir, "set-env-new-env-file-per-step", "push", "", platforms, secrets},
|
||||
{workdir, "no-panic-on-invalid-composite-action", "push", "jobs failed due to invalid action", platforms, secrets},
|
||||
{workdir, "tool-cache", "push", "", platforms, secrets},
|
||||
|
||||
// services
|
||||
{workdir, "services", "push", "", platforms, secrets},
|
||||
|
@ -349,6 +351,7 @@ func TestRunEvent(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
config.Env = testConfig.Env
|
||||
}
|
||||
|
||||
table.runTest(ctx, t, config)
|
||||
|
|
|
@ -107,7 +107,7 @@ func (sd *stepDocker) newStepContainer(ctx context.Context, image string, cmd []
|
|||
envList = append(envList, fmt.Sprintf("%s=%s", k, v))
|
||||
}
|
||||
|
||||
envList = append(envList, fmt.Sprintf("%s=%s", "RUNNER_TOOL_CACHE", "/opt/hostedtoolcache"))
|
||||
envList = append(envList, fmt.Sprintf("%s=%s", "RUNNER_TOOL_CACHE", rc.getToolCache(ctx)))
|
||||
envList = append(envList, fmt.Sprintf("%s=%s", "RUNNER_OS", "Linux"))
|
||||
envList = append(envList, fmt.Sprintf("%s=%s", "RUNNER_ARCH", container.RunnerArch(ctx)))
|
||||
envList = append(envList, fmt.Sprintf("%s=%s", "RUNNER_TEMP", "/tmp"))
|
||||
|
@ -122,6 +122,7 @@ func (sd *stepDocker) newStepContainer(ctx context.Context, image string, cmd []
|
|||
Password: rc.Config.Secrets["DOCKER_PASSWORD"],
|
||||
Name: createSimpleContainerName(rc.jobContainerName(), "STEP-"+step.ID),
|
||||
Env: envList,
|
||||
ToolCache: rc.getToolCache(ctx),
|
||||
Mounts: mounts,
|
||||
NetworkMode: fmt.Sprintf("container:%s", rc.jobContainerName()),
|
||||
Binds: binds,
|
||||
|
|
2
act/runner/testdata/tool-cache/config/config.yml
vendored
Normal file
2
act/runner/testdata/tool-cache/config/config.yml
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
env:
|
||||
RUNNER_TOOL_CACHE: /srv/otherlocaltion
|
8
act/runner/testdata/tool-cache/push.yml
vendored
Normal file
8
act/runner/testdata/tool-cache/push.yml
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
name: basic
|
||||
on: push
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- run: test "$RUNNER_TOOL_CACHE" = "/srv/otherlocaltion"
|
Loading…
Add table
Add a link
Reference in a new issue