Skip to content

Commit

Permalink
bake: deduplicate context transfer use case
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed Jun 24, 2024
1 parent 2b2eb44 commit 8591b3b
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions content/build/bake/contexts.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,49 @@ target "app" {
In most cases you should just use a single multi-stage Dockerfile with multiple
targets for similar behavior. This case is only recommended when you have
multiple Dockerfiles that can't be easily merged into one.

## Deduplicate context transfer

Check failure on line 92 in content/build/bake/contexts.md

View workflow job for this annotation

GitHub Actions / vale

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'Deduplicate'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'Deduplicate'?", "location": {"path": "content/build/bake/contexts.md", "range": {"start": {"line": 92, "column": 4}}}, "severity": "ERROR"}

When building multiple targets using the same context, transferring the context
for each target can be inefficient. To avoid transferring the same context
multiple times, use a named context and reference it for each target.

```dockerfile
FROM alpine AS base
WORKDIR /work

FROM scratch AS ctx
COPY --link . .

FROM base AS target1
RUN apk add git
RUN --mount=from=ctx ls -l

FROM base AS target2
RUN apk add curl
RUN --mount=from=ctx ls -l
```

```hcl
group "default" {
targets = ["target1", "target2"]
}
target "ctx" {
target = "ctx"
}
target "target1" {
target = "target1"
contexts = {
ctx = "target:ctx"
}
}
target "target2" {
target = "target2"
contexts = {
ctx = "target:ctx"
}
}
```

0 comments on commit 8591b3b

Please sign in to comment.