bake: make file-relative paths definition-scoped
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
+71
-1
@@ -805,6 +805,70 @@ target "app" {
|
||||
require.Equal(t, filepath.ToSlash(filepath.Clean("shared")), bo["app"].Inputs.NamedContexts["shared"].Path)
|
||||
}
|
||||
|
||||
func TestDefaultContextRebase(t *testing.T) {
|
||||
fp := File{
|
||||
Name: filepath.Join("definitions", "docker-bake.hcl"),
|
||||
Data: []byte(`
|
||||
target "app" {
|
||||
dockerfile-inline = <<EOT
|
||||
FROM scratch
|
||||
EOT
|
||||
}`),
|
||||
}
|
||||
|
||||
m, _, err := ReadTargets(context.TODO(), []File{fp}, []string{"app"}, nil, nil, nil, &EntitlementConf{}, ParseOpt{
|
||||
FileRelativePaths: true,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, filepath.ToSlash(filepath.Clean("definitions")), *m["app"].Context)
|
||||
|
||||
bo, err := TargetsToBuildOpt(m, &Input{})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, filepath.ToSlash(filepath.Clean("definitions")), bo["app"].Inputs.ContextPath)
|
||||
}
|
||||
|
||||
func TestDefinitionPathBase(t *testing.T) {
|
||||
fp1 := File{
|
||||
Name: filepath.Join("one", "docker-bake.hcl"),
|
||||
Data: []byte(`
|
||||
target "app" {
|
||||
context = "."
|
||||
contexts = {
|
||||
shared = "../shared"
|
||||
}
|
||||
}
|
||||
|
||||
target "implicit" {
|
||||
dockerfile-inline = <<EOT
|
||||
FROM scratch
|
||||
EOT
|
||||
}`),
|
||||
}
|
||||
fp2 := File{
|
||||
Name: filepath.Join("two", "docker-bake.hcl"),
|
||||
Data: []byte(`
|
||||
target "app" {
|
||||
tags = ["app:latest"]
|
||||
}
|
||||
|
||||
target "other" {
|
||||
context = "."
|
||||
}`),
|
||||
}
|
||||
|
||||
m, _, err := ReadTargets(context.TODO(), []File{fp1, fp2}, []string{"app", "implicit", "other"}, nil, nil, nil, &EntitlementConf{}, ParseOpt{
|
||||
FileRelativePaths: true,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, filepath.ToSlash(filepath.Clean("one")), *m["app"].Context)
|
||||
require.Equal(t, filepath.ToSlash(filepath.Clean("shared")), m["app"].Contexts["shared"])
|
||||
require.Equal(t, []string{"app:latest"}, m["app"].Tags)
|
||||
require.Equal(t, filepath.ToSlash(filepath.Clean("one")), *m["implicit"].Context)
|
||||
require.Equal(t, filepath.ToSlash(filepath.Clean("two")), *m["other"].Context)
|
||||
}
|
||||
|
||||
func TestOverridesNotRebased(t *testing.T) {
|
||||
fp := File{
|
||||
Name: filepath.Join("subdir", "docker-bake.hcl"),
|
||||
@@ -839,21 +903,27 @@ services:
|
||||
context: ./dockerfiles/debian
|
||||
additional_contexts:
|
||||
shared: ../shared
|
||||
implicit:
|
||||
build:
|
||||
dockerfile_inline: |
|
||||
FROM scratch
|
||||
`),
|
||||
}
|
||||
|
||||
m, _, err := ReadTargets(context.TODO(), []File{fp}, []string{"debian"}, nil, nil, nil, &EntitlementConf{}, ParseOpt{
|
||||
m, _, err := ReadTargets(context.TODO(), []File{fp}, []string{"debian", "implicit"}, nil, nil, nil, &EntitlementConf{}, ParseOpt{
|
||||
FileRelativePaths: true,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, filepath.ToSlash(filepath.Clean("tests/dockerfiles/debian")), *m["debian"].Context)
|
||||
require.Equal(t, filepath.ToSlash(filepath.Clean("shared")), m["debian"].Contexts["shared"])
|
||||
require.Equal(t, filepath.ToSlash(filepath.Clean("tests")), *m["implicit"].Context)
|
||||
|
||||
bo, err := TargetsToBuildOpt(m, &Input{})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, filepath.ToSlash(filepath.Clean("tests/dockerfiles/debian")), bo["debian"].Inputs.ContextPath)
|
||||
require.Equal(t, filepath.Join("tests", "dockerfiles", "debian", "Dockerfile"), bo["debian"].Inputs.DockerfilePath)
|
||||
require.Equal(t, filepath.ToSlash(filepath.Clean("tests")), bo["implicit"].Inputs.ContextPath)
|
||||
}
|
||||
|
||||
func TestOverrideMerge(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user