From 84386c1b167d93323728f1f9e5ebda86f2a5d744 Mon Sep 17 00:00:00 2001 From: sillyguodong Date: Thu, 18 May 2023 15:01:43 +0800 Subject: [PATCH] Add exec command flag of `network` (#192) Related to #184 Add command flag of `network` for `exec`, the default value of `--network` is empty string. Valid values are: `host `, `bridge`, `` and empty string. Co-authored-by: Jason Song Reviewed-on: https://gitea.com/gitea/act_runner/pulls/192 Reviewed-by: a1012112796 <1012112796@qq.com> Reviewed-by: Jason Song Co-authored-by: sillyguodong Co-committed-by: sillyguodong --- internal/app/cmd/exec.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/app/cmd/exec.go b/internal/app/cmd/exec.go index 16177fb..06568a9 100644 --- a/internal/app/cmd/exec.go +++ b/internal/app/cmd/exec.go @@ -57,6 +57,7 @@ type executeArgs struct { dryrun bool image string cacheHandler *artifactcache.Handler + network string } // WorkflowsPath returns path to workflow file(s) @@ -385,7 +386,7 @@ func runExec(ctx context.Context, execArgs *executeArgs) func(cmd *cobra.Command // EventJSON: string(eventJSON), ContainerNamePrefix: fmt.Sprintf("GITEA-ACTIONS-TASK-%s", eventName), ContainerMaxLifetime: maxLifetime, - ContainerNetworkMode: container.NetworkMode("bridge"), + ContainerNetworkMode: container.NetworkMode(execArgs.network), DefaultActionInstance: execArgs.defaultActionsUrl, PlatformPicker: func(_ []string) string { return execArgs.image @@ -464,6 +465,7 @@ func loadExecCmd(ctx context.Context) *cobra.Command { execCmd.PersistentFlags().BoolVarP(&execArg.debug, "debug", "d", false, "enable debug log") execCmd.PersistentFlags().BoolVarP(&execArg.dryrun, "dryrun", "n", false, "dryrun mode") execCmd.PersistentFlags().StringVarP(&execArg.image, "image", "i", "node:16-bullseye", "docker image to use") + execCmd.PersistentFlags().StringVarP(&execArg.network, "network", "", "", "Specify the network to which the container will connect") return execCmd }