Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2953 from radriaanse/add-docker-nocache
Browse files Browse the repository at this point in the history
plugin/docker: add no-cache option
  • Loading branch information
krantzinator authored Jan 31, 2022
2 parents d6194c5 + 38664ed commit 8b600fd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/2953.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
plugin/docker: Add parameter to disable the build cache
```
15 changes: 14 additions & 1 deletion builtin/docker/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ type BuilderConfig struct {

// Controls the passing of the target stage
Target string `hcl:"target,optional"`

// Disable the build cache
NoCache bool `hcl:"no_cache,optional"`
}

func (b *Builder) Documentation() (*docs.Documentation, error) {
Expand Down Expand Up @@ -167,6 +170,14 @@ build {
),
)

doc.SetField(
"no_cache",
"Do not use cache when building the image",
docs.Summary(
"Ensures a clean image build.",
),
)

return doc, nil
}

Expand Down Expand Up @@ -309,7 +320,7 @@ func (b *Builder) Build(
// Build
step.Done()
step = nil
if err := b.buildWithDocker(ctx, ui, sg, cli, contextDir, relDockerfile, result.Name(), b.config.Platform, b.config.BuildArgs, b.config.Target, log); err != nil {
if err := b.buildWithDocker(ctx, ui, sg, cli, contextDir, relDockerfile, result.Name(), b.config.Platform, b.config.BuildArgs, b.config.Target, b.config.NoCache, log); err != nil {
return nil, err
}

Expand Down Expand Up @@ -384,6 +395,7 @@ func (b *Builder) buildWithDocker(
platform string,
buildArgs map[string]*string,
target string,
noCache bool,
log hclog.Logger,
) error {
excludes, err := build.ReadDockerignore(contextDir)
Expand Down Expand Up @@ -432,6 +444,7 @@ func (b *Builder) buildWithDocker(
Platform: platform,
BuildArgs: buildArgs,
Target: target,
NoCache: noCache,
}

// Buildkit builds need a session under most circumstances, but sessions are only supported in >1.39
Expand Down
9 changes: 9 additions & 0 deletions website/content/partials/components/builder-docker.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ Set this when the Dockerfile is not APP-PATH/Dockerfile.
- Type: **string**
- **Optional**

#### no_cache

Do not use cache when building the image.

Ensures a clean image build.

- Type: **bool**
- **Optional**

#### platform

Set target platform to build container if server is multi-platform capable.
Expand Down

0 comments on commit 8b600fd

Please sign in to comment.