Skip to content

Commit

Permalink
client: allow exposing fsutil.FS through SolveOpts
Browse files Browse the repository at this point in the history
This completes propogating the fsutil.FS abstraction into the SolveOpt,
deprecating the old LocalDirs.

Since this is entirely a golang-level abstraction, we could potentially
investigate just removing the old LocalDirs directly.

Signed-off-by: Justin Chadwell <[email protected]>
  • Loading branch information
jedevc committed Aug 3, 2023
1 parent 3202433 commit 0de1f87
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 27 deletions.
28 changes: 16 additions & 12 deletions client/solve.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ import (

type SolveOpt struct {
Exports []ExportEntry
LocalDirs map[string]string
LocalDirs map[string]string // Deprecated: use LocalFiles
LocalFiles map[string]fsutil.FS
OCIStores map[string]content.Store
SharedKey string
Frontend string
Expand Down Expand Up @@ -90,7 +91,19 @@ func (c *Client) solve(ctx context.Context, def *llb.Definition, runGateway runG
return nil, errors.New("invalid with def and cb")
}

syncedDirs, err := prepareSyncedFiles(def, opt.LocalDirs)
sourceFS := make(map[string]fsutil.FS)
for k, fs := range opt.LocalFiles {
sourceFS[k] = fs
}
for k, dir := range opt.LocalDirs {
fs, err := fsutil.NewFS(dir)
if err != nil {
return nil, err
}
sourceFS[k] = fs
}

syncedDirs, err := prepareSyncedFiles(def, sourceFS)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -361,16 +374,7 @@ func (c *Client) solve(ctx context.Context, def *llb.Definition, runGateway runG
return res, nil
}

func prepareSyncedFiles(def *llb.Definition, localDirs map[string]string) (filesync.StaticDirSource, error) {
localFiles := make(map[string]fsutil.FS)
for name, d := range localDirs {
fs, err := fsutil.NewFS(d)
if err != nil {
return nil, err
}
localFiles[name] = fs
}

func prepareSyncedFiles(def *llb.Definition, localFiles map[string]fsutil.FS) (filesync.StaticDirSource, error) {
resetUIDAndGID := func(p string, st *fstypes.Stat) fsutil.MapResult {
st.Uid = 0
st.Gid = 0
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,4 @@ require (
kernel.org/pub/linux/libs/security/libcap/psx v1.2.67 // indirect
)

replace github.com/tonistiigi/fsutil => github.com/jedevc/fsutil v0.0.0-20230802153912-742c4adcbe5e
replace github.com/tonistiigi/fsutil => github.com/jedevc/fsutil v0.0.0-20230803100855-c871a2bd1eba
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -791,8 +791,8 @@ github.com/ishidawataru/sctp v0.0.0-20191218070446-00ab2ac2db07/go.mod h1:co9pwD
github.com/j-keck/arping v0.0.0-20160618110441-2cf9dc699c56/go.mod h1:ymszkNOg6tORTn+6F6j+Jc8TOr5osrynvN6ivFWZ2GA=
github.com/jaguilar/vt100 v0.0.0-20150826170717-2703a27b14ea/go.mod h1:QMdK4dGB3YhEW2BmA1wgGpPYI3HZy/5gD705PXKUVSg=
github.com/jarcoal/httpmock v1.0.5/go.mod h1:ATjnClrvW/3tijVmpL/va5Z3aAyGvqU3gCT8nX0Txik=
github.com/jedevc/fsutil v0.0.0-20230802153912-742c4adcbe5e h1:Totzxm1JcB/ySSktGMvm0WKAhqOrIzxp74g0/dlEuyk=
github.com/jedevc/fsutil v0.0.0-20230802153912-742c4adcbe5e/go.mod h1:SxX/oNQ/ag6Vaoli547ipFK9J7BZn5JqJG0JE8lf8bA=
github.com/jedevc/fsutil v0.0.0-20230803100855-c871a2bd1eba h1:vTu2wEQlaf4AKt5SfNxPl4mCecg18gGtorS3ngPQrf0=
github.com/jedevc/fsutil v0.0.0-20230803100855-c871a2bd1eba/go.mod h1:SxX/oNQ/ag6Vaoli547ipFK9J7BZn5JqJG0JE8lf8bA=
github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU=
github.com/jingyugao/rowserrcheck v0.0.0-20191204022205-72ab7603b68a/go.mod h1:xRskid8CManxVta/ALEhJha/pweKBaVG6fWgc0yH25s=
github.com/jirfag/go-printf-func-name v0.0.0-20191110105641-45db9963cdd3/go.mod h1:HEWGJkRDzjJY2sqdDwxccsGicWEf9BQOZsq2tV+xzM0=
Expand Down
26 changes: 16 additions & 10 deletions vendor/github.com/tonistiigi/fsutil/followlinks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ github.com/spdx/tools-golang/spdx/v2/v2_3
## explicit; go 1.20
github.com/stretchr/testify/assert
github.com/stretchr/testify/require
# github.com/tonistiigi/fsutil v0.0.0-20230629203738-36ef4d8c0dbb => github.com/jedevc/fsutil v0.0.0-20230802153912-742c4adcbe5e
# github.com/tonistiigi/fsutil v0.0.0-20230629203738-36ef4d8c0dbb => github.com/jedevc/fsutil v0.0.0-20230803100855-c871a2bd1eba
## explicit; go 1.19
github.com/tonistiigi/fsutil
github.com/tonistiigi/fsutil/copy
Expand Down Expand Up @@ -1026,4 +1026,4 @@ kernel.org/pub/linux/libs/security/libcap/cap
# kernel.org/pub/linux/libs/security/libcap/psx v1.2.67
## explicit; go 1.11
kernel.org/pub/linux/libs/security/libcap/psx
# github.com/tonistiigi/fsutil => github.com/jedevc/fsutil v0.0.0-20230802153912-742c4adcbe5e
# github.com/tonistiigi/fsutil => github.com/jedevc/fsutil v0.0.0-20230803100855-c871a2bd1eba

0 comments on commit 0de1f87

Please sign in to comment.