From 12b68ec20aa7f2bbb992b053907bff97eb497676 Mon Sep 17 00:00:00 2001 From: Andreas Salhus Bakseter <141913422+baksetercx@users.noreply.github.com> Date: Thu, 5 Feb 2026 10:24:28 +0100 Subject: [PATCH 1/2] Add option to disable cache --- pkg/build/build.go | 20 +++++++++++-- pkg/build/build_test.go | 63 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 2 deletions(-) diff --git a/pkg/build/build.go b/pkg/build/build.go index 2eb5d6d..df2f642 100644 --- a/pkg/build/build.go +++ b/pkg/build/build.go @@ -62,6 +62,13 @@ func Command() *cli.Command { Value: DefaultCacheTag, Sources: cli.EnvVars("3LV_CACHE_TAG"), }, + &cli.BoolFlag{ + Name: "disable-cache", + Usage: "Disable the use of cache when building the image." + + " Cache produced by the build will still be pushed to the registry if --push is enabled.", + Value: false, + Sources: cli.EnvVars("3LV_DISABLE_CACHE"), + }, &cli.StringFlag{ Name: "azure-tenant-id", Usage: "The tenant ID to use when authenticating with the Azure Container Registry.", @@ -243,6 +250,8 @@ func Build(_ context.Context, c *cli.Command) error { return cli.Exit(err, 1) } + disableCache := c.Bool("disable-cache") + additionalTags := utils.RemoveZeroValues(c.StringSlice("additional-tags")) buildArgs := lo.SliceToMap(utils.RemoveZeroValues(c.StringSlice("build-args")), func(f string) (string, string) { split := strings.Split(f, "=") @@ -255,6 +264,7 @@ func Build(_ context.Context, c *cli.Command) error { buildContext, imageName, cacheTag, + disableCache, additionalTags, buildArgs, nil, @@ -356,6 +366,7 @@ func buildImageCommand( buildContext string, imageName string, cacheTag string, + disableCache bool, additionalTags []string, buildArgs map[string]string, options *command.RunOptions, @@ -383,10 +394,15 @@ func buildImageCommand( "--load", "--cache-to", "type=inline", - "--cache-from", - imageName+":"+cacheTag, ) + if !disableCache { + buildCmd.Args = append(buildCmd.Args, + "--cache-from", + imageName+":"+cacheTag, + ) + } + for key, value := range buildArgs { buildCmd.Args = append(buildCmd.Args, "--build-arg", key+"="+value) } diff --git a/pkg/build/build_test.go b/pkg/build/build_test.go index 943514f..6df6029 100644 --- a/pkg/build/build_test.go +++ b/pkg/build/build_test.go @@ -78,6 +78,7 @@ func TestBuildCommand1(t *testing.T) { buildContext = "src/app" imageName = "containerregistryelvia.azurecr.io/test-image" cacheTag = "latest" + disableCache = false ) imageNameWithCacheTag := imageName + ":" + cacheTag @@ -108,6 +109,7 @@ func TestBuildCommand1(t *testing.T) { buildContext, imageName, cacheTag, + disableCache, additionalTags, buildArgs, &command.RunOptions{DryRun: true}, @@ -127,6 +129,7 @@ func TestBuildCommand2(t *testing.T) { dockerfilePath = "Dockerfile" buildContext = "." imageName = "ghcr.io/test-image" + disableCache = false ) imageNameWithCacheTag := imageName + ":" + DefaultCacheTag @@ -157,6 +160,7 @@ func TestBuildCommand2(t *testing.T) { buildContext, imageName, DefaultCacheTag, + disableCache, additionalTags, buildArgs, &command.RunOptions{DryRun: true}, @@ -176,6 +180,7 @@ func TestBuildCommand3(t *testing.T) { dockerfilePath = "Dockerfile" buildContext = "." imageName = "ghcr.io/test-image" + disableCache = false ) imageNameWithCacheTag := imageName + ":" + DefaultCacheTag @@ -212,6 +217,7 @@ func TestBuildCommand3(t *testing.T) { buildContext, imageName, DefaultCacheTag, + disableCache, additionalTags, buildArgs, &command.RunOptions{DryRun: true}, @@ -231,6 +237,7 @@ func TestBuildCommandWithBuildArgs(t *testing.T) { dockerfilePath = "Dockerfile" buildContext = "." imageName = "ghcr.io/test-image" + disableCache = false ) imageNameWithCacheTag := imageName + ":" + DefaultCacheTag @@ -274,6 +281,62 @@ func TestBuildCommandWithBuildArgs(t *testing.T) { buildContext, imageName, DefaultCacheTag, + disableCache, + additionalTags, + buildArgs, + &command.RunOptions{DryRun: true}, + ) + + command.ExpectedCommandStringEqualsActualCommand( + t, + expectedCommandString, + actualCommand, + ) +} + +func TestBuildCommandWithDisableCache(t *testing.T) { + t.Parallel() + + const ( + dockerfilePath = "Dockerfile" + buildContext = "." + imageName = "ghcr.io/test-image" + disableCache = true + ) + + imageNameWithCacheTag := imageName + ":" + DefaultCacheTag + additionalTags := []string{"latest", "v42.0.1", "v420alpha"} + buildArgs := map[string]string{} + + expectedCommandString := strings.Join( + []string{ + "docker", + "buildx", + "build", + "-f", + dockerfilePath, + "--load", + "--cache-to", + "type=inline", + "-t", + imageName + ":" + additionalTags[0], + "-t", + imageName + ":" + additionalTags[1], + "-t", + imageName + ":" + additionalTags[2], + "-t", + imageNameWithCacheTag, + buildContext, + }, + " ", + ) + + actualCommand := buildImageCommand( + dockerfilePath, + buildContext, + imageName, + DefaultCacheTag, + disableCache, additionalTags, buildArgs, &command.RunOptions{DryRun: true}, From f116d39378728a85ce1141c88efd7c7f2574f1b6 Mon Sep 17 00:00:00 2001 From: Andreas Salhus Bakseter <141913422+baksetercx@users.noreply.github.com> Date: Thu, 5 Feb 2026 10:24:51 +0100 Subject: [PATCH 2/2] 0.35.0 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 6e5caff..7b52f5e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.34.7 +0.35.0