Skip to content

Commit

Permalink
Replace usage of LocalDirs with LocalMounts in buildctl and examples
Browse files Browse the repository at this point in the history
Signed-off-by: Leandro Santiago <leandrosansilva@gmail.com>
  • Loading branch information
leandrosansilva committed Jan 29, 2024
1 parent 447b4e1 commit b3d99d6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
4 changes: 2 additions & 2 deletions cmd/buildctl/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func buildAction(clicontext *cli.Context) error {

solveOpt := client.SolveOpt{
Exports: exports,
// LocalDirs is set later
// LocalMounts is set later
Frontend: clicontext.String("frontend"),
// FrontendAttrs is set later
// OCILayouts is set later
Expand All @@ -267,7 +267,7 @@ func buildAction(clicontext *cli.Context) error {
return errors.Wrap(err, "invalid opt")
}

solveOpt.LocalDirs, err = build.ParseLocal(clicontext.StringSlice("local"))
solveOpt.LocalMounts, err = build.ParseLocal(clicontext.StringSlice("local"))
if err != nil {
return errors.Wrap(err, "invalid local")
}
Expand Down
23 changes: 21 additions & 2 deletions cmd/buildctl/build/local.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
package build

import (
"github.com/pkg/errors"
"github.com/tonistiigi/fsutil"
)

// ParseLocal parses --local
func ParseLocal(locals []string) (map[string]string, error) {
return attrMap(locals)
func ParseLocal(locals []string) (map[string]fsutil.FS, error) {
localDirs, err := attrMap(locals)
if err != nil {
return nil, errors.WithStack(err)
}

mounts := make(map[string]fsutil.FS, len(localDirs))

for k, v := range localDirs {
mounts[k], err = fsutil.NewFS(v)
if err != nil {
return nil, errors.WithStack(err)
}
}

return mounts, nil
}
18 changes: 14 additions & 4 deletions examples/build-using-dockerfile/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/moby/buildkit/util/progress/progressui"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/tonistiigi/fsutil"
"github.com/urfave/cli"
"golang.org/x/sync/errgroup"
)
Expand Down Expand Up @@ -136,9 +137,15 @@ func newSolveOpt(clicontext *cli.Context, w io.WriteCloser) (*client.SolveOpt, e
if file == "" {
file = filepath.Join(buildCtx, "Dockerfile")
}
localDirs := map[string]string{
"context": buildCtx,
"dockerfile": filepath.Dir(file),

cxtLocalMount, err := fsutil.NewFS(buildCtx)
if err != nil {
return nil, errors.New("invalid buildCtx local mount dir")
}

dockerfileLocalMount, err := fsutil.NewFS(filepath.Dir(file))
if err != nil {
return nil, errors.New("invalid dockerfile local mount dir")
}

frontend := "dockerfile.v0" // TODO: use gateway
Expand Down Expand Up @@ -173,7 +180,10 @@ func newSolveOpt(clicontext *cli.Context, w io.WriteCloser) (*client.SolveOpt, e
},
},
},
LocalDirs: localDirs,
LocalMounts: map[string]fsutil.FS{
"context": cxtLocalMount,
"dockerfile": dockerfileLocalMount,
},
Frontend: frontend,
FrontendAttrs: frontendAttrs,
}, nil
Expand Down

0 comments on commit b3d99d6

Please sign in to comment.