Skip to content

Commit 05db2dc

Browse files
authored
Merge pull request #393 from crazy-max/remote-override
make bake definitions extensible for downstream overrides
2 parents 7d1f727 + f62e7c0 commit 05db2dc

2 files changed

Lines changed: 104 additions & 24 deletions

File tree

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ ___
1717
* [Build](#build)
1818
* [Requirements](#requirements)
1919
* [Usage](#usage)
20+
* [Remote override](#remote-override)
2021
* [Contributing](#contributing)
2122

2223
## Release
@@ -81,6 +82,55 @@ $ PKG_REF=v0.24.0 docker buildx bake pkg-buildx-*
8182
$ docker buildx bake --push --set *.tags=dockereng/packaging:buildx-v0.24.0 release-buildx
8283
```
8384

85+
### Remote override
86+
87+
Downstream repositories can reuse this repository as a remote Bake definition
88+
and extend it with a local `docker-bake.override.hcl` file instead of forking
89+
the full `docker-bake.hcl`.
90+
91+
Example local override:
92+
93+
```hcl
94+
variable "PKGS_EXTRA" {
95+
default = ["my-package"]
96+
}
97+
98+
variable "PKG_PLATFORMS_EXTRA" {
99+
default = {
100+
my-package = ["linux/amd64"]
101+
}
102+
}
103+
104+
variable "PKG_CONTEXTS_EXTRA" {
105+
default = {
106+
my-package = "cwd://pkg/my-package"
107+
}
108+
}
109+
110+
target "_pkg-my-package" {
111+
dockerfile = "cwd://pkg/my-package/Dockerfile"
112+
args = {
113+
PKG_NAME = "my-package"
114+
PKG_REPO = "https://github.com/example/my-package.git"
115+
PKG_REF = "main"
116+
}
117+
}
118+
```
119+
120+
Example invocation from the downstream repository:
121+
122+
```shell
123+
$ docker buildx bake \
124+
-f docker-bake.hcl \
125+
-f cwd://docker-bake.override.hcl \
126+
"https://github.com/docker/packaging.git#main" \
127+
pkg-my-package-debian12
128+
```
129+
130+
Use the `cwd://` prefix for local files and directories when combining a local
131+
override with a remote Bake definition. Without it, Bake resolves paths relative
132+
to the remote context instead of the current working directory.
133+
84134
## Contributing
85135

86136
Want to contribute? Awesome! You can find information about contributing to

docker-bake.hcl

Lines changed: 54 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ variable "DISTROS" {
4545
]
4646
}
4747

48-
variable "PKGS" {
49-
description = "List of packages to build from ./pkg directory. Don't forget to update _pkg-* target if you add/remove a package."
48+
variable "PKGS_BASE" {
49+
description = "Base list of packages built from this repo. Use PKGS_EXTRA in an override file to add downstream packages."
5050
default = [
5151
"buildx",
5252
"compose",
@@ -59,6 +59,49 @@ variable "PKGS" {
5959
]
6060
}
6161

62+
variable "PKGS_EXTRA" {
63+
description = "Additional packages to append from an override bake definition."
64+
default = []
65+
}
66+
67+
variable "PKGS" {
68+
description = "Full list of packages to build from ./pkg directory or an override-provided package context."
69+
default = concat(PKGS_BASE, PKGS_EXTRA)
70+
}
71+
72+
variable "PKG_PLATFORMS_BASE" {
73+
description = "Base package platform mapping. Use PKG_PLATFORMS_EXTRA in an override bake definition to add downstream packages."
74+
default = {
75+
# https://github.com/docker/buildx/blob/0c747263ef1426f5fa217fcdb616eddf33da6c2d/docker-bake.hcl#L156-L174
76+
buildx = ["darwin/amd64", "darwin/arm64", "linux/amd64", "linux/arm/v6", "linux/arm/v7", "linux/arm64", "linux/ppc64le", "linux/riscv64", "linux/s390x", "windows/amd64", "windows/arm64"]
77+
# https://github.com/docker/compose/blob/c626befee1596abcc74578cb10dd96ae1667f76f/docker-bake.hcl#L112-L124
78+
compose = ["darwin/amd64", "darwin/arm64", "linux/amd64", "linux/arm/v6", "linux/arm/v7", "linux/arm64", "linux/ppc64le", "linux/riscv64", "linux/s390x", "windows/amd64", "windows/arm64"]
79+
# https://github.com/containerd/containerd/blob/e373060a953aeaa35554e2f667043fed73ff6248/.github/workflows/ci.yml#L142-L162
80+
# https://github.com/containerd/containerd/blob/e373060a953aeaa35554e2f667043fed73ff6248/.github/workflows/ci.yml#L133-L134
81+
containerd = ["linux/amd64", "linux/arm/v6", "linux/arm/v7", "linux/arm64", "linux/ppc64le", "linux/s390x", "windows/amd64", "windows/arm64"]
82+
# https://github.com/docker/docker-credential-helpers/blob/f9d3010165b642df37215b1be945552f2c6f0e3b/docker-bake.hcl#L56-L66
83+
credential-helpers = ["darwin/amd64", "darwin/arm64", "linux/amd64", "linux/arm/v6", "linux/arm/v7", "linux/arm64", "linux/ppc64le", "linux/s390x", "windows/amd64"]
84+
# https://github.com/docker/cli/blob/84038691220e7ba3329a177e4e3357b4ee0e3a52/docker-bake.hcl#L30-L42
85+
docker-cli = ["darwin/amd64", "darwin/arm64", "linux/386", "linux/amd64", "linux/arm/v6", "linux/arm/v7", "linux/arm64", "linux/ppc64le", "linux/riscv64", "linux/s390x", "windows/amd64", "windows/arm64"]
86+
# https://github.com/moby/moby/blob/83264918d3e1c61341511e360a7277150b914b3f/docker-bake.hcl#L82-L91
87+
docker-engine = ["linux/amd64", "linux/arm/v6", "linux/arm/v7", "linux/arm64", "linux/ppc64le", "linux/s390x", "windows/amd64", "windows/arm64"]
88+
# https://github.com/docker/model-runner/blob/039f7a31c0365f9161c9b9b6bb3888161d16e388/cmd/cli/Makefile#L39-L43
89+
model = ["darwin/amd64", "darwin/arm64", "linux/amd64", "linux/arm64", "linux/arm/v7", "windows/amd64", "windows/arm64"]
90+
# https://github.com/docker/docker-agent/blob/5b9feaabe743a5ad577f2247ed55d5dcb2678e8b/Taskfile.yml#L79
91+
agent = ["darwin/amd64", "darwin/arm64", "linux/amd64", "linux/arm64", "windows/amd64", "windows/arm64"]
92+
}
93+
}
94+
95+
variable "PKG_PLATFORMS_EXTRA" {
96+
description = "Additional package platform mapping to merge from an override bake definition."
97+
default = {}
98+
}
99+
100+
variable "PKG_CONTEXTS_EXTRA" {
101+
description = "Additional package context mapping to merge from an override bake definition."
102+
default = {}
103+
}
104+
62105
variable "DISTRO_NAME" {
63106
description = "Name of the distro."
64107
default = null
@@ -631,25 +674,12 @@ target "_pkg-agent" {
631674
# Returns the list of supported platforms for a given package.
632675
function "pkgPlatforms" {
633676
params = [pkg]
634-
result = lookup({
635-
# https://github.com/docker/buildx/blob/0c747263ef1426f5fa217fcdb616eddf33da6c2d/docker-bake.hcl#L156-L174
636-
buildx = ["darwin/amd64", "darwin/arm64", "linux/amd64", "linux/arm/v6", "linux/arm/v7", "linux/arm64", "linux/ppc64le", "linux/riscv64", "linux/s390x", "windows/amd64", "windows/arm64"]
637-
# https://github.com/docker/compose/blob/c626befee1596abcc74578cb10dd96ae1667f76f/docker-bake.hcl#L112-L124
638-
compose = ["darwin/amd64", "darwin/arm64", "linux/amd64", "linux/arm/v6", "linux/arm/v7", "linux/arm64", "linux/ppc64le", "linux/riscv64", "linux/s390x", "windows/amd64", "windows/arm64"]
639-
# https://github.com/containerd/containerd/blob/e373060a953aeaa35554e2f667043fed73ff6248/.github/workflows/ci.yml#L142-L162
640-
# https://github.com/containerd/containerd/blob/e373060a953aeaa35554e2f667043fed73ff6248/.github/workflows/ci.yml#L133-L134
641-
containerd = ["linux/amd64", "linux/arm/v6", "linux/arm/v7", "linux/arm64", "linux/ppc64le", "linux/s390x", "windows/amd64", "windows/arm64"]
642-
# https://github.com/docker/docker-credential-helpers/blob/f9d3010165b642df37215b1be945552f2c6f0e3b/docker-bake.hcl#L56-L66
643-
credential-helpers = ["darwin/amd64", "darwin/arm64", "linux/amd64", "linux/arm/v6", "linux/arm/v7", "linux/arm64", "linux/ppc64le", "linux/s390x", "windows/amd64"]
644-
# https://github.com/docker/cli/blob/84038691220e7ba3329a177e4e3357b4ee0e3a52/docker-bake.hcl#L30-L42
645-
docker-cli = ["darwin/amd64", "darwin/arm64", "linux/386", "linux/amd64", "linux/arm/v6", "linux/arm/v7", "linux/arm64", "linux/ppc64le", "linux/riscv64", "linux/s390x", "windows/amd64", "windows/arm64"]
646-
# https://github.com/moby/moby/blob/83264918d3e1c61341511e360a7277150b914b3f/docker-bake.hcl#L82-L91
647-
docker-engine = ["linux/amd64", "linux/arm/v6", "linux/arm/v7", "linux/arm64", "linux/ppc64le", "linux/s390x", "windows/amd64", "windows/arm64"]
648-
# https://github.com/docker/model-runner/blob/039f7a31c0365f9161c9b9b6bb3888161d16e388/cmd/cli/Makefile#L39-L43
649-
model = ["darwin/amd64", "darwin/arm64", "linux/amd64", "linux/arm64", "linux/arm/v7", "windows/amd64", "windows/arm64"]
650-
# https://github.com/docker/docker-agent/blob/5b9feaabe743a5ad577f2247ed55d5dcb2678e8b/Taskfile.yml#L79
651-
agent = ["darwin/amd64", "darwin/arm64", "linux/amd64", "linux/arm64", "windows/amd64", "windows/arm64"]
652-
}, pkg, [])
677+
result = lookup(merge(PKG_PLATFORMS_BASE, PKG_PLATFORMS_EXTRA), pkg, [])
678+
}
679+
680+
function "pkgContext" {
681+
params = [pkg]
682+
result = lookup(PKG_CONTEXTS_EXTRA, pkg, "./pkg/${pkg}")
653683
}
654684

655685
#
@@ -694,7 +724,7 @@ target "pkg" {
694724
pkg = PKGS
695725
distro = DISTROS
696726
}
697-
context = "./pkg/${pkg}"
727+
context = pkgContext(pkg)
698728
contexts = {
699729
scripts = "./hack/scripts"
700730
}
@@ -717,7 +747,7 @@ target "verify" {
717747
pkg = PKGS
718748
distro = DISTROS
719749
}
720-
context = "./pkg/${pkg}"
750+
context = pkgContext(pkg)
721751
dockerfile = "verify.Dockerfile"
722752
contexts = {
723753
scripts = "./hack/scripts"
@@ -750,7 +780,7 @@ target "metadata" {
750780
matrix = {
751781
pkg = PKGS
752782
}
753-
context = "./pkg/${pkg}"
783+
context = pkgContext(pkg)
754784
contexts = {
755785
scripts = "./hack/scripts"
756786
}

0 commit comments

Comments
 (0)