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 <me@jedevc.com>
  • Loading branch information
jedevc committed Sep 4, 2023
1 parent 8c3ea7d commit 2dea35e
Showing 1 changed file with 16 additions and 12 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

0 comments on commit 2dea35e

Please sign in to comment.