Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply maybeUnixPath to ssh path in build config #723

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading