MCPcopy Index your code
hub / github.com/dagger/dagger / ConnectEngineToEngine

Function ConnectEngineToEngine

engine/client/client.go:350–437  ·  view source on GitHub ↗

ConnectEngineToEngine connects a Dagger client to another Dagger engine using an existing session connection. Session attachables are proxied back to the original client.

(ctx context.Context, params EngineToEngineParams)

Source from the content-addressed store, hash-verified

348// ConnectEngineToEngine connects a Dagger client to another Dagger engine using an existing session connection.
349// Session attachables are proxied back to the original client.
350func ConnectEngineToEngine(ctx context.Context, params EngineToEngineParams) (_ *Client, rerr error) {
351 loadWorkspaceModules, err := normalizeWorkspaceModuleLoading(
352 params.LoadWorkspaceModules,
353 params.SkipWorkspaceModules,
354 )
355 if err != nil {
356 return nil, err
357 }
358 params.LoadWorkspaceModules = loadWorkspaceModules
359 params.SkipWorkspaceModules = false
360
361 c := &Client{
362 Params: params.Params,
363 isCloudScaleOutClient: true,
364 }
365
366 if c.ID == "" {
367 c.ID = os.Getenv("DAGGER_SESSION_CLIENT_ID")
368 }
369 if c.ID == "" {
370 c.ID = identity.NewID()
371 }
372 if c.SessionID == "" {
373 c.SessionID = identity.NewID()
374 }
375 if c.SecretToken == "" {
376 c.SecretToken = uuid.New().String()
377 }
378
379 // NB: decouple from the originator's cancel ctx
380 c.internalCtx, c.internalCancel = context.WithCancelCause(context.WithoutCancel(ctx))
381 c.closeCtx, c.closeRequests = context.WithCancelCause(context.WithoutCancel(ctx))
382
383 c.eg, c.internalCtx = errgroup.WithContext(c.internalCtx)
384
385 defer func() {
386 if rerr != nil {
387 c.internalCancel(errors.New("Connect failed"))
388 }
389 }()
390
391 c.labels = params.Labels
392
393 hostname, err := os.Hostname()
394 if err != nil {
395 return nil, fmt.Errorf("get hostname: %w", err)
396 }
397 c.hostname = hostname
398
399 c.stableClientID = params.StableClientID
400
401 // NB: don't propagate this ctx, we don't want everything tucked beneath connect
402 connectCtx, span := Tracer(ctx).Start(ctx, "connect to cloud engine")
403 defer telemetry.EndWithCause(span, &rerr)
404
405 if err := c.startEngine(connectCtx, params.Params); err != nil {
406 return nil, fmt.Errorf("start engine: %w", err)
407 }

Callers

nothing calls this directly

Calls 15

startEngineMethod · 0.95
startE2ESessionMethod · 0.95
subscribeTelemetryMethod · 0.95
daggerConnectMethod · 0.95
NewIDFunction · 0.92
NormalizeVersionFunction · 0.92
TracerFunction · 0.70
GetenvMethod · 0.65
StringMethod · 0.65
NewMethod · 0.65

Tested by

no test coverage detected