bake: add file-relative path opt-in#3935
Conversation
|
Needs docs follow-up: https://docs.docker.com/build/building/variables/#build-tool-configuration-variables |
fc54769 to
4ce75f7
Compare
tonistiigi
left a comment
There was a problem hiding this comment.
Looks like default . does not atm take the relative mode into account
t.Run("default-context-in-subdirectory", func(t *testing.T) {
bakefile := []byte(`
target "default" {
dockerfile-inline = <<EOT
FROM scratch
COPY marker /marker
EOT
}
`)
dir := tmpdir(
t,
fstest.CreateDir("definitions", 0700),
fstest.CreateFile("definitions/docker-bake.hcl", bakefile, 0600),
fstest.CreateFile("definitions/marker", []byte("marker"), 0600),
)
dirDest := t.TempDir()
out, err := bakeCmd(
sb,
withDir(dir),
withArgs("--file", "definitions/docker-bake.hcl", "--set", "*.output=type=local,dest="+dirDest),
withEnv("BUILDX_BAKE_FILE_RELATIVE_PATHS=1"),
)
require.NoError(t, err, out)
require.FileExists(t, filepath.Join(dirDest, "marker"))
})
| (typically `;` on Windows and `:` elsewhere), but can be changed with `BUILDX_BAKE_PATH_SEPARATOR`. | ||
|
|
||
| By default, local directory build contexts in Bake files are resolved from the | ||
| current working directory. To opt in to resolving local directory build contexts |
There was a problem hiding this comment.
Why the "first" bake file? Rather than "current" bake file. Even if this is more complicated, I think that should be the difference as the benefit of this method is that there isn't one global target directory.
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
4ce75f7 to
ad2e996
Compare
|
@tonistiigi Updated so file-relative mode is no longer based on the first Bake file. The parser now tracks the definition file that contributed each path. For HCL targets, it records the source block filename while decoding the target. For Compose files, it parses files separately in this mode so each generated target keeps the Compose file directory before normal Bake merging happens. The rebase now uses that metadata per field. An explicit
Also added coverage for the implicit default context case, for multi-file definitions using the defining file instead of the first file, and for the Compose subdirectory case. |
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
ad2e996 to
9e98fbe
Compare
fixes #1028
fixes #197
This adds an opt-in Bake mode that resolves local directory paths in
target.contextandtarget.contextsrelative to the Bake or Compose file that defines each path whenBUILDX_BAKE_FILE_RELATIVE_PATHS=1is set.Bake now accepts a parser option that records the definition file for local build context paths and rebases them after HCL or Compose files are parsed. The
buildx bakecommand enables this option fromBUILDX_BAKE_FILE_RELATIVE_PATHS, whilecwd://remains available for paths that should stay relative to the invocation directory.The opt-in also applies to targets that omit
context, so the implicit default.is resolved from the target definition file instead of the invocation directory.