From 799098b0e630caff38f220dd0ab5e216667ec916 Mon Sep 17 00:00:00 2001 From: "Ryan (hackercat)" Date: Sun, 23 May 2021 14:43:09 +0000 Subject: [PATCH] feat: add option for custom socket path (#698) --- README.md | 58 ++++++++++++++++++++------------------- cmd/input.go | 1 + cmd/root.go | 2 ++ pkg/runner/run_context.go | 6 +++- pkg/runner/runner.go | 1 + 5 files changed, 39 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 04c2f37..5e81563 100644 --- a/README.md +++ b/README.md @@ -131,34 +131,36 @@ It will save that information to `~/.actrc`, please refer to [Configuration](#co # Flags ```none - -a, --actor string user that triggered the event (default "nektos/act") - -b, --bind bind working directory to container, rather than copy - --container-architecture string Architecture which should be used to run containers, e.g.: linux/amd64. If not specified, will use host default architecture. Requires Docker server API Version 1.41+. Ignored on earlier Docker server platforms. - --defaultbranch string the name of the main branch - --detect-event Use first event type from workflow as event that triggered the workflow - -C, --directory string working directory (default ".") - -n, --dryrun dryrun mode - --env stringArray env to make available to actions with optional value (e.g. --env myenv=foo or -s myenv) - --env-file string environment file to read and use as env in the containers (default ".env") - -e, --eventpath string path to event JSON file - --github-instance string GitHub instance to use. Don't use this if you are not using GitHub Enterprise Server. (default "github.com") - -g, --graph draw workflows - -h, --help help for act - --insecure-secrets NOT RECOMMENDED! Doesn't hide secrets while printing logs. - -j, --job string run job - -l, --list list workflows - -P, --platform stringArray custom image to use per platform (e.g. -P ubuntu-18.04=nektos/act-environments-ubuntu:18.04) - --privileged use privileged mode - -p, --pull pull docker image(s) even if already present - -q, --quiet disable logging of output from steps - -r, --reuse reuse action containers to maintain state - -s, --secret stringArray secret to make available to actions with optional value (e.g. -s mysecret=foo or -s mysecret) - --secret-file string file with list of secrets to read from (e.g. --secret-file .secrets) (default ".secrets") - --use-gitignore Controls whether paths specified in .gitignore should be copied into container (default true) - --userns string user namespace to use - -v, --verbose verbose output - -w, --watch watch the contents of the local repo and run when files change - -W, --workflows string path to workflow file(s) (default "./.github/workflows/") + -a, --actor string user that triggered the event (default "nektos/act") + -b, --bind bind working directory to container, rather than copy + --container-architecture string Architecture which should be used to run containers, e.g.: linux/amd64. If not specified, will use host default architecture. Requires Docker server API Version 1.41+. Ignored on earlier Docker server platforms. + --container-daemon-socket string Path to Docker daemon socket which will be mounted to containers (default "/var/run/docker.sock") + --defaultbranch string the name of the main branch + --detect-event Use first event type from workflow as event that triggered the workflow + -C, --directory string working directory (default ".") + -n, --dryrun dryrun mode + --env stringArray env to make available to actions with optional value (e.g. --e myenv=foo or -s myenv) + --env-file string environment file to read and use as env in the containers (default ".env") + -e, --eventpath string path to event JSON file + --github-instance string GitHub instance to use. Don't use this if you are not using GitHub Enterprise Server. (default "github.com") + -g, --graph draw workflows + -h, --help help for act + --insecure-secrets NOT RECOMMENDED! Doesn't hide secrets while printing logs. + -j, --job string run job + -l, --list list workflows + --no-recurse Flag to disable running workflows from subdirectories of specified path in '--workflows'/'-W' flag + -P, --platform stringArray custom image to use per platform (e.g. -P ubuntu-18.04=nektos/act-environments-ubuntu:18.04) + --privileged use privileged mode + -p, --pull pull docker image(s) even if already present + -q, --quiet disable logging of output from steps + -r, --reuse reuse action containers to maintain state + -s, --secret stringArray secret to make available to actions with optional value (e.g. -s mysecret=foo or -s mysecret) + --secret-file string file with list of secrets to read from (e.g. --secret-file .secrets) (default ".secrets") + --use-gitignore Controls whether paths specified in .gitignore should be copied into container (default true) + --userns string user namespace to use + -v, --verbose verbose output + -w, --watch watch the contents of the local repo and run when files change + -W, --workflows string path to workflow file(s) (default "./.github/workflows/") ``` In case you want to pass a value for `${{ github.token }}`, you should pass `GITHUB_TOKEN` as secret: `act -s GITHUB_TOKEN=[insert token or leave blank for secure input]`. diff --git a/cmd/input.go b/cmd/input.go index 17bff93..3a91014 100644 --- a/cmd/input.go +++ b/cmd/input.go @@ -28,6 +28,7 @@ type Input struct { privileged bool usernsMode string containerArchitecture string + containerDaemonSocket string noWorkflowRecurse bool useGitIgnore bool githubInstance string diff --git a/cmd/root.go b/cmd/root.go index c3ab1f3..05dbd72 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -61,6 +61,7 @@ func Execute(ctx context.Context, version string) { rootCmd.PersistentFlags().BoolVarP(&input.insecureSecrets, "insecure-secrets", "", false, "NOT RECOMMENDED! Doesn't hide secrets while printing logs.") rootCmd.PersistentFlags().StringVarP(&input.envfile, "env-file", "", ".env", "environment file to read and use as env in the containers") rootCmd.PersistentFlags().StringVarP(&input.containerArchitecture, "container-architecture", "", "", "Architecture which should be used to run containers, e.g.: linux/amd64. If not specified, will use host default architecture. Requires Docker server API Version 1.41+. Ignored on earlier Docker server platforms.") + rootCmd.PersistentFlags().StringVarP(&input.containerDaemonSocket, "container-daemon-socket", "", "/var/run/docker.sock", "Path to Docker daemon socket which will be mounted to containers") rootCmd.PersistentFlags().StringVarP(&input.githubInstance, "github-instance", "", "github.com", "GitHub instance to use. Don't use this if you are not using GitHub Enterprise Server.") rootCmd.SetArgs(args()) @@ -255,6 +256,7 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str Privileged: input.privileged, UsernsMode: input.usernsMode, ContainerArchitecture: input.containerArchitecture, + ContainerDaemonSocket: input.containerDaemonSocket, UseGitIgnore: input.useGitIgnore, GitHubInstance: input.githubInstance, } diff --git a/pkg/runner/run_context.go b/pkg/runner/run_context.go index 5dbee29..fb0d441 100755 --- a/pkg/runner/run_context.go +++ b/pkg/runner/run_context.go @@ -67,8 +67,12 @@ func (rc *RunContext) jobContainerName() string { func (rc *RunContext) GetBindsAndMounts() ([]string, map[string]string) { name := rc.jobContainerName() + if rc.Config.ContainerDaemonSocket == "" { + rc.Config.ContainerDaemonSocket = "/var/run/docker.sock" + } + binds := []string{ - fmt.Sprintf("%s:%s", "/var/run/docker.sock", "/var/run/docker.sock"), + fmt.Sprintf("%s:%s", rc.Config.ContainerDaemonSocket, "/var/run/docker.sock"), } mounts := map[string]string{ diff --git a/pkg/runner/runner.go b/pkg/runner/runner.go index 11bbb67..9d8b6f9 100644 --- a/pkg/runner/runner.go +++ b/pkg/runner/runner.go @@ -37,6 +37,7 @@ type Config struct { Privileged bool // use privileged mode UsernsMode string // user namespace to use ContainerArchitecture string // Desired OS/architecture platform for running containers + ContainerDaemonSocket string // Path to Docker daemon socket UseGitIgnore bool // controls if paths in .gitignore should not be copied into container, default true GitHubInstance string // GitHub instance to use, default "github.com" }