1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2025-11-23 21:44:44 +02:00

Option to change temp dir for local backend (#2702)

---
*Sponsored by Kithara Software GmbH*
This commit is contained in:
6543
2023-11-02 15:45:18 +01:00
committed by GitHub
parent da6f39258d
commit 7bc40f20cb
5 changed files with 35 additions and 6 deletions

View File

@@ -27,6 +27,7 @@ import (
"sync"
"github.com/rs/zerolog/log"
"github.com/urfave/cli/v2"
"golang.org/x/text/encoding/unicode"
"golang.org/x/text/transform"
@@ -42,6 +43,7 @@ type workflowState struct {
}
type local struct {
tempDir string
workflows sync.Map
output io.ReadCloser
pluginGitBinary string
@@ -64,7 +66,12 @@ func (e *local) IsAvailable(context.Context) bool {
return true
}
func (e *local) Load(context.Context) (*types.EngineInfo, error) {
func (e *local) Load(ctx context.Context) (*types.EngineInfo, error) {
c, ok := ctx.Value(types.CliContext).(*cli.Context)
if ok {
e.tempDir = c.String("backend-local-temp-dir")
}
e.loadClone()
return &types.EngineInfo{
@@ -76,7 +83,7 @@ func (e *local) Load(context.Context) (*types.EngineInfo, error) {
func (e *local) SetupWorkflow(_ context.Context, _ *types.Config, taskUUID string) error {
log.Trace().Str("taskUUID", taskUUID).Msg("create workflow environment")
baseDir, err := os.MkdirTemp("", "woodpecker-local-*")
baseDir, err := os.MkdirTemp(e.tempDir, "woodpecker-local-*")
if err != nil {
return err
}
@@ -139,7 +146,7 @@ func (e *local) StartStep(ctx context.Context, step *types.Step, taskUUID string
// execCommands use step.Image as shell and run the commands in it
func (e *local) execCommands(ctx context.Context, step *types.Step, state *workflowState, env []string) error {
// Prepare commands
args, err := genCmdByShell(step.Image, step.Commands)
args, err := e.genCmdByShell(step.Image, step.Commands)
if err != nil {
return fmt.Errorf("could not convert commands into args: %w", err)
}