From 8ad6c07083c7cd7f45ea9e0808e3297bf2370ab5 Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 24 Nov 2021 16:51:37 +0100 Subject: [PATCH] feat: add option for docker image rebuild (#878) Adds option to rebuild local action docker images Fixed up README due to missing flags after PR #714 and #716 Signed-off-by: hackercat Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- README.md | 7 +++++-- cmd/input.go | 1 + cmd/root.go | 2 ++ pkg/runner/runner.go | 1 + pkg/runner/step_context.go | 2 +- 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 02ffed782ee..7da2ac98420 100644 --- a/README.md +++ b/README.md @@ -165,11 +165,12 @@ It will save that information to `~/.actrc`, please refer to [Configuration](#co ```none -a, --actor string user that triggered the event (default "nektos/act") - --artifact-server-path string Defines the path where the artifact server stores uploads and retrieves downloads from. - If not specified the artifact server will not start. + --artifact-server-path string Defines the path where the artifact server stores uploads and retrieves downloads from. If not specified the artifact server will not start. --artifact-server-port string Defines the port where the artifact server listens (will only bind to localhost). (default "34567") -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-cap-add stringArray kernel capabilities to add to the workflow containers (e.g. --container-cap-add SYS_PTRACE) + --container-cap-drop stringArray kernel capabilities to remove from the workflow containers (e.g. --container-cap-drop SYS_PTRACE) --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 @@ -189,7 +190,9 @@ It will save that information to `~/.actrc`, please refer to [Configuration](#co --privileged use privileged mode -p, --pull pull docker image(s) even if already present -q, --quiet disable logging of output from steps + --rebuild rebuild local action docker image(s) even if already present -r, --reuse reuse action containers to maintain state + --rm automatically remove containers just before exit -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) diff --git a/cmd/input.go b/cmd/input.go index 7e52884738a..4dea829dda9 100644 --- a/cmd/input.go +++ b/cmd/input.go @@ -20,6 +20,7 @@ type Input struct { platforms []string dryrun bool forcePull bool + forceRebuild bool noOutput bool envfile string secretfile string diff --git a/cmd/root.go b/cmd/root.go index 31686efd13c..adfe69bfc46 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -45,6 +45,7 @@ func Execute(ctx context.Context, version string) { 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) even if already present") + rootCmd.Flags().BoolVarP(&input.forceRebuild, "rebuild", "", false, "rebuild local action docker image(s) even if already present") rootCmd.Flags().BoolVarP(&input.autodetectEvent, "detect-event", "", false, "Use first event type from workflow as event that triggered the workflow") rootCmd.Flags().StringVarP(&input.eventPath, "eventpath", "e", "", "path to event JSON file") rootCmd.Flags().StringVar(&input.defaultBranch, "defaultbranch", "", "the name of the main branch") @@ -260,6 +261,7 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str EventPath: input.EventPath(), DefaultBranch: defaultbranch, ForcePull: input.forcePull, + ForceRebuild: input.forceRebuild, ReuseContainers: input.reuseContainers, Workdir: input.Workdir(), BindWorkdir: input.bindWorkdir, diff --git a/pkg/runner/runner.go b/pkg/runner/runner.go index 2525e5e8787..5fb88483af3 100644 --- a/pkg/runner/runner.go +++ b/pkg/runner/runner.go @@ -29,6 +29,7 @@ type Config struct { DefaultBranch string // name of the main branch for this repository ReuseContainers bool // reuse containers to maintain state ForcePull bool // force pulling of the image, even if already present + ForceRebuild bool // force rebuilding local docker image action LogOutput bool // log the output from docker run Env map[string]string // env for containers Secrets map[string]string // list of secrets diff --git a/pkg/runner/step_context.go b/pkg/runner/step_context.go index 74109a641e6..13c01d1f09b 100644 --- a/pkg/runner/step_context.go +++ b/pkg/runner/step_context.go @@ -552,7 +552,7 @@ func (sc *StepContext) execAsDocker(ctx context.Context, action *model.Action, a } } - if !correctArchExists { + if !correctArchExists || rc.Config.ForceRebuild { log.Debugf("image '%s' for architecture '%s' will be built from context '%s", image, rc.Config.ContainerArchitecture, contextDir) var actionContainer container.Container if localAction {