use filepath.IsAbs to support windows paths

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2025-04-22 11:15:45 +02:00
parent 9730a20f6b
commit c370f90b73
No known key found for this signature in database
GPG Key ID: 9858809D6F8F6E7E
2 changed files with 3 additions and 3 deletions

View File

@ -1360,8 +1360,8 @@ func toBuildOpt(t *Target, inp *Input) (*build.Options, error) {
if strings.HasPrefix(bi.ContextPath, "cwd://") { if strings.HasPrefix(bi.ContextPath, "cwd://") {
bi.ContextPath = path.Clean(strings.TrimPrefix(bi.ContextPath, "cwd://")) bi.ContextPath = path.Clean(strings.TrimPrefix(bi.ContextPath, "cwd://"))
} }
if !build.IsRemoteURL(bi.ContextPath) && bi.ContextState == nil && !path.IsAbs(bi.DockerfilePath) { if !build.IsRemoteURL(bi.ContextPath) && bi.ContextState == nil && !filepath.IsAbs(bi.DockerfilePath) {
bi.DockerfilePath = path.Join(bi.ContextPath, bi.DockerfilePath) bi.DockerfilePath = filepath.Join(bi.ContextPath, bi.DockerfilePath)
} }
for k, v := range bi.NamedContexts { for k, v := range bi.NamedContexts {
if strings.HasPrefix(v.Path, "cwd://") { if strings.HasPrefix(v.Path, "cwd://") {

View File

@ -692,7 +692,7 @@ func TestHCLContextCwdPrefix(t *testing.T) {
require.Contains(t, m, "app") require.Contains(t, m, "app")
assert.Equal(t, "test", *m["app"].Dockerfile) assert.Equal(t, "test", *m["app"].Dockerfile)
assert.Equal(t, "foo", *m["app"].Context) assert.Equal(t, "foo", *m["app"].Context)
assert.Equal(t, "foo/test", bo["app"].Inputs.DockerfilePath) assert.Equal(t, filepath.Clean("foo/test"), bo["app"].Inputs.DockerfilePath)
assert.Equal(t, "foo", bo["app"].Inputs.ContextPath) assert.Equal(t, "foo", bo["app"].Inputs.ContextPath)
} }