Skip to content

Remote buildkit -without docker #3939

Closed

Description

@RealHarshThakur

What are you trying to do?

  • I'm trying to achieve a workflow where dev machines could spin up dagger engine as the state can shared on buildkit.
  • I would like to avoid using Docker to spin up Buildkit.
  • I'm okay with the responsibility of directly having to maintain buildkit - although it would be nice if Dagger could have links to Buildkit docs for operational concerns like scaling, caching, etc.

Screenshot 2022-11-21 at 1 58 10 PM

Why is this important to you?

I think Docker should remain an optional dependency for Dagger.

Note: this was supported in v0.3.x but recent changes(from v0.4.0 I think?) seem to have stopped picking BUILDKIT_HOST .

How are you currently working around this?

I think this could be a viable solution : #3938

Activity

  1. sipsma commented on Nov 21, 2022

    @sipsma
    Contributor

    @RealHarshThakur Thanks for reaching out and filing this issue!

    We are thinking about the best way to approach our support for this in the short term and will update you when we have a decision soon.

    Two questions right away though:

    1. I saw in the other PR that you wanted to use tcp:// to connect to the remote buildkit. Do you need to also configure TLS certs to connect to it? Or do you just want to use plain tcp?
    2. We have diverged a bit from the default moby/buildkit image and now have a few customizations that require our own image. Will that work for you provided we give you a stable image repo + tags to pull from?
      • Or is there any requirement on your side that you must use moby/buildkit for whatever reason?
  2. RealHarshThakur commented on Nov 22, 2022

    @RealHarshThakur
    Author

    Thanks @sipsma for getting back.

    Do you need to also configure TLS certs to connect to it? Or do you just want to use plain tcp?

    Plain tcp works.

    is there any requirement on your side that you must use moby/buildkit for whatever reason?

    No, happy to run and operate the fork.

    Will that work for you provided we give you a stable image repo + tags to pull from?

    Yep.

  3. morlay commented on Dec 7, 2022

    @morlay
    Contributor

    With #3938, (@RealHarshThakur, Thanks)
    Engine could start before all jobs in code.

    In this way, I could be easy to migrate cue version of dagger in my CI (just buildkit in k8s, without docker in job runner)
    Engine image is not necessary.

    package main
    
    import (
    	"context"
    	"fmt"
    	"net"
    	"net/http"
    	"os"
    	"os/signal"
    	"syscall"
    	"time"
    
    	"dagger.io/dagger"
    	"github.com/dagger/dagger/engine"
    	"github.com/dagger/dagger/router"
    	"github.com/pkg/errors"
    )
    
    func main() {
    	addr := PrepareEngine()
    
    	_ = os.Setenv("DAGGER_HOST", addr)
    
    	ctx := context.Background()
    	client, err := dagger.Connect(ctx)
    	if err != nil {
    		panic(err)
    	}
    	defer client.Close()
    
    	_, err = client.Container().
    		From("alpine").
    		Export(ctx, ".tmp/image.tar")
    
    	if err != nil {
    		panic(err)
    	}
    }
    
    func PrepareEngine() string {
    	startOpts := &engine.Config{
    		RemoteAddr: "tcp://0.0.0.0:1234",
    		LogOutput:  os.Stderr,
    	}
    
    	signalCh := make(chan os.Signal, 1)
    	signal.Notify(signalCh, syscall.SIGINT, syscall.SIGTERM)
    
    	l, err := net.Listen("tcp", "localhost:12345")
    	if err != nil {
    		panic(err)
    	}
    
    	go func() {
    		<-signalCh
    		defer l.Close()
    	}()
    
    	go func() {
    		if err := engine.Start(context.Background(), startOpts, func(ctx context.Context, r *router.Router) error {
    			srv := http.Server{
    				Handler:           r,
    				ReadHeaderTimeout: 30 * time.Second,
    			}
    
    			go func() {
    				if _, err := os.Stdout.Write([]byte(fmt.Sprintf("engine serving %s\n", l.Addr().String()))); err != nil {
    					panic(err)
    				}
    			}()
    
    			err := srv.Serve(l)
    			if err != nil && !errors.Is(err, net.ErrClosed) {
    				return err
    			}
    			return nil
    		}); err != nil {
    			panic(err)
    		}
    	}()
    
    	return fmt.Sprintf("http://%s", l.Addr().String())
    }
    go run main.go
    engine serving 127.0.0.1:12345
    #1 resolve image config for docker.io/library/alpine:latest
    #1 DONE 1.1s
    
    #2 docker-image://docker.io/library/alpine:latest
    #2 resolve docker.io/library/alpine:latest
    #2 resolve docker.io/library/alpine:latest 0.4s done
    #2 CACHED
    
    #3 exporting to oci image format
    #3 exporting layers done
    #3 exporting manifest sha256:8a6462d15ee95dc0b974896a4343cba0d30863ee0c4c38385ad13732e5b7226a done
    #3 exporting config sha256:dc533ca815a1c986ab1885175887366da25aa2c58e84689685adb3d4dc1b87ae done
    #3 sending tarball 0.0s done
  4. sipsma commented on Dec 7, 2022

    @sipsma
    Contributor

    Engine image is not necessary.

    @morlay The engine image will be necessary for running any execs (on go sdk version v0.4.1 and above). We bundle a binary in the image that we use as a shim for redirecting stdio (among other things). It won't work with vanilla moby/buildkit anymore. We expect that divergence to grow over time too as we add more custom features, so it's not just temporary.

    We're working on figuring out the path to supporting provisioning outside of docker here currently (but may need to break that out into separate issues depending on the direction it goes).

  5. morlay commented on Dec 7, 2022

    @morlay
    Contributor

    @sipsma Got it.

    Could I use ghcr.io/dagger/engine with mounting /etc/buildkit/buildkitd.toml?
    Just for exposing tcp address, registry mirrors settings, and gc settings.

    If it could, I really hope #3938 could be landed ASAP.
    it is the only block for me to migrate from dagger-cue.

    Graph of @RealHarshThakur is my use case too.

    Shared buildkit (dagger/engine) will be speed up the CI with controllered caches.

  6. RealHarshThakur commented on Dec 7, 2022

    @RealHarshThakur
    Author

    @morlay I think that PR won't go through as there are different plans but I'm confident Dagger team will make it easy support our use-case. I'm on v0.3.x until it's officially sorted out

  7. morlay commented on Feb 17, 2023

    @morlay
    Contributor

    @RealHarshThakur

    Now we could use _EXPERIMENTAL_DAGGER_RUNNER_HOST=tcp://<engine_service_host>:1234 to connect remote dagger engine

    Just run the engine with custom buildkitd.toml and mount to /etc/dagger/engine.toml

    [grpc]
    address =  ["tcp://0.0.0.0:1234"]
    // pod container
    containers: engine: {
    	image: {
    		name:      _ | *"ghcr.io/dagger/engine"
    		tag:       _ | *"\(version)"
    	}
    	securityContext: privileged: true
    	ports: tcp: 1234
    	readinessProbe: {
    		exec: command: ["buildctl", "--addr=tcp://0.0.0.0:\(ports.tcp)", "debug", "workers"]
    		timeoutSeconds:   1
    		periodSeconds:    10
    		successThreshold: 1
    		failureThreshold: 3
    	}
    }
  8. RealHarshThakur commented on Feb 17, 2023

    @RealHarshThakur
    Author

    Nice! I haven't migrated over yet to the newer version but thanks for pointing out. Out of curiosity, how are you hosting the engine? Personally, I've this setup on Kubernetes deployment behind a LB in round-robin mode.

    From what you showed above, it looks as simple as changing the image. From the initial setup, I found that each Buildkit pod can only handle one request at a time i.e if a second build request arrives, the second build will fail. We're working on setting up HPA which triggers scaling based on CPU usage but I wonder if there's a more reliable metric. I assume the challenges will lie with Dagger engine too.

  9. morlay commented on Feb 18, 2023

    @morlay
    Contributor

    how are you hosting the engine?

    Just k8s deployments and simple service

    I found that each Buildkit pod can only handle one request at a time i.e if a second build request arrives, the second build will fail.

    I have not seen this issue. Maybe becasue of my buildkit configuration.

    [worker.oci]
       max-parallelism = 8

    https://github.com/moby/buildkit/blob/master/docs/buildkitd.toml.md

    Btw each buildkit instance has a lockfile at root , so I need to set my deployment when mount HostPath / PVC

    spec: replicas: 1
    spec: strategy: type: "Recreate"
  10. RealHarshThakur commented on Feb 18, 2023

    @RealHarshThakur
    Author

    Thanks @morlay. Gonna try that out.

  11. RealHarshThakur commented on May 5, 2023

    @RealHarshThakur
    Author

    I've been using self-hosted dagger engine for some time now- closing this. Thanks team :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions