From 24bdb024bf4e0244751b781bf947f1e2ec62058d Mon Sep 17 00:00:00 2001 From: whywaita Date: Sun, 2 Aug 2020 05:21:49 +0900 Subject: [PATCH] add flag of privileged mode --- cmd/input.go | 1 + cmd/root.go | 2 ++ pkg/container/docker_run.go | 2 ++ pkg/runner/run_context.go | 1 + pkg/runner/runner.go | 1 + pkg/runner/step_context.go | 1 + 6 files changed, 8 insertions(+) diff --git a/cmd/input.go b/cmd/input.go index f4d3ae8..736c11b 100644 --- a/cmd/input.go +++ b/cmd/input.go @@ -20,6 +20,7 @@ type Input struct { noOutput bool envfile string secretfile string + privileged bool } func (i *Input) resolve(path string) string { diff --git a/cmd/root.go b/cmd/root.go index 7b5a9ef..8ac8d63 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -41,6 +41,7 @@ func Execute(ctx context.Context, version string) { 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.Flags().BoolVar(&input.privileged, "privileged", false, "use privileged mode") rootCmd.PersistentFlags().StringVarP(&input.actor, "actor", "a", "nektos/act", "user that triggered the event") rootCmd.PersistentFlags().StringVarP(&input.workflowsPath, "workflows", "W", "./.github/workflows/", "path to workflow file(s)") rootCmd.PersistentFlags().StringVarP(&input.workdir, "directory", "C", ".", "working directory") @@ -168,6 +169,7 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str Env: envs, Secrets: secrets, Platforms: input.newPlatforms(), + Privileged: input.privileged, } runner, err := runner.New(config) if err != nil { diff --git a/pkg/container/docker_run.go b/pkg/container/docker_run.go index 09e3cf4..79e35d1 100644 --- a/pkg/container/docker_run.go +++ b/pkg/container/docker_run.go @@ -40,6 +40,7 @@ type NewContainerInput struct { Stdout io.Writer Stderr io.Writer NetworkMode string + Privileged bool } // FileEntry is a file to copy to a container @@ -261,6 +262,7 @@ func (cr *containerReference) create() common.Executor { Binds: input.Binds, Mounts: mounts, NetworkMode: container.NetworkMode(input.NetworkMode), + Privileged: input.Privileged, }, nil, input.Name) if err != nil { return errors.WithStack(err) diff --git a/pkg/runner/run_context.go b/pkg/runner/run_context.go index e0e3338..2829cc6 100644 --- a/pkg/runner/run_context.go +++ b/pkg/runner/run_context.go @@ -104,6 +104,7 @@ func (rc *RunContext) startJobContainer() common.Executor { Binds: binds, Stdout: logWriter, Stderr: logWriter, + Privileged: rc.Config.Privileged, }) var copyWorkspace bool diff --git a/pkg/runner/runner.go b/pkg/runner/runner.go index 54a4705..e5ea0c8 100644 --- a/pkg/runner/runner.go +++ b/pkg/runner/runner.go @@ -28,6 +28,7 @@ type Config struct { Env map[string]string // env for containers Secrets map[string]string // list of secrets Platforms map[string]string // list of platforms + Privileged bool // use privileged mode } type runnerImpl struct { diff --git a/pkg/runner/step_context.go b/pkg/runner/step_context.go index 247a1c0..cd43e47 100644 --- a/pkg/runner/step_context.go +++ b/pkg/runner/step_context.go @@ -191,6 +191,7 @@ func (sc *StepContext) newStepContainer(ctx context.Context, image string, cmd [ Binds: binds, Stdout: logWriter, Stderr: logWriter, + Privileged: rc.Config.Privileged, }) return stepContainer }