Skip to content

Commit 069f43c

Browse files
authored
add ability to control container image autorebuild (#116)
1 parent 034e2ac commit 069f43c

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

docs/actions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ Action runtime options:
148148
--entrypoint string Image Entrypoint: Overwrite the default ENTRYPOINT of the image. Example: --entrypoint "/bin/sh"
149149
--exec Exec command: Overwrite the command of the action. Argument and options are not validated, sets container CMD directly. Example usage: --exec -- ls -lah
150150
--no-cache No cache: Send command to build container without cache
151+
--rebuild-image Rebuild image: Rebuild image if the action directory or the Dockerfile has changed
151152
--remote-copy-back Remote copy back: Copies the working directory back from the container. Works only if the runtime is remote.
152153
--remote-runtime Remote runtime: Forces the container runtime to be used as remote. Copies the working directory to a container volume. Local binds are not used.
153154
--remove-image Remove Image: Remove an image after execution of action

pkg/action/runtime.container.go

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ const (
2222
containerActionMount = "/action"
2323

2424
// Environment specific flags.
25-
containerFlagRemote = "remote-runtime"
26-
containerFlagCopyBack = "remote-copy-back"
27-
containerFlagRemoveImage = "remove-image"
28-
containerFlagNoCache = "no-cache"
29-
containerFlagEntrypoint = "entrypoint"
30-
containerFlagExec = "exec"
25+
containerFlagRemote = "remote-runtime"
26+
containerFlagCopyBack = "remote-copy-back"
27+
containerFlagRemoveImage = "remove-image"
28+
containerFlagNoCache = "no-cache"
29+
containerFlagRebuildImage = "rebuild-image"
30+
containerFlagEntrypoint = "entrypoint"
31+
containerFlagExec = "exec"
3132
)
3233

3334
type runtimeContainer struct {
@@ -53,6 +54,7 @@ type runtimeContainer struct {
5354
copyBack bool
5455
removeImg bool
5556
noCache bool
57+
rebuildImage bool
5658
entrypoint string
5759
entrypointSet bool
5860
exec bool
@@ -133,6 +135,13 @@ func (c *runtimeContainer) GetFlags() *FlagsGroup {
133135
Type: jsonschema.Boolean,
134136
Default: false,
135137
},
138+
&DefParameter{
139+
Name: containerFlagRebuildImage,
140+
Title: "Auto-rebuild image",
141+
Description: "Rebuild image if the action directory or the Dockerfile has changed",
142+
Type: jsonschema.Boolean,
143+
Default: true,
144+
},
136145
&DefParameter{
137146
Name: containerFlagEntrypoint,
138147
Title: "Image Entrypoint",
@@ -190,6 +199,10 @@ func (c *runtimeContainer) SetFlags(input *Input) error {
190199
c.noCache = nc.(bool)
191200
}
192201

202+
if rb, ok := flags[containerFlagRebuildImage]; ok {
203+
c.rebuildImage = rb.(bool)
204+
}
205+
193206
if e, ok := flags[containerFlagEntrypoint]; ok && e != "" {
194207
c.entrypointSet = true
195208
c.entrypoint = e.(string)
@@ -392,7 +405,7 @@ func (c *runtimeContainer) imageRemove(ctx context.Context, a *Action) error {
392405

393406
func (c *runtimeContainer) isRebuildRequired(bi *driver.BuildDefinition) (bool, error) {
394407
// @todo test image cache resolution somehow.
395-
if c.imgccres == nil || bi == nil {
408+
if c.imgccres == nil || bi == nil || !c.rebuildImage {
396409
return false, nil
397410
}
398411

0 commit comments

Comments
 (0)