From a99a1e9c5a0f6f82c1fd00530682573a15702b34 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> --- act/runner/runner.go | 1 + act/runner/step_context.go | 2 +- cmd/input.go | 1 + cmd/root.go | 2 ++ 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/act/runner/runner.go b/act/runner/runner.go index 2525e5e8..5fb88483 100644 --- a/act/runner/runner.go +++ b/act/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/act/runner/step_context.go b/act/runner/step_context.go index 74109a64..13c01d1f 100644 --- a/act/runner/step_context.go +++ b/act/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 { diff --git a/cmd/input.go b/cmd/input.go index 7e528847..4dea829d 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 31686efd..adfe69bf 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,