From 35400f76fa20a31f56bf9836f7720d1ff4713ea4 Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Fri, 28 Apr 2023 22:03:52 +0800 Subject: [PATCH] Add parent directory for working directory (#154) Fixes #145 At present, the working directory of a work flow is a path like `//`, so the directory may conflict with system directory like `/usr/bin`. We need to add a parent directory for the working directory. In this PR, the parent directory is `/workspace` by default and users could configure it by the `workdir_parent` option. This change doesn't affect the host mode because in host mode the working directory will always be in `$HOME/.cache/act/` directory. Co-authored-by: Jason Song Reviewed-on: https://gitea.com/gitea/act_runner/pulls/154 Reviewed-by: Jason Song Co-authored-by: Zettat123 Co-committed-by: Zettat123 --- internal/app/run/runner.go | 6 +++--- internal/pkg/config/config.example.yaml | 3 +++ internal/pkg/config/config.go | 10 +++++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/internal/app/run/runner.go b/internal/app/run/runner.go index 6a98de7..c5801eb 100644 --- a/internal/app/run/runner.go +++ b/internal/app/run/runner.go @@ -166,9 +166,9 @@ func (r *Runner) run(ctx context.Context, task *runnerv1.Task, reporter *report. } runnerConfig := &runner.Config{ - // On Linux, Workdir will be like "//" - // On Windows, Workdir will be like "\\" - Workdir: filepath.FromSlash(string(filepath.Separator) + preset.Repository), + // On Linux, Workdir will be like "///" + // On Windows, Workdir will be like "\\\" + Workdir: filepath.FromSlash(fmt.Sprintf("/%s/%s", r.cfg.Container.WorkdirParent, preset.Repository)), BindWorkdir: false, ReuseContainers: false, diff --git a/internal/pkg/config/config.example.yaml b/internal/pkg/config/config.example.yaml index 12e69f8..a3cc4b3 100644 --- a/internal/pkg/config/config.example.yaml +++ b/internal/pkg/config/config.example.yaml @@ -48,3 +48,6 @@ container: privileged: false # And other options to be used when the container is started (eg, --add-host=my.gitea.url:host-gateway). options: + # The parent directory of a job's working directory. + # If it's empty, /workspace will be used. + workdir_parent: diff --git a/internal/pkg/config/config.go b/internal/pkg/config/config.go index 30e33d2..7cbcfc2 100644 --- a/internal/pkg/config/config.go +++ b/internal/pkg/config/config.go @@ -34,9 +34,10 @@ type Config struct { Port uint16 `yaml:"port"` } `yaml:"cache"` Container struct { - NetworkMode string `yaml:"network_mode"` - Privileged bool `yaml:"privileged"` - Options string `yaml:"options"` + NetworkMode string `yaml:"network_mode"` + Privileged bool `yaml:"privileged"` + Options string `yaml:"options"` + WorkdirParent string `yaml:"workdir_parent"` } `yaml:"container"` } @@ -94,6 +95,9 @@ func LoadDefault(file string) (*Config, error) { if cfg.Container.NetworkMode == "" { cfg.Container.NetworkMode = "bridge" } + if cfg.Container.WorkdirParent == "" { + cfg.Container.WorkdirParent = "workspace" + } if cfg.Runner.FetchTimeout <= 0 { cfg.Runner.FetchTimeout = 5 * time.Second }