Skip to content

Commit

Permalink
resolve defaults in main rather than runtime init
Browse files Browse the repository at this point in the history
otherwise no services get forwarded and the remote end tries to talk to
a local buildkit instead
  • Loading branch information
vito committed May 30, 2022
1 parent 7f64ae9 commit 50e0fad
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
20 changes: 20 additions & 0 deletions cmd/bass/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import (
"net"
"net/http"
_ "net/http/pprof"
"net/url"
"os"
"runtime/pprof"

"github.com/adrg/xdg"
flag "github.com/spf13/pflag"
"github.com/vito/bass/pkg/bass"
"github.com/vito/bass/pkg/cli"
Expand Down Expand Up @@ -79,15 +81,33 @@ func main() {
}
}

var buildkitAddrs = bass.RuntimeAddrs{}

var DefaultConfig = bass.Config{
Runtimes: []bass.RuntimeConfig{
{
Platform: bass.LinuxPlatform,
Runtime: runtimes.BuildkitName,
Addrs: buildkitAddrs,
},
},
}

func init() {
// support respecting XDG_RUNTIME_DIR instead of assuming /run/
sockPath, _ := xdg.SearchConfigFile("bass/buildkitd.sock")

if sockPath == "" {
sockPath, _ = xdg.SearchRuntimeFile("buildkit/buildkitd.sock")
}

if sockPath == "" {
sockPath = "/run/buildkit/buildkitd.sock"
}

buildkitAddrs[runtimes.BuildkitdAddrName] = &url.URL{Scheme: "unix", Path: sockPath}
}

func root(ctx context.Context) error {
if showVersion {
printVersion(ctx)
Expand Down
29 changes: 6 additions & 23 deletions pkg/runtimes/buildkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"fmt"
"io"
"io/fs"
"net/url"
"os"
"path"
"path/filepath"
Expand All @@ -17,7 +16,6 @@ import (
"text/tabwriter"
"time"

"github.com/adrg/xdg"
"github.com/containerd/containerd/platforms"
"github.com/docker/distribution/reference"
"github.com/moby/buildkit/client"
Expand Down Expand Up @@ -96,7 +94,12 @@ func NewBuildkit(_ bass.RuntimePool, addrs bass.RuntimeAddrs, cfg *bass.Scope) (
}
}

client, err := dialBuildkit(addrs)
addr, found := addrs.Service(BuildkitdAddrName)
if !found {
return nil, fmt.Errorf("service not configured: %s", BuildkitdAddrName)
}

client, err := kitdclient.New(context.TODO(), addr.String())
if err != nil {
return nil, fmt.Errorf("dial buildkit: %w", err)
}
Expand Down Expand Up @@ -126,26 +129,6 @@ func NewBuildkit(_ bass.RuntimePool, addrs bass.RuntimeAddrs, cfg *bass.Scope) (
}, nil
}

func dialBuildkit(addrs bass.RuntimeAddrs) (*kitdclient.Client, error) {
addr, found := addrs.Service(BuildkitdAddrName)
if !found {
// support respecting XDG_RUNTIME_DIR instead of assuming /run/
sockPath, _ := xdg.SearchConfigFile("bass/buildkitd.sock")

if sockPath == "" {
sockPath, _ = xdg.SearchRuntimeFile("buildkit/buildkitd.sock")
}

if sockPath == "" {
sockPath = "/run/buildkit/buildkitd.sock"
}

addr = &url.URL{Scheme: "unix", Path: sockPath}
}

return kitdclient.New(context.TODO(), addr.String())
}

func (runtime *Buildkit) Resolve(ctx context.Context, imageRef bass.ThunkImageRef) (bass.ThunkImageRef, error) {
ref, err := imageRef.Ref()
if err != nil {
Expand Down

0 comments on commit 50e0fad

Please sign in to comment.