Skip to content

Commit bc597e6

Browse files
jedevccrazy-max
authored andcommitted
bake: fix incorrect dockerfile resolution against cwd:// context
We need to resolve the strip the cwd:// prefix before attempting to resolve the dockerfile. Otherwise, we'll get the cwd:// prefix in the dockerfile name, which isn't stripped out later. Signed-off-by: Justin Chadwell <[email protected]> (cherry picked from commit 431732f)
1 parent 687feca commit bc597e6

2 files changed

Lines changed: 11 additions & 10 deletions

File tree

bake/bake.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,12 +1048,12 @@ func toBuildOpt(t *Target, inp *Input) (*build.Options, error) {
10481048
bi.DockerfileInline = *t.DockerfileInline
10491049
}
10501050
updateContext(&bi, inp)
1051-
if !build.IsRemoteURL(bi.ContextPath) && bi.ContextState == nil && !path.IsAbs(bi.DockerfilePath) {
1052-
bi.DockerfilePath = path.Join(bi.ContextPath, bi.DockerfilePath)
1053-
}
10541051
if strings.HasPrefix(bi.ContextPath, "cwd://") {
10551052
bi.ContextPath = path.Clean(strings.TrimPrefix(bi.ContextPath, "cwd://"))
10561053
}
1054+
if !build.IsRemoteURL(bi.ContextPath) && bi.ContextState == nil && !path.IsAbs(bi.DockerfilePath) {
1055+
bi.DockerfilePath = path.Join(bi.ContextPath, bi.DockerfilePath)
1056+
}
10571057
for k, v := range bi.NamedContexts {
10581058
if strings.HasPrefix(v.Path, "cwd://") {
10591059
bi.NamedContexts[k] = build.NamedContext{Path: path.Clean(strings.TrimPrefix(v.Path, "cwd://"))}

bake/bake_test.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -386,18 +386,19 @@ func TestHCLCwdPrefix(t *testing.T) {
386386
m, g, err := ReadTargets(ctx, []File{fp}, []string{"app"}, nil, nil)
387387
require.NoError(t, err)
388388

389-
require.Equal(t, 1, len(m))
390-
_, ok := m["app"]
391-
require.True(t, ok)
392-
393-
_, err = TargetsToBuildOpt(m, &Input{})
389+
bo, err := TargetsToBuildOpt(m, &Input{})
394390
require.NoError(t, err)
395391

392+
require.Equal(t, 1, len(g))
393+
require.Equal(t, []string{"app"}, g["default"].Targets)
394+
395+
require.Equal(t, 1, len(m))
396+
require.Contains(t, m, "app")
396397
require.Equal(t, "test", *m["app"].Dockerfile)
397398
require.Equal(t, "foo", *m["app"].Context)
398399

399-
require.Equal(t, 1, len(g))
400-
require.Equal(t, []string{"app"}, g["default"].Targets)
400+
require.Equal(t, "foo/test", bo["app"].Inputs.DockerfilePath)
401+
require.Equal(t, "foo", bo["app"].Inputs.ContextPath)
401402
}
402403

403404
func TestOverrideMerge(t *testing.T) {

0 commit comments

Comments
 (0)