Skip to content

Commit 9642b85

Browse files
Vigilansndeloof
authored andcommitted
Apply maybeUnixPath to ssh path in build config
Signed-off-by: Vigilans <[email protected]>
1 parent 7f822e3 commit 9642b85

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

loader/loader_test.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2477,7 +2477,7 @@ services:
24772477
assert.NilError(t, err)
24782478
sshValue, err := svc.Build.SSH.Get("key1")
24792479
assert.NilError(t, err)
2480-
assert.Equal(t, "value1", sshValue)
2480+
assert.Equal(t, filepath.Join(os.Getenv("PWD"), "value1"), sshValue)
24812481
}
24822482

24832483
func TestLoadSSHWithKeysValuesInBuildConfig(t *testing.T) {
@@ -2490,18 +2490,23 @@ services:
24902490
ssh:
24912491
- key1=value1
24922492
- key2=value2
2493+
- default
24932494
`)
24942495
assert.NilError(t, err)
24952496
svc, err := actual.GetService("test")
24962497
assert.NilError(t, err)
24972498

24982499
sshValue, err := svc.Build.SSH.Get("key1")
24992500
assert.NilError(t, err)
2500-
assert.Equal(t, "value1", sshValue)
2501+
assert.Equal(t, filepath.Join(os.Getenv("PWD"), "value1"), sshValue)
25012502

25022503
sshValue, err = svc.Build.SSH.Get("key2")
25032504
assert.NilError(t, err)
2504-
assert.Equal(t, "value2", sshValue)
2505+
assert.Equal(t, filepath.Join(os.Getenv("PWD"), "value2"), sshValue)
2506+
2507+
sshValue, err = svc.Build.SSH.Get("default")
2508+
assert.NilError(t, err)
2509+
assert.Equal(t, "", sshValue)
25052510
}
25062511

25072512
func TestProjectNameInterpolation(t *testing.T) {

paths/resolve.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func ResolveRelativePaths(project map[string]any, base string, remotes []RemoteR
3636
r.resolvers = map[tree.Path]resolver{
3737
"services.*.build.context": r.absContextPath,
3838
"services.*.build.additional_contexts.*": r.absContextPath,
39+
"services.*.build.ssh.*": r.maybeUnixPath,
3940
"services.*.env_file.*.path": r.absPath,
4041
"services.*.label_file.*": r.absPath,
4142
"services.*.extends.file": r.absExtendsPath,

paths/unix.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ import (
2424
)
2525

2626
func (r *relativePathsResolver) maybeUnixPath(a any) (any, error) {
27-
p := a.(string)
27+
p, ok := a.(string)
28+
if !ok {
29+
return a, nil
30+
}
2831
p = ExpandUser(p)
2932
// Check if source is an absolute path (either Unix or Windows), to
3033
// handle a Windows client with a Unix daemon or vice-versa.

0 commit comments

Comments
 (0)