From bffa7054b18514a925b356e1ab3ef455f006c82c Mon Sep 17 00:00:00 2001 From: David Karlsson <35727626+dvdksn@users.noreply.github.com> Date: Fri, 14 Jun 2024 12:29:16 +0200 Subject: [PATCH] build(bake): add targets description Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com> --- content/build/bake/targets.md | 95 +++++++++++++++++++++++++++++++++++ data/toc.yaml | 2 + 2 files changed, 97 insertions(+) create mode 100644 content/build/bake/targets.md diff --git a/content/build/bake/targets.md b/content/build/bake/targets.md new file mode 100644 index 0000000000..dd4f8003a1 --- /dev/null +++ b/content/build/bake/targets.md @@ -0,0 +1,95 @@ +--- +title: Bake targets +description: Learn how to define and use targets in Bake +keywords: bake, target, targets, buildx, docker, buildkit, default +--- + +A target in a Bake file represents a build invocation. It holds all the +information you would normally pass to a `docker build` command using flags. + +```hcl +target "webapp" { + dockerfile = "webapp.Dockerfile" + tags = ["docker.io/username/webapp:latest"] + context = "https://github.com/username/webapp" +} +``` + +To build a target with Bake, pass name of the target to the `bake` command. + +```console +$ docker buildx bake webapp +``` + +You can build multiple targets at once by passing multiple target names to the +`bake` command. + +```console +$ docker buildx bake webapp api tests +``` + +## Default target + +If you don't specify a target when running `docker buildx bake`, Bake will +build the target named `default`. + +```hcl +target "default" { + dockerfile = "webapp.Dockerfile" + tags = ["docker.io/username/webapp:latest"] + context = "https://github.com/username/webapp" +} +``` + +To build this target, run `docker buildx bake` without any arguments: + +```console +$ docker buildx bake +``` + +## Target properties + +The properties you can set for a target closely resemble the CLI flags for +`docker build`, with a few additional properties that are specific to Bake. + +For all the properties you can set for a target, see the [Bake reference](/build/bake/reference#target). + +## Grouping targets + +You can group targets together using the `group` block. This is useful when you +want to build multiple targets at once. + +```hcl +group "all" { + targets = ["webapp", "api", "tests"] +} + +target "webapp" { + dockerfile = "webapp.Dockerfile" + tags = ["docker.io/username/webapp:latest"] + context = "https://github.com/username/webapp" +} + +target "api" { + dockerfile = "api.Dockerfile" + tags = ["docker.io/username/api:latest"] + context = "https://github.com/username/api" +} + +target "tests" { + dockerfile = "tests.Dockerfile" + contexts = { + webapp = "target:webapp", + api = "target:api", + } + output = ["type=local,dest=build/tests"] + context = "." +} +``` + +To build all the targets in a group, pass the name of the group to the `bake` +command. + +```console +$ docker buildx bake all +``` diff --git a/data/toc.yaml b/data/toc.yaml index bffd6a99bd..96a246bd0a 100644 --- a/data/toc.yaml +++ b/data/toc.yaml @@ -1953,6 +1953,8 @@ Manuals: title: Overview - path: /build/bake/introduction/ title: Introduction + - path: /build/bake/targets/ + title: Targets - path: /build/bake/reference/ title: Bake file reference - path: /build/bake/configuring-build/