Skip to content

Commit

Permalink
Apply maybeUnixPath to ssh path in build config
Browse files Browse the repository at this point in the history
Signed-off-by: Vigilans <[email protected]>
  • Loading branch information
Vigilans authored and ndeloof committed Jan 7, 2025
1 parent 7f822e3 commit 9642b85
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
11 changes: 8 additions & 3 deletions loader/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2477,7 +2477,7 @@ services:
assert.NilError(t, err)
sshValue, err := svc.Build.SSH.Get("key1")
assert.NilError(t, err)
assert.Equal(t, "value1", sshValue)
assert.Equal(t, filepath.Join(os.Getenv("PWD"), "value1"), sshValue)
}

func TestLoadSSHWithKeysValuesInBuildConfig(t *testing.T) {
Expand All @@ -2490,18 +2490,23 @@ services:
ssh:
- key1=value1
- key2=value2
- default
`)
assert.NilError(t, err)
svc, err := actual.GetService("test")
assert.NilError(t, err)

sshValue, err := svc.Build.SSH.Get("key1")
assert.NilError(t, err)
assert.Equal(t, "value1", sshValue)
assert.Equal(t, filepath.Join(os.Getenv("PWD"), "value1"), sshValue)

sshValue, err = svc.Build.SSH.Get("key2")
assert.NilError(t, err)
assert.Equal(t, "value2", sshValue)
assert.Equal(t, filepath.Join(os.Getenv("PWD"), "value2"), sshValue)

sshValue, err = svc.Build.SSH.Get("default")
assert.NilError(t, err)
assert.Equal(t, "", sshValue)
}

func TestProjectNameInterpolation(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions paths/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func ResolveRelativePaths(project map[string]any, base string, remotes []RemoteR
r.resolvers = map[tree.Path]resolver{
"services.*.build.context": r.absContextPath,
"services.*.build.additional_contexts.*": r.absContextPath,
"services.*.build.ssh.*": r.maybeUnixPath,
"services.*.env_file.*.path": r.absPath,
"services.*.label_file.*": r.absPath,
"services.*.extends.file": r.absExtendsPath,
Expand Down
5 changes: 4 additions & 1 deletion paths/unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ import (
)

func (r *relativePathsResolver) maybeUnixPath(a any) (any, error) {
p := a.(string)
p, ok := a.(string)
if !ok {
return a, nil
}
p = ExpandUser(p)
// Check if source is an absolute path (either Unix or Windows), to
// handle a Windows client with a Unix daemon or vice-versa.
Expand Down

0 comments on commit 9642b85

Please sign in to comment.