diff --git a/cmd/input.go b/cmd/input.go index 63a64ad..3b1b34f 100644 --- a/cmd/input.go +++ b/cmd/input.go @@ -11,6 +11,7 @@ type Input struct { workflowsPath string eventPath string reuseContainers bool + bindWorkdir bool secrets []string platforms []string dryrun bool diff --git a/cmd/root.go b/cmd/root.go index a22b10f..efbc05c 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -33,6 +33,7 @@ func Execute(ctx context.Context, version string) { rootCmd.Flags().StringArrayVarP(&input.secrets, "secret", "s", []string{}, "secret to make available to actions with optional value (e.g. -s mysecret=foo or -s mysecret)") rootCmd.Flags().StringArrayVarP(&input.platforms, "platform", "P", []string{}, "custom image to use per platform (e.g. -P ubuntu-18.04=nektos/act-environments-ubuntu:18.04)") rootCmd.Flags().BoolVarP(&input.reuseContainers, "reuse", "r", false, "reuse action containers to maintain state") + rootCmd.Flags().BoolVarP(&input.bindWorkdir, "bind", "b", false, "bind working directory to container, rather than copy") rootCmd.Flags().BoolVarP(&input.forcePull, "pull", "p", false, "pull docker image(s) if already present") rootCmd.Flags().StringVarP(&input.eventPath, "eventpath", "e", "", "path to event JSON file") rootCmd.PersistentFlags().StringVarP(&input.workflowsPath, "workflows", "W", "./.github/workflows/", "path to workflow files") @@ -97,6 +98,7 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str ForcePull: input.forcePull, ReuseContainers: input.reuseContainers, Workdir: input.Workdir(), + BindWorkdir: input.bindWorkdir, LogOutput: !input.noOutput, Secrets: newSecrets(input.secrets), Platforms: input.newPlatforms(), diff --git a/pkg/container/docker_run.go b/pkg/container/docker_run.go index f7ee069..faf436b 100644 --- a/pkg/container/docker_run.go +++ b/pkg/container/docker_run.go @@ -101,6 +101,7 @@ func (cr *containerReference) Copy(destPath string, files ...*FileEntry) common. func (cr *containerReference) CopyDir(destPath string, srcPath string) common.Executor { return common.NewPipelineExecutor( + common.NewInfoExecutor("%sdocker cp src=%s dst=%s", logPrefix, srcPath, destPath), cr.connect(), cr.find(), cr.copyDir(destPath, srcPath), @@ -310,13 +311,14 @@ func (cr *containerReference) copyDir(dstPath string, srcPath string) common.Exe } log.Debugf("Writing tarball %s from %s", tarFile.Name(), srcPath) defer tarFile.Close() - //defer os.Remove(tarFile.Name()) + defer os.Remove(tarFile.Name()) tw := tar.NewWriter(tarFile) srcPrefix := filepath.Dir(srcPath) if !strings.HasSuffix(srcPrefix, string(filepath.Separator)) { srcPrefix += string(filepath.Separator) } + log.Debugf("Stripping prefix:%s src:%s", srcPrefix, srcPath) err = filepath.Walk(srcPath, func(file string, fi os.FileInfo, err error) error { if err != nil { @@ -336,6 +338,7 @@ func (cr *containerReference) copyDir(dstPath string, srcPath string) common.Exe // update the name to correctly reflect the desired destination when untaring header.Name = strings.TrimPrefix(file, srcPrefix) + log.Debugf("%s -> %s", file, header.Name) // write the header if err := tw.WriteHeader(header); err != nil { diff --git a/pkg/runner/run_context.go b/pkg/runner/run_context.go index 429db61..09d3ed2 100644 --- a/pkg/runner/run_context.go +++ b/pkg/runner/run_context.go @@ -82,6 +82,13 @@ func (rc *RunContext) startJobContainer() common.Executor { envList = append(envList, fmt.Sprintf("%s=%s", "RUNNER_TOOL_CACHE", "/toolcache")) + binds := []string{ + fmt.Sprintf("%s:%s", "/var/run/docker.sock", "/var/run/docker.sock"), + } + if rc.Config.BindWorkdir { + binds = append(binds, fmt.Sprintf("%s:%s%s", rc.Config.Workdir, "/github/workspace", bindModifiers)) + } + rc.JobContainer = container.NewContainer(&container.NewContainerInput{ Cmd: nil, Entrypoint: []string{"/usr/bin/tail", "-f", "/dev/null"}, @@ -95,10 +102,7 @@ func (rc *RunContext) startJobContainer() common.Executor { "act-actions": "/actions", }, - Binds: []string{ - fmt.Sprintf("%s:%s%s", rc.Config.Workdir, "/github/workspace", bindModifiers), - fmt.Sprintf("%s:%s", "/var/run/docker.sock", "/var/run/docker.sock"), - }, + Binds: binds, Stdout: logWriter, Stderr: logWriter, }) @@ -108,6 +112,7 @@ func (rc *RunContext) startJobContainer() common.Executor { rc.JobContainer.Remove().IfBool(!rc.Config.ReuseContainers), rc.JobContainer.Create(), rc.JobContainer.Start(false), + rc.JobContainer.CopyDir("/github/workspace", rc.Config.Workdir+"/.").IfBool(!rc.Config.BindWorkdir), rc.JobContainer.Copy("/github/", &container.FileEntry{ Name: "workflow/event.json", Mode: 644, diff --git a/pkg/runner/runner.go b/pkg/runner/runner.go index 6aa1eaf..3befe0c 100644 --- a/pkg/runner/runner.go +++ b/pkg/runner/runner.go @@ -18,6 +18,7 @@ type Runner interface { // Config contains the config for a new runner type Config struct { Workdir string // path to working directory + BindWorkdir bool // bind the workdir to the job container EventName string // name of event to run EventPath string // path to JSON file to use for event.json in containers ReuseContainers bool // reuse containers to maintain state diff --git a/pkg/runner/step_context.go b/pkg/runner/step_context.go index 7d2fd80..cece632 100644 --- a/pkg/runner/step_context.go +++ b/pkg/runner/step_context.go @@ -160,6 +160,13 @@ func (sc *StepContext) newStepContainer(ctx context.Context, image string, cmd [ envList = append(envList, fmt.Sprintf("%s=%s", "RUNNER_TOOL_CACHE", "/toolcache")) + binds := []string{ + fmt.Sprintf("%s:%s", "/var/run/docker.sock", "/var/run/docker.sock"), + } + if rc.Config.BindWorkdir { + binds = append(binds, fmt.Sprintf("%s:%s%s", rc.Config.Workdir, "/github/workspace", bindModifiers)) + } + stepContainer := container.NewContainer(&container.NewContainerInput{ Cmd: cmd, Entrypoint: entrypoint, @@ -172,10 +179,7 @@ func (sc *StepContext) newStepContainer(ctx context.Context, image string, cmd [ "act-toolcache": "/toolcache", "act-actions": "/actions", }, - Binds: []string{ - fmt.Sprintf("%s:%s%s", rc.Config.Workdir, "/github/workspace", bindModifiers), - fmt.Sprintf("%s:%s", "/var/run/docker.sock", "/var/run/docker.sock"), - }, + Binds: binds, Stdout: logWriter, Stderr: logWriter, }) diff --git a/pkg/runner/testdata/basic/push.yml b/pkg/runner/testdata/basic/push.yml index 30218ac..2ae1ea5 100644 --- a/pkg/runner/testdata/basic/push.yml +++ b/pkg/runner/testdata/basic/push.yml @@ -5,6 +5,7 @@ jobs: check: runs-on: ubuntu-latest steps: + - run: ls - run: echo 'hello world' - run: echo ${GITHUB_SHA} >> /github/sha.txt - run: cat /github/sha.txt | grep ${GITHUB_SHA}