From 87a120e8e30d7dbca9830a80e73ce76590c909ff Mon Sep 17 00:00:00 2001 From: Justin Chadwell Date: Mon, 3 Apr 2023 10:48:31 +0100 Subject: [PATCH] bake: use build.IsRemoteURL Signed-off-by: Justin Chadwell --- bake/bake.go | 8 ++++---- bake/remote.go | 10 ---------- commands/bake.go | 4 ++-- 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/bake/bake.go b/bake/bake.go index c8ec628b..c5ec48af 100644 --- a/bake/bake.go +++ b/bake/bake.go @@ -789,7 +789,7 @@ func updateContext(t *build.Inputs, inp *Input) { if strings.HasPrefix(v.Path, "cwd://") || strings.HasPrefix(v.Path, "target:") || strings.HasPrefix(v.Path, "docker-image:") { continue } - if IsRemoteURL(v.Path) { + if build.IsRemoteURL(v.Path) { continue } st := llb.Scratch().File(llb.Copy(*inp.State, v.Path, "/"), llb.WithCustomNamef("set context %s to %s", k, v.Path)) @@ -803,7 +803,7 @@ func updateContext(t *build.Inputs, inp *Input) { if strings.HasPrefix(t.ContextPath, "cwd://") { return } - if IsRemoteURL(t.ContextPath) { + if build.IsRemoteURL(t.ContextPath) { return } st := llb.Scratch().File(llb.Copy(*inp.State, t.ContextPath, "/"), llb.WithCustomNamef("set context to %s", t.ContextPath)) @@ -839,7 +839,7 @@ func validateContextsEntitlements(t build.Inputs, inp *Input) error { } func checkPath(p string) error { - if IsRemoteURL(p) || strings.HasPrefix(p, "target:") || strings.HasPrefix(p, "docker-image:") { + if build.IsRemoteURL(p) || strings.HasPrefix(p, "target:") || strings.HasPrefix(p, "docker-image:") { return nil } p, err := filepath.EvalSymlinks(p) @@ -875,7 +875,7 @@ func toBuildOpt(t *Target, inp *Input) (*build.Options, error) { if t.Context != nil { contextPath = *t.Context } - if !strings.HasPrefix(contextPath, "cwd://") && !IsRemoteURL(contextPath) { + if !strings.HasPrefix(contextPath, "cwd://") && !build.IsRemoteURL(contextPath) { contextPath = path.Clean(contextPath) } dockerfilePath := "Dockerfile" diff --git a/bake/remote.go b/bake/remote.go index 939957d0..4574eb7d 100644 --- a/bake/remote.go +++ b/bake/remote.go @@ -83,16 +83,6 @@ func ReadRemoteFiles(ctx context.Context, nodes []builder.Node, url string, name return files, inp, nil } -func IsRemoteURL(url string) bool { - if _, _, ok := detectHTTPContext(url); ok { - return true - } - if _, ok := detectGitContext(url); ok { - return true - } - return false -} - func detectHTTPContext(url string) (*llb.State, string, bool) { if httpPrefix.MatchString(url) { httpContext := llb.HTTP(url, llb.Filename("context"), llb.WithCustomName("[internal] load remote build context")) diff --git a/commands/bake.go b/commands/bake.go index 9c49327e..f66e20c9 100644 --- a/commands/bake.go +++ b/commands/bake.go @@ -47,11 +47,11 @@ func runBake(dockerCli command.Cli, targets []string, in bakeOptions, cFlags com cmdContext := "cwd://" if len(targets) > 0 { - if bake.IsRemoteURL(targets[0]) { + if build.IsRemoteURL(targets[0]) { url = targets[0] targets = targets[1:] if len(targets) > 0 { - if bake.IsRemoteURL(targets[0]) { + if build.IsRemoteURL(targets[0]) { cmdContext = targets[0] targets = targets[1:] }