Expand user home dir in client filesystem

Signed-off-by: Helder Correia <174525+helderco@users.noreply.github.com>
This commit is contained in:
Helder Correia 2022-03-25 11:50:47 -01:00
parent 2c137210a2
commit 770acd3ce2
No known key found for this signature in database
GPG Key ID: C6490D872EF1DCA7
5 changed files with 20 additions and 15 deletions

View File

@ -8,8 +8,8 @@ import (
dagger.#Plan & { dagger.#Plan & {
client: filesystem: { client: filesystem: {
"/home/user/.ssh/id_rsa": read: contents: dagger.#Secret "~/.ssh/id_rsa": read: contents: dagger.#Secret
"/home/user/.ssh/known_hosts": read: contents: dagger.#Secret "~/.ssh/known_hosts": read: contents: dagger.#Secret
} }
actions: { actions: {
@ -22,8 +22,8 @@ dagger.#Plan & {
tag: "myimage:v2" tag: "myimage:v2"
host: "ssh://root@93.184.216.34" host: "ssh://root@93.184.216.34"
ssh: { ssh: {
key: client.filesystem."/home/user/.ssh/id_rsa".read.contents key: client.filesystem."~/.ssh/id_rsa".read.contents
knownHosts: client.filesystem."/home/user/.ssh/known_hosts".read.contents knownHosts: client.filesystem."~/.ssh/known_hosts".read.contents
} }
} }
} }

View File

@ -7,15 +7,15 @@ import (
dagger.#Plan & { dagger.#Plan & {
client: filesystem: { client: filesystem: {
"/home/user/.ssh/id_rsa": read: contents: dagger.#Secret "~/.ssh/id_rsa": read: contents: dagger.#Secret
"/home/user/.ssh/known_hosts": read: contents: dagger.#Secret "~/.ssh/known_hosts": read: contents: dagger.#Secret
} }
actions: run: cli.#Run & { actions: run: cli.#Run & {
host: "ssh://root@93.184.216.34" host: "ssh://root@93.184.216.34"
ssh: { ssh: {
key: client.filesystem."/home/user/.ssh/id_rsa".read.contents key: client.filesystem."~/.ssh/id_rsa".read.contents
knownHosts: client.filesystem."/home/user/.ssh/known_hosts".read.contents knownHosts: client.filesystem."~/.ssh/known_hosts".read.contents
} }
command: name: "info" command: name: "info"
} }

View File

@ -5,7 +5,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"os" "os"
"path/filepath"
"cuelang.org/go/cue" "cuelang.org/go/cue"
"github.com/moby/buildkit/client/llb" "github.com/moby/buildkit/client/llb"
@ -66,10 +65,7 @@ func (t clientFilesystemReadTask) parsePath(v *compiler.Value) (path string, err
return return
} }
path, err = filepath.Abs(path) path, err = clientFilePath(path)
if err != nil {
return
}
return return
} }

View File

@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"io/fs" "io/fs"
"os" "os"
"path/filepath"
"cuelang.org/go/cue" "cuelang.org/go/cue"
bk "github.com/moby/buildkit/client" bk "github.com/moby/buildkit/client"
@ -28,7 +27,7 @@ func (t clientFilesystemWriteTask) Run(ctx context.Context, pctx *plancontext.Co
return nil, err return nil, err
} }
path, err = filepath.Abs(path) path, err = clientFilePath(path)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -2,7 +2,9 @@ package task
import ( import (
"fmt" "fmt"
"path/filepath"
"github.com/mitchellh/go-homedir"
"github.com/moby/buildkit/client/llb" "github.com/moby/buildkit/client/llb"
"go.dagger.io/dagger/compiler" "go.dagger.io/dagger/compiler"
) )
@ -16,3 +18,11 @@ func vertexNamef(v *compiler.Value, format string, a ...interface{}) string {
func withCustomName(v *compiler.Value, format string, a ...interface{}) llb.ConstraintsOpt { func withCustomName(v *compiler.Value, format string, a ...interface{}) llb.ConstraintsOpt {
return llb.WithCustomName(vertexNamef(v, format, a...)) return llb.WithCustomName(vertexNamef(v, format, a...))
} }
func clientFilePath(path string) (string, error) {
expanded, err := homedir.Expand(path)
if err != nil {
return "", err
}
return filepath.Abs(expanded)
}