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

plugin/docker: add no-cache option #2953

Merged
merged 2 commits into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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