status
stringclasses
1 value
repo_name
stringclasses
31 values
repo_url
stringclasses
31 values
issue_id
int64
1
104k
title
stringlengths
4
233
body
stringlengths
0
186k
βŒ€
issue_url
stringlengths
38
56
pull_url
stringlengths
37
54
before_fix_sha
stringlengths
40
40
after_fix_sha
stringlengths
40
40
report_datetime
timestamp[us, tz=UTC]
language
stringclasses
5 values
commit_datetime
timestamp[us, tz=UTC]
updated_file
stringlengths
7
188
chunk_content
stringlengths
1
1.03M
closed
dagger/dagger
https://github.com/dagger/dagger
6,430
🐞 Service stop semantics work differently between SDK and Modules
### What is the issue? Initially repoted by @matipan here: https://discord.com/channels/707636530424053791/1120503349599543376/1196809237150584995 Given the current function ```go func (m *Foo) Nginx(ctx context.Context) error { svc := dag.Container(). From("nginx"). WithExposedPort(80). AsService() tunnel, err := dag.Host().Tunnel(svc).Start(ctx) if err != nil { return err } defer tunnel.Stop(ctx) endpoint, err := tunnel.Endpoint(ctx) if err != nil { return err } res, err := http.Get("http://" + endpoint + "/") if err != nil { return err } defer res.Body.Close() io.Copy(os.Stdout, res.Body) return nil } ``` upon calling `dagger call nginx`, dagger will hang for a long time in the `defer tunnel.Stop(ctx)` call. If instead of just stopping the tunnel, we stop both the service and the tunnel in the defer function, this works as intended. This doesn't happen while using the SDK directly without modules, the `defer` statement described in the example returns immediately. ### Dagger version v0.9.6 ### Steps to reproduce Run the snippet above withing a context of a module. ### Log output _No response_
https://github.com/dagger/dagger/issues/6430
https://github.com/dagger/dagger/pull/6518
8483a5e7ace6174c60e37ba395ddd1ad9b849c1e
6982b28be3c7b40fb5b5dae70601077f27bae1b8
2024-01-16T14:58:22Z
go
2024-01-29T19:37:23Z
engine/buildkit/client.go
containers: make(map[bkgw.Container]struct{}), closeCtx: closeCtx, cancel: cancel, execMetadata: make(map[digest.Digest]ContainerExecUncachedMetadata), } session, err := client.newSession(ctx) if err != nil { return nil, err } client.session = session job, err := client.GenericSolver.NewJob(client.ID()) if err != nil { return nil, err } client.job = job client.job.SessionID = client.ID() entitlementSet := entitlements.Set{} if opts.PrivilegedExecEnabled { entitlementSet[entitlements.EntitlementSecurityInsecure] = struct{}{}
closed
dagger/dagger
https://github.com/dagger/dagger
6,430
🐞 Service stop semantics work differently between SDK and Modules
### What is the issue? Initially repoted by @matipan here: https://discord.com/channels/707636530424053791/1120503349599543376/1196809237150584995 Given the current function ```go func (m *Foo) Nginx(ctx context.Context) error { svc := dag.Container(). From("nginx"). WithExposedPort(80). AsService() tunnel, err := dag.Host().Tunnel(svc).Start(ctx) if err != nil { return err } defer tunnel.Stop(ctx) endpoint, err := tunnel.Endpoint(ctx) if err != nil { return err } res, err := http.Get("http://" + endpoint + "/") if err != nil { return err } defer res.Body.Close() io.Copy(os.Stdout, res.Body) return nil } ``` upon calling `dagger call nginx`, dagger will hang for a long time in the `defer tunnel.Stop(ctx)` call. If instead of just stopping the tunnel, we stop both the service and the tunnel in the defer function, this works as intended. This doesn't happen while using the SDK directly without modules, the `defer` statement described in the example returns immediately. ### Dagger version v0.9.6 ### Steps to reproduce Run the snippet above withing a context of a module. ### Log output _No response_
https://github.com/dagger/dagger/issues/6430
https://github.com/dagger/dagger/pull/6518
8483a5e7ace6174c60e37ba395ddd1ad9b849c1e
6982b28be3c7b40fb5b5dae70601077f27bae1b8
2024-01-16T14:58:22Z
go
2024-01-29T19:37:23Z
engine/buildkit/client.go
} client.job.SetValue(entitlementsJobKey, entitlementSet) client.llbBridge = client.LLBSolver.Bridge(client.job) client.llbBridge = recordingGateway{client.llbBridge} client.dialer = &net.Dialer{} if opts.DNSConfig != nil { client.dialer.Resolver = &net.Resolver{ PreferGo: true, Dial: func(ctx context.Context, network, address string) (net.Conn, error) { if len(opts.DNSConfig.Nameservers) == 0 { return nil, errors.New("no nameservers configured") } var errs []error for _, ns := range opts.DNSConfig.Nameservers { conn, err := client.dialer.DialContext(ctx, network, net.JoinHostPort(ns, "53")) if err != nil { errs = append(errs, err) continue } return conn, nil } return nil, errors.Join(errs...) }, } }
closed
dagger/dagger
https://github.com/dagger/dagger
6,430
🐞 Service stop semantics work differently between SDK and Modules
### What is the issue? Initially repoted by @matipan here: https://discord.com/channels/707636530424053791/1120503349599543376/1196809237150584995 Given the current function ```go func (m *Foo) Nginx(ctx context.Context) error { svc := dag.Container(). From("nginx"). WithExposedPort(80). AsService() tunnel, err := dag.Host().Tunnel(svc).Start(ctx) if err != nil { return err } defer tunnel.Stop(ctx) endpoint, err := tunnel.Endpoint(ctx) if err != nil { return err } res, err := http.Get("http://" + endpoint + "/") if err != nil { return err } defer res.Body.Close() io.Copy(os.Stdout, res.Body) return nil } ``` upon calling `dagger call nginx`, dagger will hang for a long time in the `defer tunnel.Stop(ctx)` call. If instead of just stopping the tunnel, we stop both the service and the tunnel in the defer function, this works as intended. This doesn't happen while using the SDK directly without modules, the `defer` statement described in the example returns immediately. ### Dagger version v0.9.6 ### Steps to reproduce Run the snippet above withing a context of a module. ### Log output _No response_
https://github.com/dagger/dagger/issues/6430
https://github.com/dagger/dagger/pull/6518
8483a5e7ace6174c60e37ba395ddd1ad9b849c1e
6982b28be3c7b40fb5b5dae70601077f27bae1b8
2024-01-16T14:58:22Z
go
2024-01-29T19:37:23Z
engine/buildkit/client.go
return client, nil } func (c *Client) ID() string { return c.session.ID() } func (c *Client) Close() error { c.closeMu.Lock() defer c.closeMu.Unlock() select { case <-c.closeCtx.Done(): return nil default: } c.cancel() c.job.Discard() c.job.CloseProgress() c.refsMu.Lock() for rf := range c.refs { if rf != nil { rf.resultProxy.Release(context.Background()) } } c.refs = nil c.refsMu.Unlock() c.containersMu.Lock() var containerReleaseGroup errgroup.Group for ctr := range c.containers { if ctr := ctr; ctr != nil { containerReleaseGroup.Go(func() error {
closed
dagger/dagger
https://github.com/dagger/dagger
6,430
🐞 Service stop semantics work differently between SDK and Modules
### What is the issue? Initially repoted by @matipan here: https://discord.com/channels/707636530424053791/1120503349599543376/1196809237150584995 Given the current function ```go func (m *Foo) Nginx(ctx context.Context) error { svc := dag.Container(). From("nginx"). WithExposedPort(80). AsService() tunnel, err := dag.Host().Tunnel(svc).Start(ctx) if err != nil { return err } defer tunnel.Stop(ctx) endpoint, err := tunnel.Endpoint(ctx) if err != nil { return err } res, err := http.Get("http://" + endpoint + "/") if err != nil { return err } defer res.Body.Close() io.Copy(os.Stdout, res.Body) return nil } ``` upon calling `dagger call nginx`, dagger will hang for a long time in the `defer tunnel.Stop(ctx)` call. If instead of just stopping the tunnel, we stop both the service and the tunnel in the defer function, this works as intended. This doesn't happen while using the SDK directly without modules, the `defer` statement described in the example returns immediately. ### Dagger version v0.9.6 ### Steps to reproduce Run the snippet above withing a context of a module. ### Log output _No response_
https://github.com/dagger/dagger/issues/6430
https://github.com/dagger/dagger/pull/6518
8483a5e7ace6174c60e37ba395ddd1ad9b849c1e
6982b28be3c7b40fb5b5dae70601077f27bae1b8
2024-01-16T14:58:22Z
go
2024-01-29T19:37:23Z
engine/buildkit/client.go
releaseCtx, cancelRelease := context.WithTimeout(context.Background(), 30*time.Second) defer cancelRelease() return ctr.Release(releaseCtx) }) } } err := containerReleaseGroup.Wait() if err != nil { bklog.G(context.Background()).WithError(err).Error("failed to release containers") } c.containers = nil c.containersMu.Unlock() return nil } func (c *Client) withClientCloseCancel(ctx context.Context) (context.Context, context.CancelFunc, error) { c.closeMu.RLock() defer c.closeMu.RUnlock() select { case <-c.closeCtx.Done(): return nil, nil, errors.New("client closed") default: } ctx, cancel := context.WithCancel(ctx) go func() { select { case <-c.closeCtx.Done(): cancel() case <-ctx.Done():
closed
dagger/dagger
https://github.com/dagger/dagger
6,430
🐞 Service stop semantics work differently between SDK and Modules
### What is the issue? Initially repoted by @matipan here: https://discord.com/channels/707636530424053791/1120503349599543376/1196809237150584995 Given the current function ```go func (m *Foo) Nginx(ctx context.Context) error { svc := dag.Container(). From("nginx"). WithExposedPort(80). AsService() tunnel, err := dag.Host().Tunnel(svc).Start(ctx) if err != nil { return err } defer tunnel.Stop(ctx) endpoint, err := tunnel.Endpoint(ctx) if err != nil { return err } res, err := http.Get("http://" + endpoint + "/") if err != nil { return err } defer res.Body.Close() io.Copy(os.Stdout, res.Body) return nil } ``` upon calling `dagger call nginx`, dagger will hang for a long time in the `defer tunnel.Stop(ctx)` call. If instead of just stopping the tunnel, we stop both the service and the tunnel in the defer function, this works as intended. This doesn't happen while using the SDK directly without modules, the `defer` statement described in the example returns immediately. ### Dagger version v0.9.6 ### Steps to reproduce Run the snippet above withing a context of a module. ### Log output _No response_
https://github.com/dagger/dagger/issues/6430
https://github.com/dagger/dagger/pull/6518
8483a5e7ace6174c60e37ba395ddd1ad9b849c1e
6982b28be3c7b40fb5b5dae70601077f27bae1b8
2024-01-16T14:58:22Z
go
2024-01-29T19:37:23Z
engine/buildkit/client.go
} }() return ctx, cancel, nil } func (c *Client) Solve(ctx context.Context, req bkgw.SolveRequest) (_ *Result, rerr error) { ctx, cancel, err := c.withClientCloseCancel(ctx) if err != nil { return nil, err } defer cancel() ctx = withOutgoingContext(ctx) req.CacheImports = c.UpstreamCacheImports if req.Definition != nil && req.Definition.Def != nil { clientMetadata, err := engine.ClientMetadataFromContext(ctx) if err != nil { return nil, err } dag, err := DefToDAG(req.Definition) if err != nil { return nil, err } if err := dag.Walk(func(dag *OpDAG) error { execOp, ok := dag.AsExec() if !ok { return nil } if execOp.Meta == nil { execOp.Meta = &bksolverpb.Meta{}
closed
dagger/dagger
https://github.com/dagger/dagger
6,430
🐞 Service stop semantics work differently between SDK and Modules
### What is the issue? Initially repoted by @matipan here: https://discord.com/channels/707636530424053791/1120503349599543376/1196809237150584995 Given the current function ```go func (m *Foo) Nginx(ctx context.Context) error { svc := dag.Container(). From("nginx"). WithExposedPort(80). AsService() tunnel, err := dag.Host().Tunnel(svc).Start(ctx) if err != nil { return err } defer tunnel.Stop(ctx) endpoint, err := tunnel.Endpoint(ctx) if err != nil { return err } res, err := http.Get("http://" + endpoint + "/") if err != nil { return err } defer res.Body.Close() io.Copy(os.Stdout, res.Body) return nil } ``` upon calling `dagger call nginx`, dagger will hang for a long time in the `defer tunnel.Stop(ctx)` call. If instead of just stopping the tunnel, we stop both the service and the tunnel in the defer function, this works as intended. This doesn't happen while using the SDK directly without modules, the `defer` statement described in the example returns immediately. ### Dagger version v0.9.6 ### Steps to reproduce Run the snippet above withing a context of a module. ### Log output _No response_
https://github.com/dagger/dagger/issues/6430
https://github.com/dagger/dagger/pull/6518
8483a5e7ace6174c60e37ba395ddd1ad9b849c1e
6982b28be3c7b40fb5b5dae70601077f27bae1b8
2024-01-16T14:58:22Z
go
2024-01-29T19:37:23Z
engine/buildkit/client.go
} if execOp.Meta.ProxyEnv == nil { execOp.Meta.ProxyEnv = &bksolverpb.ProxyEnv{} } c.execMetadataMu.Lock() execMeta, ok := c.execMetadata[*execOp.OpDigest] if !ok { execMeta = ContainerExecUncachedMetadata{ ParentClientIDs: clientMetadata.ClientIDs(), ServerID: clientMetadata.ServerID, } c.execMetadata[*execOp.OpDigest] = execMeta } c.execMetadataMu.Unlock() var err error execOp.Meta.ProxyEnv.FtpProxy, err = execMeta.ToPBFtpProxyVal() if err != nil { return err } return nil }); err != nil { return nil, err } newDef, err := dag.Marshal() if err != nil { return nil, err
closed
dagger/dagger
https://github.com/dagger/dagger
6,430
🐞 Service stop semantics work differently between SDK and Modules
### What is the issue? Initially repoted by @matipan here: https://discord.com/channels/707636530424053791/1120503349599543376/1196809237150584995 Given the current function ```go func (m *Foo) Nginx(ctx context.Context) error { svc := dag.Container(). From("nginx"). WithExposedPort(80). AsService() tunnel, err := dag.Host().Tunnel(svc).Start(ctx) if err != nil { return err } defer tunnel.Stop(ctx) endpoint, err := tunnel.Endpoint(ctx) if err != nil { return err } res, err := http.Get("http://" + endpoint + "/") if err != nil { return err } defer res.Body.Close() io.Copy(os.Stdout, res.Body) return nil } ``` upon calling `dagger call nginx`, dagger will hang for a long time in the `defer tunnel.Stop(ctx)` call. If instead of just stopping the tunnel, we stop both the service and the tunnel in the defer function, this works as intended. This doesn't happen while using the SDK directly without modules, the `defer` statement described in the example returns immediately. ### Dagger version v0.9.6 ### Steps to reproduce Run the snippet above withing a context of a module. ### Log output _No response_
https://github.com/dagger/dagger/issues/6430
https://github.com/dagger/dagger/pull/6518
8483a5e7ace6174c60e37ba395ddd1ad9b849c1e
6982b28be3c7b40fb5b5dae70601077f27bae1b8
2024-01-16T14:58:22Z
go
2024-01-29T19:37:23Z
engine/buildkit/client.go
} req.Definition = newDef } llbRes, err := c.llbBridge.Solve(ctx, req, c.ID()) if err != nil { return nil, wrapError(ctx, err, c.ID()) } res, err := solverresult.ConvertResult(llbRes, func(rp bksolver.ResultProxy) (*ref, error) { return newRef(rp, c), nil }) if err != nil { llbRes.EachRef(func(rp bksolver.ResultProxy) error { return rp.Release(context.Background()) }) return nil, err } c.refsMu.Lock() defer c.refsMu.Unlock() if res.Ref != nil { c.refs[res.Ref] = struct{}{} } for _, rf := range res.Refs { c.refs[rf] = struct{}{} } return res, nil } func (c *Client) ResolveImageConfig(ctx context.Context, ref string, opt llb.ResolveImageConfigOpt) (string, digest.Digest, []byte, error) { ctx, cancel, err := c.withClientCloseCancel(ctx) if err != nil { return "", "", nil, err
closed
dagger/dagger
https://github.com/dagger/dagger
6,430
🐞 Service stop semantics work differently between SDK and Modules
### What is the issue? Initially repoted by @matipan here: https://discord.com/channels/707636530424053791/1120503349599543376/1196809237150584995 Given the current function ```go func (m *Foo) Nginx(ctx context.Context) error { svc := dag.Container(). From("nginx"). WithExposedPort(80). AsService() tunnel, err := dag.Host().Tunnel(svc).Start(ctx) if err != nil { return err } defer tunnel.Stop(ctx) endpoint, err := tunnel.Endpoint(ctx) if err != nil { return err } res, err := http.Get("http://" + endpoint + "/") if err != nil { return err } defer res.Body.Close() io.Copy(os.Stdout, res.Body) return nil } ``` upon calling `dagger call nginx`, dagger will hang for a long time in the `defer tunnel.Stop(ctx)` call. If instead of just stopping the tunnel, we stop both the service and the tunnel in the defer function, this works as intended. This doesn't happen while using the SDK directly without modules, the `defer` statement described in the example returns immediately. ### Dagger version v0.9.6 ### Steps to reproduce Run the snippet above withing a context of a module. ### Log output _No response_
https://github.com/dagger/dagger/issues/6430
https://github.com/dagger/dagger/pull/6518
8483a5e7ace6174c60e37ba395ddd1ad9b849c1e
6982b28be3c7b40fb5b5dae70601077f27bae1b8
2024-01-16T14:58:22Z
go
2024-01-29T19:37:23Z
engine/buildkit/client.go
} defer cancel() ctx = withOutgoingContext(ctx) return c.llbBridge.ResolveImageConfig(ctx, ref, opt) } func (c *Client) NewContainer(ctx context.Context, req bkgw.NewContainerRequest) (bkgw.Container, error) { ctx, cancel, err := c.withClientCloseCancel(ctx) if err != nil { return nil, err } defer cancel() ctx = withOutgoingContext(ctx) ctrReq := bkcontainer.NewContainerRequest{ ContainerID: identity.NewID(), NetMode: req.NetMode, Hostname: req.Hostname, Mounts: make([]bkcontainer.Mount, len(req.Mounts)), } extraHosts, err := bkcontainer.ParseExtraHosts(req.ExtraHosts) if err != nil { return nil, err } ctrReq.ExtraHosts = extraHosts eg, egctx := errgroup.WithContext(ctx) for i, m := range req.Mounts { i, m := i, m eg.Go(func() error { var workerRef *bkworker.WorkerRef if m.Ref != nil {
closed
dagger/dagger
https://github.com/dagger/dagger
6,430
🐞 Service stop semantics work differently between SDK and Modules
### What is the issue? Initially repoted by @matipan here: https://discord.com/channels/707636530424053791/1120503349599543376/1196809237150584995 Given the current function ```go func (m *Foo) Nginx(ctx context.Context) error { svc := dag.Container(). From("nginx"). WithExposedPort(80). AsService() tunnel, err := dag.Host().Tunnel(svc).Start(ctx) if err != nil { return err } defer tunnel.Stop(ctx) endpoint, err := tunnel.Endpoint(ctx) if err != nil { return err } res, err := http.Get("http://" + endpoint + "/") if err != nil { return err } defer res.Body.Close() io.Copy(os.Stdout, res.Body) return nil } ``` upon calling `dagger call nginx`, dagger will hang for a long time in the `defer tunnel.Stop(ctx)` call. If instead of just stopping the tunnel, we stop both the service and the tunnel in the defer function, this works as intended. This doesn't happen while using the SDK directly without modules, the `defer` statement described in the example returns immediately. ### Dagger version v0.9.6 ### Steps to reproduce Run the snippet above withing a context of a module. ### Log output _No response_
https://github.com/dagger/dagger/issues/6430
https://github.com/dagger/dagger/pull/6518
8483a5e7ace6174c60e37ba395ddd1ad9b849c1e
6982b28be3c7b40fb5b5dae70601077f27bae1b8
2024-01-16T14:58:22Z
go
2024-01-29T19:37:23Z
engine/buildkit/client.go
ref, ok := m.Ref.(*ref) if !ok { return fmt.Errorf("dagger: unexpected ref type: %T", m.Ref) } if ref != nil { res, err := ref.resultProxy.Result(egctx) if err != nil { return fmt.Errorf("result: %w", err) } workerRef, ok = res.Sys().(*bkworker.WorkerRef) if !ok { return fmt.Errorf("invalid res: %T", res.Sys()) } } } ctrReq.Mounts[i] = bkcontainer.Mount{ WorkerRef: workerRef, Mount: &bksolverpb.Mount{ Dest: m.Dest, Selector: m.Selector, Readonly: m.Readonly, MountType: m.MountType, CacheOpt: m.CacheOpt, SecretOpt: m.SecretOpt, SSHOpt: m.SSHOpt, }, } return nil }) }
closed
dagger/dagger
https://github.com/dagger/dagger
6,430
🐞 Service stop semantics work differently between SDK and Modules
### What is the issue? Initially repoted by @matipan here: https://discord.com/channels/707636530424053791/1120503349599543376/1196809237150584995 Given the current function ```go func (m *Foo) Nginx(ctx context.Context) error { svc := dag.Container(). From("nginx"). WithExposedPort(80). AsService() tunnel, err := dag.Host().Tunnel(svc).Start(ctx) if err != nil { return err } defer tunnel.Stop(ctx) endpoint, err := tunnel.Endpoint(ctx) if err != nil { return err } res, err := http.Get("http://" + endpoint + "/") if err != nil { return err } defer res.Body.Close() io.Copy(os.Stdout, res.Body) return nil } ``` upon calling `dagger call nginx`, dagger will hang for a long time in the `defer tunnel.Stop(ctx)` call. If instead of just stopping the tunnel, we stop both the service and the tunnel in the defer function, this works as intended. This doesn't happen while using the SDK directly without modules, the `defer` statement described in the example returns immediately. ### Dagger version v0.9.6 ### Steps to reproduce Run the snippet above withing a context of a module. ### Log output _No response_
https://github.com/dagger/dagger/issues/6430
https://github.com/dagger/dagger/pull/6518
8483a5e7ace6174c60e37ba395ddd1ad9b849c1e
6982b28be3c7b40fb5b5dae70601077f27bae1b8
2024-01-16T14:58:22Z
go
2024-01-29T19:37:23Z
engine/buildkit/client.go
err = eg.Wait() if err != nil { return nil, fmt.Errorf("wait: %w", err) } ctr, err := bkcontainer.NewContainer( context.Background(), c.Worker, c.SessionManager, bksession.NewGroup(c.ID()), ctrReq, ) if err != nil { return nil, err } c.containersMu.Lock() defer c.containersMu.Unlock() if c.containers == nil { if err := ctr.Release(context.Background()); err != nil { return nil, fmt.Errorf("release after close: %w", err) } return nil, errors.New("client closed") } c.containers[ctr] = struct{}{} return ctr, nil } func (c *Client) WriteStatusesTo(ctx context.Context, ch chan *bkclient.SolveStatus) error { return c.job.Status(ctx, ch) } func (c *Client) RegisterClient(clientID, clientHostname, secretToken string) error {
closed
dagger/dagger
https://github.com/dagger/dagger
6,430
🐞 Service stop semantics work differently between SDK and Modules
### What is the issue? Initially repoted by @matipan here: https://discord.com/channels/707636530424053791/1120503349599543376/1196809237150584995 Given the current function ```go func (m *Foo) Nginx(ctx context.Context) error { svc := dag.Container(). From("nginx"). WithExposedPort(80). AsService() tunnel, err := dag.Host().Tunnel(svc).Start(ctx) if err != nil { return err } defer tunnel.Stop(ctx) endpoint, err := tunnel.Endpoint(ctx) if err != nil { return err } res, err := http.Get("http://" + endpoint + "/") if err != nil { return err } defer res.Body.Close() io.Copy(os.Stdout, res.Body) return nil } ``` upon calling `dagger call nginx`, dagger will hang for a long time in the `defer tunnel.Stop(ctx)` call. If instead of just stopping the tunnel, we stop both the service and the tunnel in the defer function, this works as intended. This doesn't happen while using the SDK directly without modules, the `defer` statement described in the example returns immediately. ### Dagger version v0.9.6 ### Steps to reproduce Run the snippet above withing a context of a module. ### Log output _No response_
https://github.com/dagger/dagger/issues/6430
https://github.com/dagger/dagger/pull/6518
8483a5e7ace6174c60e37ba395ddd1ad9b849c1e
6982b28be3c7b40fb5b5dae70601077f27bae1b8
2024-01-16T14:58:22Z
go
2024-01-29T19:37:23Z
engine/buildkit/client.go
c.clientMu.Lock() defer c.clientMu.Unlock() existingToken, ok := c.clientIDToSecretToken[clientID] if ok { if existingToken != secretToken { return fmt.Errorf("client ID %q already registered with different secret token", clientID) } return nil } c.clientIDToSecretToken[clientID] = secretToken return nil } func (c *Client) VerifyClient(clientID, secretToken string) error { c.clientMu.RLock() defer c.clientMu.RUnlock() existingToken, ok := c.clientIDToSecretToken[clientID] if !ok { return fmt.Errorf("client ID %q not registered", clientID) } if existingToken != secretToken { return fmt.Errorf("client ID %q registered with different secret token", clientID) } return nil } func (c *Client) CombinedResult(ctx context.Context) (*Result, error) { c.refsMu.Lock()
closed
dagger/dagger
https://github.com/dagger/dagger
6,430
🐞 Service stop semantics work differently between SDK and Modules
### What is the issue? Initially repoted by @matipan here: https://discord.com/channels/707636530424053791/1120503349599543376/1196809237150584995 Given the current function ```go func (m *Foo) Nginx(ctx context.Context) error { svc := dag.Container(). From("nginx"). WithExposedPort(80). AsService() tunnel, err := dag.Host().Tunnel(svc).Start(ctx) if err != nil { return err } defer tunnel.Stop(ctx) endpoint, err := tunnel.Endpoint(ctx) if err != nil { return err } res, err := http.Get("http://" + endpoint + "/") if err != nil { return err } defer res.Body.Close() io.Copy(os.Stdout, res.Body) return nil } ``` upon calling `dagger call nginx`, dagger will hang for a long time in the `defer tunnel.Stop(ctx)` call. If instead of just stopping the tunnel, we stop both the service and the tunnel in the defer function, this works as intended. This doesn't happen while using the SDK directly without modules, the `defer` statement described in the example returns immediately. ### Dagger version v0.9.6 ### Steps to reproduce Run the snippet above withing a context of a module. ### Log output _No response_
https://github.com/dagger/dagger/issues/6430
https://github.com/dagger/dagger/pull/6518
8483a5e7ace6174c60e37ba395ddd1ad9b849c1e
6982b28be3c7b40fb5b5dae70601077f27bae1b8
2024-01-16T14:58:22Z
go
2024-01-29T19:37:23Z
engine/buildkit/client.go
mergeInputs := make([]llb.State, 0, len(c.refs)) for r := range c.refs { state, err := r.ToState() if err != nil { c.refsMu.Unlock() return nil, err } mergeInputs = append(mergeInputs, state) } c.refsMu.Unlock() llbdef, err := llb.Merge(mergeInputs, llb.WithCustomName("combined session result")).Marshal(ctx) if err != nil { return nil, err } return c.Solve(ctx, bkgw.SolveRequest{ Definition: llbdef.ToPB(), }) } func (c *Client) UpstreamCacheExport(ctx context.Context, cacheExportFuncs []ResolveCacheExporterFunc) error { ctx, cancel, err := c.withClientCloseCancel(ctx) if err != nil { return err } defer cancel() if len(cacheExportFuncs) == 0 { return nil } bklog.G(ctx).Debugf("exporting %d caches", len(cacheExportFuncs)) combinedResult, err := c.CombinedResult(ctx) if err != nil {
closed
dagger/dagger
https://github.com/dagger/dagger
6,430
🐞 Service stop semantics work differently between SDK and Modules
### What is the issue? Initially repoted by @matipan here: https://discord.com/channels/707636530424053791/1120503349599543376/1196809237150584995 Given the current function ```go func (m *Foo) Nginx(ctx context.Context) error { svc := dag.Container(). From("nginx"). WithExposedPort(80). AsService() tunnel, err := dag.Host().Tunnel(svc).Start(ctx) if err != nil { return err } defer tunnel.Stop(ctx) endpoint, err := tunnel.Endpoint(ctx) if err != nil { return err } res, err := http.Get("http://" + endpoint + "/") if err != nil { return err } defer res.Body.Close() io.Copy(os.Stdout, res.Body) return nil } ``` upon calling `dagger call nginx`, dagger will hang for a long time in the `defer tunnel.Stop(ctx)` call. If instead of just stopping the tunnel, we stop both the service and the tunnel in the defer function, this works as intended. This doesn't happen while using the SDK directly without modules, the `defer` statement described in the example returns immediately. ### Dagger version v0.9.6 ### Steps to reproduce Run the snippet above withing a context of a module. ### Log output _No response_
https://github.com/dagger/dagger/issues/6430
https://github.com/dagger/dagger/pull/6518
8483a5e7ace6174c60e37ba395ddd1ad9b849c1e
6982b28be3c7b40fb5b5dae70601077f27bae1b8
2024-01-16T14:58:22Z
go
2024-01-29T19:37:23Z
engine/buildkit/client.go
return err } cacheRes, err := ConvertToWorkerCacheResult(ctx, combinedResult) if err != nil { return fmt.Errorf("failed to convert result: %s", err) } bklog.G(ctx).Debugf("converting to solverRes") solverRes, err := solverresult.ConvertResult(combinedResult, func(rf *ref) (bksolver.CachedResult, error) { return rf.resultProxy.Result(ctx) }) if err != nil { return fmt.Errorf("failed to convert result: %s", err) } sessionGroup := bksession.NewGroup(c.ID()) eg, ctx := errgroup.WithContext(ctx) for _, exporterFunc := range cacheExportFuncs { exporterFunc := exporterFunc eg.Go(func() error { bklog.G(ctx).Debugf("getting exporter") exporter, err := exporterFunc(ctx, sessionGroup) if err != nil { return err } bklog.G(ctx).Debugf("exporting cache with %T", exporter) compressionCfg := exporter.Config().Compression err = solverresult.EachRef(solverRes, cacheRes, func(res bksolver.CachedResult, ref bkcache.ImmutableRef) error { bklog.G(ctx).Debugf("exporting cache for %s", ref.ID()) ctx := withDescHandlerCacheOpts(ctx, ref) bklog.G(ctx).Debugf("calling exporter")
closed
dagger/dagger
https://github.com/dagger/dagger
6,430
🐞 Service stop semantics work differently between SDK and Modules
### What is the issue? Initially repoted by @matipan here: https://discord.com/channels/707636530424053791/1120503349599543376/1196809237150584995 Given the current function ```go func (m *Foo) Nginx(ctx context.Context) error { svc := dag.Container(). From("nginx"). WithExposedPort(80). AsService() tunnel, err := dag.Host().Tunnel(svc).Start(ctx) if err != nil { return err } defer tunnel.Stop(ctx) endpoint, err := tunnel.Endpoint(ctx) if err != nil { return err } res, err := http.Get("http://" + endpoint + "/") if err != nil { return err } defer res.Body.Close() io.Copy(os.Stdout, res.Body) return nil } ``` upon calling `dagger call nginx`, dagger will hang for a long time in the `defer tunnel.Stop(ctx)` call. If instead of just stopping the tunnel, we stop both the service and the tunnel in the defer function, this works as intended. This doesn't happen while using the SDK directly without modules, the `defer` statement described in the example returns immediately. ### Dagger version v0.9.6 ### Steps to reproduce Run the snippet above withing a context of a module. ### Log output _No response_
https://github.com/dagger/dagger/issues/6430
https://github.com/dagger/dagger/pull/6518
8483a5e7ace6174c60e37ba395ddd1ad9b849c1e
6982b28be3c7b40fb5b5dae70601077f27bae1b8
2024-01-16T14:58:22Z
go
2024-01-29T19:37:23Z
engine/buildkit/client.go
_, err = res.CacheKeys()[0].Exporter.ExportTo(ctx, exporter, bksolver.CacheExportOpt{ ResolveRemotes: func(ctx context.Context, res bksolver.Result) ([]*bksolver.Remote, error) { ref, ok := res.Sys().(*bkworker.WorkerRef) if !ok { return nil, fmt.Errorf("invalid result: %T", res.Sys()) } bklog.G(ctx).Debugf("getting remotes for %s", ref.ID()) defer bklog.G(ctx).Debugf("got remotes for %s", ref.ID()) return ref.GetRemotes(ctx, true, bkcacheconfig.RefConfig{Compression: compressionCfg}, false, sessionGroup) }, Mode: bksolver.CacheExportModeMax, Session: sessionGroup, CompressionOpt: &compressionCfg, }) return err }) if err != nil { return err } bklog.G(ctx).Debugf("finalizing exporter") defer bklog.G(ctx).Debugf("finalized exporter") _, err = exporter.Finalize(ctx) return err }) } bklog.G(ctx).Debugf("waiting for cache export") defer bklog.G(ctx).Debugf("waited for cache export") return eg.Wait() } func withDescHandlerCacheOpts(ctx context.Context, ref bkcache.ImmutableRef) context.Context {
closed
dagger/dagger
https://github.com/dagger/dagger
6,430
🐞 Service stop semantics work differently between SDK and Modules
### What is the issue? Initially repoted by @matipan here: https://discord.com/channels/707636530424053791/1120503349599543376/1196809237150584995 Given the current function ```go func (m *Foo) Nginx(ctx context.Context) error { svc := dag.Container(). From("nginx"). WithExposedPort(80). AsService() tunnel, err := dag.Host().Tunnel(svc).Start(ctx) if err != nil { return err } defer tunnel.Stop(ctx) endpoint, err := tunnel.Endpoint(ctx) if err != nil { return err } res, err := http.Get("http://" + endpoint + "/") if err != nil { return err } defer res.Body.Close() io.Copy(os.Stdout, res.Body) return nil } ``` upon calling `dagger call nginx`, dagger will hang for a long time in the `defer tunnel.Stop(ctx)` call. If instead of just stopping the tunnel, we stop both the service and the tunnel in the defer function, this works as intended. This doesn't happen while using the SDK directly without modules, the `defer` statement described in the example returns immediately. ### Dagger version v0.9.6 ### Steps to reproduce Run the snippet above withing a context of a module. ### Log output _No response_
https://github.com/dagger/dagger/issues/6430
https://github.com/dagger/dagger/pull/6518
8483a5e7ace6174c60e37ba395ddd1ad9b849c1e
6982b28be3c7b40fb5b5dae70601077f27bae1b8
2024-01-16T14:58:22Z
go
2024-01-29T19:37:23Z
engine/buildkit/client.go
return bksolver.WithCacheOptGetter(ctx, func(_ bool, keys ...interface{}) map[interface{}]interface{} { vals := make(map[interface{}]interface{}) for _, k := range keys { if key, ok := k.(bkcache.DescHandlerKey); ok { if handler := ref.DescHandler(digest.Digest(key)); handler != nil { vals[k] = handler } } } return vals }) } func (c *Client) ListenHostToContainer( ctx context.Context, hostListenAddr, proto, upstream string, ) (*session.ListenResponse, func() error, error) { ctx, cancel, err := c.withClientCloseCancel(ctx) if err != nil { return nil, nil, err } clientMetadata, err := engine.ClientMetadataFromContext(ctx) if err != nil { cancel() return nil, nil, fmt.Errorf("failed to get requester session ID: %s", err) } clientCaller, err := c.SessionManager.Get(ctx, clientMetadata.ClientID, false) if err != nil { cancel() return nil, nil, fmt.Errorf("failed to get requester session: %s", err) }
closed
dagger/dagger
https://github.com/dagger/dagger
6,430
🐞 Service stop semantics work differently between SDK and Modules
### What is the issue? Initially repoted by @matipan here: https://discord.com/channels/707636530424053791/1120503349599543376/1196809237150584995 Given the current function ```go func (m *Foo) Nginx(ctx context.Context) error { svc := dag.Container(). From("nginx"). WithExposedPort(80). AsService() tunnel, err := dag.Host().Tunnel(svc).Start(ctx) if err != nil { return err } defer tunnel.Stop(ctx) endpoint, err := tunnel.Endpoint(ctx) if err != nil { return err } res, err := http.Get("http://" + endpoint + "/") if err != nil { return err } defer res.Body.Close() io.Copy(os.Stdout, res.Body) return nil } ``` upon calling `dagger call nginx`, dagger will hang for a long time in the `defer tunnel.Stop(ctx)` call. If instead of just stopping the tunnel, we stop both the service and the tunnel in the defer function, this works as intended. This doesn't happen while using the SDK directly without modules, the `defer` statement described in the example returns immediately. ### Dagger version v0.9.6 ### Steps to reproduce Run the snippet above withing a context of a module. ### Log output _No response_
https://github.com/dagger/dagger/issues/6430
https://github.com/dagger/dagger/pull/6518
8483a5e7ace6174c60e37ba395ddd1ad9b849c1e
6982b28be3c7b40fb5b5dae70601077f27bae1b8
2024-01-16T14:58:22Z
go
2024-01-29T19:37:23Z
engine/buildkit/client.go
conn := clientCaller.Conn() tunnelClient := session.NewTunnelListenerClient(conn) listener, err := tunnelClient.Listen(ctx) if err != nil { cancel() return nil, nil, fmt.Errorf("failed to listen: %s", err) } err = listener.Send(&session.ListenRequest{ Addr: hostListenAddr, Protocol: proto, }) if err != nil { cancel() return nil, nil, fmt.Errorf("failed to send listen request: %s", err) } listenRes, err := listener.Recv() if err != nil { cancel() return nil, nil, fmt.Errorf("failed to receive listen response: %s", err) } conns := map[string]net.Conn{} connsL := &sync.Mutex{} sendL := &sync.Mutex{} wg := new(sync.WaitGroup) wg.Add(1) go func() { defer wg.Done() for { res, err := listener.Recv() if err != nil {
closed
dagger/dagger
https://github.com/dagger/dagger
6,430
🐞 Service stop semantics work differently between SDK and Modules
### What is the issue? Initially repoted by @matipan here: https://discord.com/channels/707636530424053791/1120503349599543376/1196809237150584995 Given the current function ```go func (m *Foo) Nginx(ctx context.Context) error { svc := dag.Container(). From("nginx"). WithExposedPort(80). AsService() tunnel, err := dag.Host().Tunnel(svc).Start(ctx) if err != nil { return err } defer tunnel.Stop(ctx) endpoint, err := tunnel.Endpoint(ctx) if err != nil { return err } res, err := http.Get("http://" + endpoint + "/") if err != nil { return err } defer res.Body.Close() io.Copy(os.Stdout, res.Body) return nil } ``` upon calling `dagger call nginx`, dagger will hang for a long time in the `defer tunnel.Stop(ctx)` call. If instead of just stopping the tunnel, we stop both the service and the tunnel in the defer function, this works as intended. This doesn't happen while using the SDK directly without modules, the `defer` statement described in the example returns immediately. ### Dagger version v0.9.6 ### Steps to reproduce Run the snippet above withing a context of a module. ### Log output _No response_
https://github.com/dagger/dagger/issues/6430
https://github.com/dagger/dagger/pull/6518
8483a5e7ace6174c60e37ba395ddd1ad9b849c1e
6982b28be3c7b40fb5b5dae70601077f27bae1b8
2024-01-16T14:58:22Z
go
2024-01-29T19:37:23Z
engine/buildkit/client.go
bklog.G(ctx).Warnf("listener recv err: %s", err) return } connID := res.GetConnId() if connID == "" { continue } connsL.Lock() conn, found := conns[connID] connsL.Unlock() if !found { conn, err := c.dialer.Dial(proto, upstream) if err != nil { bklog.G(ctx).Warnf("failed to dial %s %s: %s", proto, upstream, err) return } connsL.Lock() conns[connID] = conn connsL.Unlock() wg.Add(1) go func() { defer wg.Done() data := make([]byte, 32*1024) for { n, err := conn.Read(data) if err != nil { return } sendL.Lock() err = listener.Send(&session.ListenRequest{
closed
dagger/dagger
https://github.com/dagger/dagger
6,430
🐞 Service stop semantics work differently between SDK and Modules
### What is the issue? Initially repoted by @matipan here: https://discord.com/channels/707636530424053791/1120503349599543376/1196809237150584995 Given the current function ```go func (m *Foo) Nginx(ctx context.Context) error { svc := dag.Container(). From("nginx"). WithExposedPort(80). AsService() tunnel, err := dag.Host().Tunnel(svc).Start(ctx) if err != nil { return err } defer tunnel.Stop(ctx) endpoint, err := tunnel.Endpoint(ctx) if err != nil { return err } res, err := http.Get("http://" + endpoint + "/") if err != nil { return err } defer res.Body.Close() io.Copy(os.Stdout, res.Body) return nil } ``` upon calling `dagger call nginx`, dagger will hang for a long time in the `defer tunnel.Stop(ctx)` call. If instead of just stopping the tunnel, we stop both the service and the tunnel in the defer function, this works as intended. This doesn't happen while using the SDK directly without modules, the `defer` statement described in the example returns immediately. ### Dagger version v0.9.6 ### Steps to reproduce Run the snippet above withing a context of a module. ### Log output _No response_
https://github.com/dagger/dagger/issues/6430
https://github.com/dagger/dagger/pull/6518
8483a5e7ace6174c60e37ba395ddd1ad9b849c1e
6982b28be3c7b40fb5b5dae70601077f27bae1b8
2024-01-16T14:58:22Z
go
2024-01-29T19:37:23Z
engine/buildkit/client.go
ConnId: connID, Data: data[:n], }) sendL.Unlock() if err != nil { return } } }() } if res.Data != nil { _, err = conn.Write(res.Data) if err != nil { return } } } }() return listenRes, func() error { defer cancel() sendL.Lock() err := listener.CloseSend() sendL.Unlock() if err == nil { wg.Wait() } return err }, nil } func withOutgoingContext(ctx context.Context) context.Context {
closed
dagger/dagger
https://github.com/dagger/dagger
6,430
🐞 Service stop semantics work differently between SDK and Modules
### What is the issue? Initially repoted by @matipan here: https://discord.com/channels/707636530424053791/1120503349599543376/1196809237150584995 Given the current function ```go func (m *Foo) Nginx(ctx context.Context) error { svc := dag.Container(). From("nginx"). WithExposedPort(80). AsService() tunnel, err := dag.Host().Tunnel(svc).Start(ctx) if err != nil { return err } defer tunnel.Stop(ctx) endpoint, err := tunnel.Endpoint(ctx) if err != nil { return err } res, err := http.Get("http://" + endpoint + "/") if err != nil { return err } defer res.Body.Close() io.Copy(os.Stdout, res.Body) return nil } ``` upon calling `dagger call nginx`, dagger will hang for a long time in the `defer tunnel.Stop(ctx)` call. If instead of just stopping the tunnel, we stop both the service and the tunnel in the defer function, this works as intended. This doesn't happen while using the SDK directly without modules, the `defer` statement described in the example returns immediately. ### Dagger version v0.9.6 ### Steps to reproduce Run the snippet above withing a context of a module. ### Log output _No response_
https://github.com/dagger/dagger/issues/6430
https://github.com/dagger/dagger/pull/6518
8483a5e7ace6174c60e37ba395ddd1ad9b849c1e
6982b28be3c7b40fb5b5dae70601077f27bae1b8
2024-01-16T14:58:22Z
go
2024-01-29T19:37:23Z
engine/buildkit/client.go
md, ok := metadata.FromIncomingContext(ctx) if ok { ctx = metadata.NewOutgoingContext(ctx, md) } return ctx } type ContainerExecUncachedMetadata struct { ParentClientIDs []string `json:"parentClientIDs,omitempty"` ServerID string `json:"serverID,omitempty"` } func (md ContainerExecUncachedMetadata) ToPBFtpProxyVal() (string, error) { b, err := json.Marshal(md) if err != nil { return "", err } return string(b), nil } func (md *ContainerExecUncachedMetadata) FromEnv(envKV string) (bool, error) { _, val, ok := strings.Cut(envKV, "ftp_proxy=") if !ok { return false, nil } err := json.Unmarshal([]byte(val), md) if err != nil { return false, err } return true, nil }
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/call.go
package main import ( "bytes" "encoding/json" "fmt" "io" "os" "path/filepath" "github.com/spf13/cobra" ) var downloadCmd = &cobra.Command{ Use: "download", Short: "Download an asset from module function", Aliases: []string{"export", "dl"}, Hidden: true, SilenceUsage: true, DisableFlagParsing: true, Args: func(cmd *cobra.Command, args []string) error { return fmt.Errorf(`%q has been replaced by "dagger call COMMANDS... --output=PATH"`, cmd.CommandPath()) }, Run: func(cmd *cobra.Command, args []string) { }, } var upCmd = &cobra.Command{ Use: "up", Short: "Start a service and expose its ports to the host", Hidden: true, SilenceUsage: true,
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/call.go
DisableFlagParsing: true, Args: func(cmd *cobra.Command, args []string) error { return fmt.Errorf(`%q has been replaced by "dagger call COMMANDS... up"`, cmd.CommandPath()) }, Run: func(cmd *cobra.Command, args []string) { }, } var shellCmd = &cobra.Command{ Use: "shell", Short: "Open a shell in a container", Hidden: true, SilenceUsage: true, DisableFlagParsing: true, Args: func(cmd *cobra.Command, args []string) error { return fmt.Errorf(`%q has been replaced by "dagger call COMMANDS... shell"`, cmd.CommandPath()) }, Run: func(cmd *cobra.Command, args []string) { }, } var outputPath string var jsonOutput bool var callCmd = &FuncCommand{ Name: "call", Short: "Call a module function", Long: `Call a module function and print the result If the last argument is either Container, Directory, or File, the pipeline will be evaluated (the result of calling *sync*) without presenting any output. Providing the --output option (shorthand: -o) is equivalent to calling *export*
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/call.go
instead. To print a property of these core objects, continue chaining by appending it to the end of the command (for example, *stdout*, *entries*, or *contents*). `, Init: func(cmd *cobra.Command) { cmd.PersistentFlags().BoolVar(&jsonOutput, "json", false, "Present result as JSON") cmd.PersistentFlags().StringVarP(&outputPath, "output", "o", "", "Path in the host to save the result to") }, OnSelectObjectLeaf: func(c *FuncCommand, name string) error { switch name { case Container, Directory, File: if outputPath != "" { c.Select("export") c.Arg("path", outputPath) if name == File { c.Arg("allowParentDirPath", true) } return nil } c.Select("sync") case Terminal: c.Select("websocketEndpoint") default: return fmt.Errorf("return type %q requires a sub-command", name) } return nil }, BeforeRequest: func(_ *FuncCommand, _ *cobra.Command, modType *modTypeDef) error { if modType.Name() != Terminal { return nil
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/call.go
} if silent || !(progress == "auto" && autoTTY || progress == "tty") { return fmt.Errorf("running shell without the TUI is not supported") } if debug { return fmt.Errorf("running shell with --debug is not supported") } if outputPath != "" { return fmt.Errorf("running shell with --output is not supported") } return nil }, AfterResponse: func(c *FuncCommand, cmd *cobra.Command, modType *modTypeDef, response any) error { switch modType.Name() { case Terminal: termEndpoint, ok := response.(string) if !ok { return fmt.Errorf("unexpected response %T: %+v", response, response) } return attachToShell(cmd.Context(), c.c, termEndpoint) case Container, Directory, File: if outputPath != "" { logOutputSuccess(cmd, outputPath) return nil }
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/call.go
cmd.PrintErrf("%s evaluated. Use \"%s --help\" to see available sub-commands.\n", modType.Name(), cmd.CommandPath()) return nil default: / / / writer := cmd.OutOrStdout() if outputPath != "" { file, err := openOutputFile(outputPath) if err != nil { return fmt.Errorf("couldn't write output to file: %w", err) } defer func() { file.Close() logOutputSuccess(cmd, outputPath) }() writer = io.MultiWriter(writer, file) } / if jsonOutput { / var buf bytes.Buffer encoder := json.NewEncoder(&buf)
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/call.go
encoder.SetEscapeHTML(false) encoder.SetIndent("", " ") if err := encoder.Encode(response); err != nil { return err } fmt.Fprintf(writer, "%s\n", buf.String()) return nil } return printFunctionResult(writer, response) } }, } / func openOutputFile(path string) (*os.File, error) { if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil { return nil, err } return os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o644) } / func logOutputSuccess(cmd *cobra.Command, path string) { path, err := filepath.Abs(path) if err != nil { / cmd.PrintErrf("WARNING: failed to get absolute path: %s\n", err) path = outputPath } cmd.PrintErrf("Saved output to %q.\n", path) } func printFunctionResult(w io.Writer, r any) error {
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/call.go
switch t := r.(type) { case []any: / for _, v := range t { if err := printFunctionResult(w, v); err != nil { return err } } return nil case map[string]any: / for _, v := range t { if err := printFunctionResult(w, v); err != nil { return err } } return nil default: fmt.Fprintf(w, "%+v\n", t) } return nil }
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/flags.go
package main import ( "bytes" "context" "crypto/sha256" "encoding/csv" "encoding/hex" "fmt" "io" "net" "net/url" "os" "os/exec" "reflect" "strconv" "strings" "dagger.io/dagger" "github.com/moby/buildkit/util/gitutil" "github.com/spf13/pflag" ) func GetCustomFlagValue(name string) DaggerValue {
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/flags.go
switch name { case Container: return &containerValue{} case Directory: return &directoryValue{} case File: return &fileValue{} case Secret: return &secretValue{} case Service: return &serviceValue{} case PortForward: return &portForwardValue{} } return nil } func GetCustomFlagValueSlice(name string) DaggerValue {
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/flags.go
switch name { case Container: return &sliceValue[*containerValue]{} case Directory: return &sliceValue[*directoryValue]{} case File: return &sliceValue[*fileValue]{} case Secret: return &sliceValue[*secretValue]{} case Service: return &sliceValue[*serviceValue]{} case PortForward: return &sliceValue[*portForwardValue]{} } return nil } type DaggerValue interface { pflag.Value Get(context.Context, *dagger.Client) (any, error) } type sliceValue[T DaggerValue] struct {
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/flags.go
value []T } func (v *sliceValue[T]) Type() string { var t T return t.Type() } func (v *sliceValue[T]) String() string { ss := []string{} for _, v := range v.value { ss = append(ss, v.String()) } out, _ := writeAsCSV(ss) return "[" + out + "]" } func (v *sliceValue[T]) Get(ctx context.Context, c *dagger.Client) (any, error) { out := make([]any, len(v.value)) for i, v := range v.value { outV, err := v.Get(ctx, c) if err != nil { return nil, err
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/flags.go
} out[i] = outV } return out, nil } func (v *sliceValue[T]) Set(s string) error { rmQuote := strings.NewReplacer(`"`, "", `'`, "", "`", "") ss, err := readAsCSV(rmQuote.Replace(s)) if err != nil && err != io.EOF { return err } out := make([]T, 0, len(ss)) for _, s := range ss { var v T if typ := reflect.TypeOf(v); typ.Kind() == reflect.Ptr { v = reflect.New(typ.Elem()).Interface().(T) } if err := v.Set(strings.TrimSpace(s)); err != nil { return err } out = append(out, v) } v.value = append(v.value, out...) return nil } type containerValue struct {
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/flags.go
address string } func (v *containerValue) Type() string { return Container } func (v *containerValue) Set(s string) error { if s == "" { return fmt.Errorf("container address cannot be empty") } v.address = s return nil } func (v *containerValue) String() string { return v.address } func (v *containerValue) Get(_ context.Context, c *dagger.Client) (any, error) { if v.address == "" { return nil, fmt.Errorf("container address cannot be empty") } return c.Container().From(v.String()), nil } type directoryValue struct {
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/flags.go
address string } func (v *directoryValue) Type() string { return Directory } func (v *directoryValue) Set(s string) error { if s == "" { return fmt.Errorf("directory address cannot be empty") } v.address = s return nil } func (v *directoryValue) String() string { return v.address } func parseGit(urlStr string) (*gitutil.GitURL, error) { u, err := gitutil.ParseURL(urlStr) if err != nil { return nil, err } if u.Fragment == nil { u.Fragment = &gitutil.GitURLFragment{} } if u.Fragment.Ref == "" {
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/flags.go
u.Fragment.Ref = "main" } return u, nil } func (v *directoryValue) Get(_ context.Context, dag *dagger.Client) (any, error) { if v.String() == "" { return nil, fmt.Errorf("directory address cannot be empty") } parsedGit, err := parseGit(v.String()) if err == nil { gitOpts := dagger.GitOpts{ KeepGitDir: true, } if authSock, ok := os.LookupEnv("SSH_AUTH_SOCK"); ok { gitOpts.SSHAuthSocket = dag.Host().UnixSocket(authSock) } gitDir := dag.Git(parsedGit.Remote, gitOpts).Branch(parsedGit.Fragment.Ref).Tree() if subdir := parsedGit.Fragment.Subdir; subdir != "" { gitDir = gitDir.Directory(subdir) } return gitDir, nil } vStr := v.String() vStr = strings.TrimPrefix(vStr, "file:") return dag.Host().Directory(vStr), nil } type fileValue struct {
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/flags.go
path string } func (v *fileValue) Type() string { return File } func (v *fileValue) Set(s string) error { if s == "" { return fmt.Errorf("file path cannot be empty") } v.path = s return nil } func (v *fileValue) String() string { return v.path } func (v *fileValue) Get(_ context.Context, c *dagger.Client) (any, error) { if v.String() == "" { return nil, fmt.Errorf("file path cannot be empty") } return c.Host().File(v.String()), nil } type secretValue struct { secretSource string sourceVal string } const ( envSecretSource = "env" fileSecretSource = "file" commandSecretSource = "cmd"
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/flags.go
) func (v *secretValue) Type() string { return Secret } func (v *secretValue) Set(s string) error { secretSource, val, ok := strings.Cut(s, ":") if !ok { val = secretSource secretSource = envSecretSource } v.secretSource = secretSource v.sourceVal = val return nil } func (v *secretValue) String() string { return fmt.Sprintf("%s:%s", v.secretSource, v.sourceVal) } func (v *secretValue) Get(ctx context.Context, c *dagger.Client) (any, error) { var plaintext string switch v.secretSource { case envSecretSource: envPlaintext, ok := os.LookupEnv(v.sourceVal) if !ok { key := v.sourceVal if len(key) >= 4 { key = key[:3] + "..."
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/flags.go
} return nil, fmt.Errorf("secret env var not found: %q", key) } plaintext = envPlaintext case fileSecretSource: filePlaintext, err := os.ReadFile(v.sourceVal) if err != nil { return nil, fmt.Errorf("failed to read secret file %q: %w", v.sourceVal, err) } plaintext = string(filePlaintext) case commandSecretSource: stdoutBytes, err := exec.CommandContext(ctx, "sh", "-c", v.sourceVal).Output() if err != nil { return nil, fmt.Errorf("failed to run secret command %q: %w", v.sourceVal, err) } plaintext = string(stdoutBytes) default: return nil, fmt.Errorf("unsupported secret arg source: %q", v.secretSource) } hash := sha256.Sum256([]byte(plaintext)) secretName := hex.EncodeToString(hash[:]) return c.SetSecret(secretName, plaintext), nil } type serviceValue struct { address string host string ports []dagger.PortForward
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/flags.go
} func (v *serviceValue) Type() string { return Service } func (v *serviceValue) String() string { return v.address } func (v *serviceValue) Set(s string) error { if s == "" { return fmt.Errorf("service address cannot be empty") } u, err := url.Parse(s) if err != nil { return err } switch u.Scheme { case "tcp": host, port, err := net.SplitHostPort(u.Host) if err != nil { return err } nPort, err := strconv.Atoi(port) if err != nil { return err } v.host = host v.ports = append(v.ports, dagger.PortForward{ Backend: nPort, Frontend: nPort, Protocol: dagger.Tcp,
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/flags.go
}) case "udp": host, port, err := net.SplitHostPort(u.Host) if err != nil { return err } nPort, err := strconv.Atoi(port) if err != nil { return err } v.host = host v.ports = append(v.ports, dagger.PortForward{ Backend: nPort, Frontend: nPort, Protocol: dagger.Udp, }) default: return fmt.Errorf("unsupported service address. Must be a valid tcp: or udp: URL") } v.address = s return nil } func (v *serviceValue) Get(ctx context.Context, c *dagger.Client) (any, error) { svc, err := c.Host().Service(v.ports, dagger.HostServiceOpts{Host: v.host}).Start(ctx) if err != nil { return nil, fmt.Errorf("failed to start service: %w", err) } return svc, nil } type portForwardValue struct {
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/flags.go
frontend int backend int } func (v *portForwardValue) Type() string { return PortForward } func (v *portForwardValue) Set(s string) error { if s == "" { return fmt.Errorf("portForward setting cannot be empty") } frontendStr, backendStr, ok := strings.Cut(s, ":") if !ok { return fmt.Errorf("portForward setting not in the form of frontend:backend: %q", s) } frontend, err := strconv.Atoi(frontendStr) if err != nil { return fmt.Errorf("portForward frontend not a valid integer: %q", frontendStr) } v.frontend = frontend backend, err := strconv.Atoi(backendStr) if err != nil { return fmt.Errorf("portForward backend not a valid integer: %q", backendStr) } v.backend = backend return nil } func (v *portForwardValue) String() string { return fmt.Sprintf("%d:%d", v.frontend, v.backend) } func (v *portForwardValue) Get(_ context.Context, c *dagger.Client) (any, error) {
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/flags.go
return &dagger.PortForward{ Frontend: v.frontend, Backend: v.backend, }, nil } func (r *modFunctionArg) AddFlag(flags *pflag.FlagSet, dag *dagger.Client) (any, error) { name := r.FlagName() usage := r.Description if flags.Lookup(name) != nil { return nil, fmt.Errorf("flag already exists: %s", name) } switch r.TypeDef.Kind { case dagger.StringKind: val, _ := getDefaultValue[string](r) return flags.String(name, val, usage), nil case dagger.IntegerKind: val, _ := getDefaultValue[int](r) return flags.Int(name, val, usage), nil case dagger.BooleanKind: val, _ := getDefaultValue[bool](r) return flags.Bool(name, val, usage), nil case dagger.ObjectKind: objName := r.TypeDef.AsObject.Name if val := GetCustomFlagValue(objName); val != nil { flags.Var(val, name, usage) return val, nil } return nil, fmt.Errorf("unsupported object type %q for flag: %s", objName, name) case dagger.InputKind:
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/flags.go
inputName := r.TypeDef.AsInput.Name if val := GetCustomFlagValue(inputName); val != nil { flags.Var(val, name, usage) return val, nil } return nil, fmt.Errorf("unsupported input type %q for flag: %s", inputName, name) case dagger.ListKind: elementType := r.TypeDef.AsList.ElementTypeDef switch elementType.Kind { case dagger.StringKind: val, _ := getDefaultValue[[]string](r) return flags.StringSlice(name, val, usage), nil case dagger.IntegerKind: val, _ := getDefaultValue[[]int](r) return flags.IntSlice(name, val, usage), nil case dagger.BooleanKind: val, _ := getDefaultValue[[]bool](r) return flags.BoolSlice(name, val, usage), nil case dagger.ObjectKind: objName := elementType.AsObject.Name if val := GetCustomFlagValueSlice(objName); val != nil { flags.Var(val, name, usage) return val, nil } return nil, fmt.Errorf("unsupported list of objects %q for flag: %s", objName, name) case dagger.InputKind: inputName := elementType.AsInput.Name if val := GetCustomFlagValueSlice(inputName); val != nil {
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/flags.go
flags.Var(val, name, usage) return val, nil } return nil, fmt.Errorf("unsupported list of input type %q for flag: %s", inputName, name) case dagger.ListKind: return nil, fmt.Errorf("unsupported list of lists for flag: %s", name) } } return nil, fmt.Errorf("unsupported type for argument: %s", r.Name) } func readAsCSV(val string) ([]string, error) { if val == "" { return []string{}, nil } stringReader := strings.NewReader(val) csvReader := csv.NewReader(stringReader) return csvReader.Read() } func writeAsCSV(vals []string) (string, error) { b := &bytes.Buffer{} w := csv.NewWriter(b) err := w.Write(vals) if err != nil { return "", err } w.Flush() return strings.TrimSuffix(b.String(), "\n"), nil }
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/functions.go
package main import ( "context" "errors" "fmt" "io" "os" "sort" "strings" "dagger.io/dagger" "dagger.io/dagger/querybuilder" "github.com/dagger/dagger/engine/client" "github.com/juju/ansiterm/tabwriter" "github.com/muesli/termenv" "github.com/spf13/cobra" "github.com/spf13/pflag"
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/functions.go
"github.com/vito/progrock" ) const ( Directory string = "Directory" Container string = "Container" File string = "File" Secret string = "Secret" Service string = "Service" Terminal string = "Terminal" PortForward string = "PortForward" ) var funcGroup = &cobra.Group{ ID: "functions", Title: "Functions", } var funcCmds = FuncCommands{ funcListCmd, callCmd, } var funcListCmd = &FuncCommand{ Name: "functions", Short: `List available functions`, Execute: func(fc *FuncCommand, cmd *cobra.Command) error { tw := tabwriter.NewWriter(cmd.OutOrStdout(), 0, 0, 3, ' ', tabwriter.DiscardEmptyColumns) var o functionProvider = fc.mod.GetMainObject() fmt.Fprintf(tw, "%s\t%s\n", termenv.String("Name").Bold(), termenv.String("Description").Bold(), )
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/functions.go
for _, field := range cmd.Flags().Args() { nextFunc, err := o.GetFunction(field) if err != nil { return err } nextType := nextFunc.ReturnType if nextType.AsFunctionProvider() != nil { o = fc.mod.GetFunctionProvider(nextType.Name()) continue } return fmt.Errorf("function '%s' returns non-object type %v", field, nextType.Kind) } fns := o.GetFunctions() sort.Slice(fns, func(i, j int) bool { return fns[i].Name < fns[j].Name }) for _, fn := range fns {
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/functions.go
desc := strings.SplitN(fn.Description, "\n", 2)[0] if desc == "" { desc = "-" } fmt.Fprintf(tw, "%s\t%s\n", cliName(fn.Name), desc, ) } return tw.Flush() }, } type FuncCommands []*FuncCommand func (fcs FuncCommands) AddFlagSet(flags *pflag.FlagSet) { for _, cmd := range fcs.All() { cmd.PersistentFlags().AddFlagSet(flags) } } func (fcs FuncCommands) AddParent(rootCmd *cobra.Command) { rootCmd.AddGroup(funcGroup) rootCmd.AddCommand(fcs.All()...) } func (fcs FuncCommands) All() []*cobra.Command { cmds := make([]*cobra.Command, len(fcs)) for i, fc := range fcs { cmds[i] = fc.Command() } return cmds } func setCmdOutput(cmd *cobra.Command, vtx *progrock.VertexRecorder) {
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/functions.go
if silent { return } var stdout io.Writer var stderr io.Writer if stdoutIsTTY { stdout = vtx.Stdout() } else { stdout = os.Stdout } if stderrIsTTY { stderr = vtx.Stderr() } else { stderr = os.Stderr } cmd.SetOut(stdout) cmd.SetErr(stderr) } type FuncCommand struct { Name string Aliases []string
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/functions.go
Short string Long string Example string Init func(*cobra.Command) Execute func(*FuncCommand, *cobra.Command) error BeforeParse func(*FuncCommand, *cobra.Command, *modFunction) error OnSelectObjectLeaf func(*FuncCommand, string) error
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/functions.go
BeforeRequest func(*FuncCommand, *cobra.Command, *modTypeDef) error AfterResponse func(*FuncCommand, *cobra.Command, *modTypeDef, any) error cmd *cobra.Command mod *moduleDef showHelp bool showUsage bool q *querybuilder.Selection c *client.Client } func (fc *FuncCommand) Command() *cobra.Command { if fc.cmd == nil { use := fmt.Sprintf("%s [flags] [command [flags]]...", fc.Name) disableFlagsInUse := true if fc.Execute != nil { use = fc.Name disableFlagsInUse = false } fc.cmd = &cobra.Command{ Use: use, Aliases: fc.Aliases, Short: fc.Short, Long: fc.Long, Example: fc.Example,
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/functions.go
GroupID: funcGroup.ID, Hidden: true, DisableFlagParsing: true, DisableFlagsInUseLine: disableFlagsInUse, PreRunE: func(c *cobra.Command, a []string) error { c.DisableFlagParsing = false c.Flags().SetInterspersed(false) c.SetGlobalNormalizationFunc(func(f *pflag.FlagSet, name string) pflag.NormalizedName { return pflag.NormalizedName(cliName(name)) }) c.FParseErrWhitelist.UnknownFlags = true if err := c.ParseFlags(a); err != nil {
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/functions.go
return c.FlagErrorFunc()(c, err) } c.FParseErrWhitelist.UnknownFlags = false fc.showHelp, _ = c.Flags().GetBool("help") return nil }, RunE: func(c *cobra.Command, a []string) error { return withEngineAndTUI(c.Context(), client.Params{}, func(ctx context.Context, engineClient *client.Client) (rerr error) { fc.c = engineClient c.SetContext(ctx) c.SilenceErrors = true return fc.execute(c, a) }) }, } if fc.Init != nil { fc.Init(fc.cmd) } } return fc.cmd } func (fc *FuncCommand) execute(c *cobra.Command, a []string) (rerr error) { ctx := c.Context() rec := progrock.FromContext(ctx)
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/functions.go
loader := rec.Vertex("cmd-func-loader", "load "+c.Name()) setCmdOutput(c, loader) cmd, flags, err := fc.load(c, a, loader) loader.Done(err) if err != nil { return err } vtx := rec.Vertex("cmd-func-exec", cmd.CommandPath(), progrock.Focused()) setCmdOutput(c, vtx) defer func() { if rerr != nil { cmd.PrintErrln("Error:", rerr.Error()) if fc.showUsage { cmd.PrintErrf("Run '%v --help' for usage.\n", cmd.CommandPath()) } } vtx.Done(rerr) }() if fc.showHelp { if cmd != c { cmd.Aliases = nil } return cmd.Help() }
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/functions.go
if err := cobra.NoArgs(cmd, flags); err != nil { return err } if fc.Execute != nil { return fc.Execute(fc, cmd) } if cmd == c { return cmd.Help() } err = cmd.RunE(cmd, flags) if err != nil { return err } return nil } func (fc *FuncCommand) load(c *cobra.Command, a []string, vtx *progrock.VertexRecorder) (cmd *cobra.Command, _ []string, rerr error) { ctx := c.Context() dag := fc.c.Dagger() defer func() { if cmd == nil { cmd = c } if rerr != nil { cmd.PrintErrln("Error:", rerr.Error()) if fc.showHelp {
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/functions.go
cmd.Help() } if fc.showUsage { cmd.PrintErrf("Run '%v --help' for usage.\n", cmd.CommandPath()) } } }() load := vtx.Task("loading module") modConf, err := getDefaultModuleConfiguration(ctx, dag, "") if err != nil { return nil, nil, fmt.Errorf("failed to get configured module: %w", err) } if !modConf.FullyInitialized() { return nil, nil, fmt.Errorf("module at source dir %q doesn't exist or is invalid", modConf.LocalSourcePath) } mod := modConf.Mod.Initialize() _, err = mod.Serve(ctx) load.Done(err) if err != nil { return nil, nil, err } load = vtx.Task("loading objects") modDef, err := loadModTypeDefs(ctx, dag, mod) load.Done(err) if err != nil { return nil, nil, err } obj := modDef.GetMainObject() if obj == nil {
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/functions.go
return nil, nil, fmt.Errorf("main object not found") } fc.mod = modDef if fc.Execute != nil { return nil, nil, nil } if obj.Constructor != nil { if err := fc.addArgsForFunction(c, a, obj.Constructor, dag); err != nil { return nil, nil, err } fc.selectFunc(obj.Name, obj.Constructor, c, dag) } else { fc.Select(obj.Name) } fc.addSubCommands(c, dag, obj) if fc.showHelp { return nil, nil, nil } traverse := vtx.Task("traversing arguments") cmd, flags, err := fc.traverse(c) defer func() { traverse.Done(rerr) }() if err != nil { if errors.Is(err, pflag.ErrHelp) { fc.showHelp = true return cmd, flags, nil } fc.showUsage = true
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/functions.go
return cmd, flags, err } return cmd, flags, nil } func (fc *FuncCommand) traverse(c *cobra.Command) (*cobra.Command, []string, error) { cmd, args, err := c.Find(c.Flags().Args()) if err != nil { return cmd, args, err } if cmd == c { return cmd, args, nil } cmd.SetContext(c.Context()) cmd.InitDefaultHelpFlag() err = cmd.PreRunE(cmd, args) if err != nil { return cmd, args, err } return fc.traverse(cmd) } func (fc *FuncCommand) addSubCommands(cmd *cobra.Command, dag *dagger.Client, fnProvider functionProvider) { if fnProvider != nil { for _, fn := range fnProvider.GetFunctions() { subCmd := fc.makeSubCmd(dag, fn) cmd.AddCommand(subCmd) } } }
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/functions.go
func (fc *FuncCommand) makeSubCmd(dag *dagger.Client, fn *modFunction) *cobra.Command { newCmd := &cobra.Command{ Use: cliName(fn.Name), Short: fn.Description, PreRunE: func(cmd *cobra.Command, args []string) (err error) { if err := fc.addArgsForFunction(cmd, args, fn, dag); err != nil { return err } fnProvider := fn.ReturnType.AsFunctionProvider() if fnProvider == nil && fn.ReturnType.AsList != nil { fnProvider = fn.ReturnType.AsList.ElementTypeDef.AsFunctionProvider() } fc.addSubCommands(cmd, dag, fnProvider) help, _ := cmd.Flags().GetBool("help") if help { return pflag.ErrHelp } return fc.selectFunc(fn.Name, fn, cmd, dag) }, RunE: func(cmd *cobra.Command, args []string) (err error) { switch fn.ReturnType.Kind { case dagger.ObjectKind, dagger.InterfaceKind: if fc.OnSelectObjectLeaf == nil { fc.showUsage = true return fmt.Errorf("%q requires a sub-command", cmd.Name())
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/functions.go
} err := fc.OnSelectObjectLeaf(fc, fn.ReturnType.Name()) if err != nil { fc.showUsage = true return fmt.Errorf("invalid selection for command %q: %w", cmd.Name(), err) } case dagger.ListKind: fnProvider := fn.ReturnType.AsList.ElementTypeDef.AsFunctionProvider() if fnProvider != nil && len(fnProvider.GetFunctions()) > 0 { fc.showUsage = true return fmt.Errorf("%q requires a sub-command", cmd.Name()) } } if fc.BeforeRequest != nil { if err = fc.BeforeRequest(fc, cmd, fn.ReturnType); err != nil { return err } } ctx := cmd.Context() query, _ := fc.q.Build(ctx) rec := progrock.FromContext(ctx) rec.Debug("executing", progrock.Labelf("query", "%+v", query)) var response any q := fc.q.Bind(&response) if err := q.Execute(ctx, dag.GraphQLClient()); err != nil { return fmt.Errorf("response from query: %w", err) } if fc.AfterResponse != nil {
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/functions.go
return fc.AfterResponse(fc, cmd, fn.ReturnType, response) } if fn.ReturnType.Kind != dagger.VoidKind { cmd.Println(response) } return nil }, } if fn.Name != newCmd.Name() { newCmd.Aliases = append(newCmd.Aliases, fn.Name) } newCmd.Flags().SetInterspersed(false) return newCmd } func (fc *FuncCommand) addArgsForFunction(cmd *cobra.Command, cmdArgs []string, fn *modFunction, dag *dagger.Client) error { fc.mod.LoadTypeDef(fn.ReturnType) for _, arg := range fn.Args { fc.mod.LoadTypeDef(arg.TypeDef) } for _, arg := range fn.Args { _, err := arg.AddFlag(cmd.Flags(), dag) if err != nil { return err } if !arg.TypeDef.Optional { cmd.MarkFlagRequired(arg.FlagName()) } } if fc.BeforeParse != nil {
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/functions.go
if err := fc.BeforeParse(fc, cmd, fn); err != nil { return err } } if err := cmd.ParseFlags(cmdArgs); err != nil { return cmd.FlagErrorFunc()(cmd, err) } help, _ := cmd.Flags().GetBool("help") if !help { if err := cmd.ValidateRequiredFlags(); err != nil { return err } if err := cmd.ValidateFlagGroups(); err != nil { return err } } return nil } func (fc *FuncCommand) selectFunc(selectName string, fn *modFunction, cmd *cobra.Command, dag *dagger.Client) error { fc.Select(selectName) for _, arg := range fn.Args { var val any flag := cmd.Flags().Lookup(arg.FlagName()) if flag == nil { return fmt.Errorf("no flag for %q", arg.FlagName()) } if arg.TypeDef.Optional && !flag.Changed {
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
cmd/dagger/functions.go
continue } val = flag.Value switch v := val.(type) { case DaggerValue: obj, err := v.Get(cmd.Context(), dag) if err != nil { return fmt.Errorf("failed to get value for argument %q: %w", arg.Name, err) } if obj == nil { return fmt.Errorf("no value for argument: %s", arg.Name) } val = obj case pflag.SliceValue: val = v.GetSlice() } fc.Arg(arg.Name, val) } return nil } func (fc *FuncCommand) Select(name string) { if fc.q == nil { fc.q = querybuilder.Query() } fc.q = fc.q.Select(gqlFieldName(name)) } func (fc *FuncCommand) Arg(name string, value any) { fc.q = fc.q.Arg(gqlArgName(name), value) }
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
core/integration/module_call_test.go
package core import ( "fmt" "strings" "testing" "dagger.io/dagger" "github.com/stretchr/testify/require" ) func TestModuleDaggerCallArgTypes(t *testing.T) { t.Parallel() t.Run("service args", func(t *testing.T) { t.Parallel() t.Run("used as service binding", func(t *testing.T) { t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=test", "--sdk=go")). WithNewFile("main.go", dagger.ContainerWithNewFileOpts{ Contents: `package main import ( "context" )
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
core/integration/module_call_test.go
type Test struct {} func (m *Test) Fn(ctx context.Context, svc *Service) (string, error) { return dag.Container().From("alpine:3.18").WithExec([]string{"apk", "add", "curl"}). WithServiceBinding("daserver", svc). WithExec([]string{"curl", "http://daserver:8000"}). Stdout(ctx) } `, }) logGen(ctx, t, modGen.Directory(".")) httpServer, _ := httpService(ctx, t, c, "im up") endpoint, err := httpServer.Endpoint(ctx) require.NoError(t, err) out, err := modGen. WithServiceBinding("testserver", httpServer). With(daggerCall("fn", "--svc", "tcp://"+endpoint)).Stdout(ctx) require.NoError(t, err) require.Equal(t, strings.TrimSpace(out), "im up") }) t.Run("used directly", func(t *testing.T) { t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=test", "--sdk=go")). WithNewFile("main.go", dagger.ContainerWithNewFileOpts{ Contents: `package main import ( "context"
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
core/integration/module_call_test.go
"fmt" "strings" ) type Test struct {} func (m *Test) Fn(ctx context.Context, svc *Service) (string, error) { ports, err := svc.Ports(ctx) if err != nil { return "", err } var out []string out = append(out, fmt.Sprintf("%d exposed ports:", len(ports))) for _, port := range ports { number, err := port.Port(ctx) if err != nil { return "", err } out = append(out, fmt.Sprintf("- TCP/%d", number)) } return strings.Join(out, "\n"), nil } `, }) logGen(ctx, t, modGen.Directory(".")) httpServer, _ := httpService(ctx, t, c, "im up") endpoint, err := httpServer.Endpoint(ctx) require.NoError(t, err) out, err := modGen. WithServiceBinding("testserver", httpServer). With(daggerCall("fn", "--svc", "tcp://"+endpoint)).Stdout(ctx) require.NoError(t, err)
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
core/integration/module_call_test.go
require.Equal(t, strings.TrimSpace(out), "1 exposed ports:\n- TCP/8000") }) }) t.Run("list args", func(t *testing.T) { t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=minimal", "--sdk=go")). WithNewFile("foo.txt", dagger.ContainerWithNewFileOpts{ Contents: "bar", }). WithNewFile("main.go", dagger.ContainerWithNewFileOpts{ Contents: `package main import ( "context" "strings" ) type Minimal struct {} func (m *Minimal) Hello(msgs []string) string { return strings.Join(msgs, "+") } func (m *Minimal) Reads(ctx context.Context, files []File) (string, error) { var contents []string for _, f := range files { content, err := f.Contents(ctx) if err != nil { return "", err }
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
core/integration/module_call_test.go
contents = append(contents, content) } return strings.Join(contents, "+"), nil } `, }) logGen(ctx, t, modGen.Directory(".")) out, err := modGen.With(daggerCall("hello", "--msgs", "yo", "--msgs", "my", "--msgs", "friend")).Stdout(ctx) require.NoError(t, err) require.Equal(t, strings.TrimSpace(out), "yo+my+friend") out, err = modGen.With(daggerCall("reads", "--files=foo.txt", "--files=foo.txt")).Stdout(ctx) require.NoError(t, err) require.Equal(t, strings.TrimSpace(out), "bar+bar") }) t.Run("directory arg inputs", func(t *testing.T) { t.Parallel() t.Run("local dir", func(t *testing.T) { t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=test", "--sdk=go")). WithNewFile("/dir/subdir/foo.txt", dagger.ContainerWithNewFileOpts{ Contents: "foo", }). WithNewFile("/dir/subdir/bar.txt", dagger.ContainerWithNewFileOpts{ Contents: "bar", }). WithNewFile("main.go", dagger.ContainerWithNewFileOpts{
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
core/integration/module_call_test.go
Contents: `package main type Test struct {} func (m *Test) Fn(dir *Directory) *Directory { return dir } `, }) out, err := modGen.With(daggerCall("fn", "--dir", "/dir/subdir", "entries")).Stdout(ctx) require.NoError(t, err) require.Equal(t, strings.TrimSpace(out), "bar.txt\nfoo.txt") out, err = modGen.With(daggerCall("fn", "--dir", "file:///dir/subdir", "entries")).Stdout(ctx) require.NoError(t, err) require.Equal(t, strings.TrimSpace(out), "bar.txt\nfoo.txt") }) t.Run("git dir", func(t *testing.T) { t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=test", "--sdk=go")). WithNewFile("main.go", dagger.ContainerWithNewFileOpts{ Contents: `package main type Test struct {} func (m *Test) Fn(dir *Directory, subpath Optional[string]) *Directory { return dir.Directory(subpath.GetOr(".")) } `, }) for _, tc := range []struct {
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
core/integration/module_call_test.go
baseURL string subpath string }{ { baseURL: "https://github.com/dagger/dagger", }, { baseURL: "https://github.com/dagger/dagger", subpath: ".changes", }, { baseURL: "https://github.com/dagger/dagger.git", }, { baseURL: "https://github.com/dagger/dagger.git", subpath: ".changes", },
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
core/integration/module_call_test.go
} { tc := tc t.Run(fmt.Sprintf("%s:%s", tc.baseURL, tc.subpath), func(t *testing.T) { url := tc.baseURL + "#v0.9.1" if tc.subpath != "" { url += ":" + tc.subpath } args := []string{"fn", "--dir", url} if tc.subpath == "" { args = append(args, "--subpath", ".changes") } args = append(args, "entries") out, err := modGen.With(daggerCall(args...)).Stdout(ctx) require.NoError(t, err) require.Contains(t, out, "v0.9.1.md") require.NotContains(t, out, "v0.9.2.md") }) } }) }) t.Run("secret args", func(t *testing.T) { t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=test", "--sdk=go")). WithNewFile("main.go", dagger.ContainerWithNewFileOpts{ Contents: `package main import "context"
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
core/integration/module_call_test.go
type Test struct {} func (m *Test) Insecure(ctx context.Context, token *Secret) (string, error) { return token.Plaintext(ctx) } `, }). WithEnvVariable("TOPSECRET", "shhh"). WithNewFile("/mysupersecret", dagger.ContainerWithNewFileOpts{Contents: "file shhh"}) t.Run("explicit env", func(t *testing.T) { t.Run("happy", func(t *testing.T) { out, err := modGen.With(daggerCall("insecure", "--token", "env:TOPSECRET")).Stdout(ctx) require.NoError(t, err) require.Equal(t, "shhh", strings.TrimSpace(out)) }) t.Run("sad", func(t *testing.T) { _, err := modGen.With(daggerCall("insecure", "--token", "env:NOWHERETOBEFOUND")).Stdout(ctx) require.ErrorContains(t, err, `secret env var not found: "NOW..."`) }) }) t.Run("implicit env", func(t *testing.T) { t.Parallel() t.Run("happy", func(t *testing.T) { out, err := modGen.With(daggerCall("insecure", "--token", "TOPSECRET")).Stdout(ctx) require.NoError(t, err) require.Equal(t, "shhh", strings.TrimSpace(out)) }) t.Run("sad", func(t *testing.T) { _, err := modGen.With(daggerCall("insecure", "--token", "NOWHERETOBEFOUND")).Stdout(ctx) require.ErrorContains(t, err, `secret env var not found: "NOW..."`) })
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
core/integration/module_call_test.go
}) t.Run("file", func(t *testing.T) { t.Run("happy", func(t *testing.T) { out, err := modGen.With(daggerCall("insecure", "--token", "file:/mysupersecret")).Stdout(ctx) require.NoError(t, err) require.Equal(t, "file shhh", strings.TrimSpace(out)) }) t.Run("sad", func(t *testing.T) { _, err := modGen.With(daggerCall("insecure", "--token", "file:/nowheretobefound")).Stdout(ctx) require.ErrorContains(t, err, `failed to read secret file "/nowheretobefound": open /nowheretobefound: no such file or directory`) }) }) t.Run("cmd", func(t *testing.T) { t.Run("happy", func(t *testing.T) { out, err := modGen.With(daggerCall("insecure", "--token", "cmd:echo -n cmd shhh")).Stdout(ctx) require.NoError(t, err) require.Equal(t, "cmd shhh", strings.TrimSpace(out)) }) t.Run("sad", func(t *testing.T) { _, err := modGen.With(daggerCall("insecure", "--token", "cmd:exit 1")).Stdout(ctx) require.ErrorContains(t, err, `failed to run secret command "exit 1": exit status 1`) }) }) t.Run("invalid source", func(t *testing.T) { _, err := modGen.With(daggerCall("insecure", "--token", "wtf:HUH")).Stdout(ctx) require.ErrorContains(t, err, `unsupported secret arg source: "wtf"`) }) }) } func TestModuleDaggerCallReturnTypes(t *testing.T) {
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
core/integration/module_call_test.go
t.Parallel() t.Run("return list objects", func(t *testing.T) { t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=minimal", "--sdk=go")). WithNewFile("main.go", dagger.ContainerWithNewFileOpts{ Contents: `package main type Minimal struct {} type Foo struct { Bar int ` + "`" + `json:"bar"` + "`" + ` } func (m *Minimal) Fn() []*Foo {
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
core/integration/module_call_test.go
var foos []*Foo for i := 0; i < 3; i++ { foos = append(foos, &Foo{Bar: i}) } return foos } `, }) logGen(ctx, t, modGen.Directory(".")) expected := "0\n1\n2" t.Run("print", func(t *testing.T) { out, err := modGen.With(daggerCall("fn", "bar")).Stdout(ctx) require.NoError(t, err) require.Equal(t, expected, strings.TrimSpace(out)) }) t.Run("output", func(t *testing.T) { out, err := modGen. With(daggerCall("fn", "bar", "-o", "./outfile")). File("./outfile"). Contents(ctx) require.NoError(t, err) require.Equal(t, expected, strings.TrimSpace(out)) }) t.Run("json", func(t *testing.T) { out, err := modGen. With(daggerCall("fn", "bar", "--json")). Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `[{"bar": 0}, {"bar": 1}, {"bar": 2}]`, out) })
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
core/integration/module_call_test.go
}) t.Run("return container", func(t *testing.T) { t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=test", "--sdk=go")). WithNewFile("main.go", dagger.ContainerWithNewFileOpts{ Contents: `package main func New() *Test { return &Test{Ctr: dag.Container().From("alpine:3.18").WithExec([]string{"echo", "hello", "world"})} } type Test struct { Ctr *Container } `, }) logGen(ctx, t, modGen.Directory(".")) t.Run("default", func(t *testing.T) { ctr := modGen.With(daggerCall("ctr")) out, err := ctr.Stdout(ctx) require.NoError(t, err) require.Empty(t, out) out, err = ctr.Stderr(ctx) require.NoError(t, err) require.Contains(t, out, "Container evaluated") }) t.Run("output", func(t *testing.T) { modGen, err := modGen.With(daggerCall("ctr", "-o", "./container.tar")).Sync(ctx)
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
core/integration/module_call_test.go
require.NoError(t, err) size, err := modGen.File("./container.tar").Size(ctx) require.NoError(t, err) require.Greater(t, size, 0) _, err = modGen.WithExec([]string{"tar", "tf", "./container.tar", "oci-layout"}).Sync(ctx) require.NoError(t, err) }) }) t.Run("return directory", func(t *testing.T) { t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=test", "--sdk=go")). WithNewFile("main.go", dagger.ContainerWithNewFileOpts{ Contents: `package main func New() *Test { return &Test{ Dir: dag.Directory().WithNewFile("foo.txt", "foo").WithNewFile("bar.txt", "bar"), } } type Test struct { Dir *Directory } `, }) logGen(ctx, t, modGen.Directory(".")) t.Run("default", func(t *testing.T) { ctr := modGen.With(daggerCall("dir"))
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
core/integration/module_call_test.go
out, err := ctr.Stdout(ctx) require.NoError(t, err) require.Empty(t, out) out, err = ctr.Stderr(ctx) require.NoError(t, err) require.Contains(t, out, "Directory evaluated") }) t.Run("output", func(t *testing.T) { modGen, err := modGen.With(daggerCall("dir", "-o", "./outdir")).Sync(ctx) require.NoError(t, err) entries, err := modGen.Directory("./outdir").Entries(ctx) require.NoError(t, err) require.Equal(t, "bar.txt\nfoo.txt", strings.Join(entries, "\n")) foo, err := modGen.Directory("./outdir").File("foo.txt").Contents(ctx) require.NoError(t, err) require.Equal(t, "foo", strings.TrimSpace(foo)) bar, err := modGen.Directory("./outdir").File("bar.txt").Contents(ctx) require.NoError(t, err) require.Equal(t, "bar", strings.TrimSpace(bar)) }) }) t.Run("return file", func(t *testing.T) { t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=test", "--sdk=go")). WithNewFile("main.go", dagger.ContainerWithNewFileOpts{ Contents: `package main
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
core/integration/module_call_test.go
func New() *Test { return &Test{ File: dag.Directory().WithNewFile("foo.txt", "foo").File("foo.txt"), } } type Test struct { File *File } `, }) logGen(ctx, t, modGen.Directory(".")) t.Run("default", func(t *testing.T) { ctr := modGen.With(daggerCall("file")) out, err := ctr.Stdout(ctx) require.NoError(t, err) require.Empty(t, out) out, err = ctr.Stderr(ctx) require.NoError(t, err) require.Contains(t, out, "File evaluated") }) t.Run("output", func(t *testing.T) { out, err := modGen. With(daggerCall("file", "-o", "./outfile")). File("./outfile"). Contents(ctx) require.NoError(t, err) require.Equal(t, "foo", strings.TrimSpace(out)) }) }) t.Run("sync", func(t *testing.T) {
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
core/integration/module_call_test.go
t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=test", "--sdk=go")). WithNewFile("main.go", dagger.ContainerWithNewFileOpts{ Contents: `package main func New() *Test { return &Test{Ctr: dag.Container().From("alpine:3.18").WithExec([]string{"echo", "hello", "world"})} } type Test struct { Ctr *Container } `, }) _, err := modGen.With(daggerCall("ctr", "sync")).Stdout(ctx) require.NoError(t, err) }) } func TestModuleDaggerCallCoreChaining(t *testing.T) { t.Parallel() t.Run("container", func(t *testing.T) { t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work").
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
core/integration/module_call_test.go
With(daggerExec("mod", "init", "--name=test", "--sdk=go")). WithNewFile("main.go", dagger.ContainerWithNewFileOpts{ Contents: `package main func New() *Test { return &Test{Ctr: dag.Container().From("alpine:3.18.5")} } type Test struct { Ctr *Container } `, }) t.Run("file", func(t *testing.T) { out, err := modGen.With(daggerCall("ctr", "file", "--path=/etc/alpine-release", "contents")).Stdout(ctx) require.NoError(t, err) require.Equal(t, "3.18.5", strings.TrimSpace(out)) }) t.Run("export", func(t *testing.T) { modGen, err := modGen.With(daggerCall("ctr", "export", "--path=./container.tar.gz")).Sync(ctx) require.NoError(t, err) size, err := modGen.File("./container.tar.gz").Size(ctx) require.NoError(t, err) require.Greater(t, size, 0) }) }) t.Run("directory", func(t *testing.T) { t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work").
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
core/integration/module_call_test.go
With(daggerExec("mod", "init", "--name=test", "--sdk=go")). WithNewFile("main.go", dagger.ContainerWithNewFileOpts{ Contents: `package main func New() *Test { return &Test{ Dir: dag.Directory().WithNewFile("foo.txt", "foo").WithNewFile("bar.txt", "bar"), } } type Test struct { Dir *Directory } `, }) t.Run("file", func(t *testing.T) { out, err := modGen.With(daggerCall("dir", "file", "--path=foo.txt", "contents")).Stdout(ctx) require.NoError(t, err) require.Equal(t, "foo", strings.TrimSpace(out)) }) t.Run("export", func(t *testing.T) { modGen, err := modGen.With(daggerCall("dir", "export", "--path=./outdir")).Sync(ctx) require.NoError(t, err) ents, err := modGen.Directory("./outdir").Entries(ctx) require.NoError(t, err) require.Equal(t, []string{"bar.txt", "foo.txt"}, ents) }) }) t.Run("return file", func(t *testing.T) { t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage).
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
core/integration/module_call_test.go
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=test", "--sdk=go")). WithNewFile("main.go", dagger.ContainerWithNewFileOpts{ Contents: `package main func New() *Test { return &Test{ File: dag.Directory().WithNewFile("foo.txt", "foo").File("foo.txt"), } } type Test struct { File *File } `, }) t.Run("size", func(t *testing.T) { out, err := modGen.With(daggerCall("file", "size")).Stdout(ctx) require.NoError(t, err) require.Equal(t, "3", strings.TrimSpace(out)) }) t.Run("export", func(t *testing.T) { modGen, err := modGen.With(daggerCall("file", "export", "--path=./outfile")).Sync(ctx) require.NoError(t, err) contents, err := modGen.File("./outfile").Contents(ctx) require.NoError(t, err) require.Equal(t, "foo", strings.TrimSpace(contents)) }) }) } func TestModuleDaggerCallSaveOutput(t *testing.T) {
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
core/integration/module_call_test.go
t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=test", "--sdk=go")). WithNewFile("main.go", dagger.ContainerWithNewFileOpts{ Contents: `package main type Test struct { } func (t *Test) Hello() string { return "hello" } func (t *Test) File() *File { return dag.Directory().WithNewFile("foo.txt", "foo").File("foo.txt") } `, }) logGen(ctx, t, modGen.Directory(".")) t.Run("truncate file", func(t *testing.T) { out, err := modGen. WithNewFile("foo.txt", dagger.ContainerWithNewFileOpts{ Contents: "foobar", }). With(daggerCall("hello", "-o", "foo.txt")). File("foo.txt"). Contents(ctx) require.NoError(t, err)
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
core/integration/module_call_test.go
require.Equal(t, "hello", strings.TrimSpace(out)) }) t.Run("not a file", func(t *testing.T) { _, err := modGen.With(daggerCall("hello", "-o", ".")).Sync(ctx) require.ErrorContains(t, err, "is a directory") }) t.Run("allow dir for file", func(t *testing.T) { out, err := modGen. With(daggerCall("file", "-o", ".")). File("foo.txt"). Contents(ctx) require.NoError(t, err) require.Equal(t, "foo", strings.TrimSpace(out)) }) t.Run("create parent dirs", func(t *testing.T) { ctr, err := modGen.With(daggerCall("hello", "-o", "foo/bar.txt")).Sync(ctx) require.NoError(t, err) t.Run("print success", func(t *testing.T) { out, err := ctr.Stderr(ctx) require.NoError(t, err) require.Contains(t, out, `Saved output to "/work/foo/bar.txt"`) }) t.Run("check directory permissions", func(t *testing.T) { out, err := ctr.WithExec([]string{"stat", "-c", "%a", "foo"}).Stdout(ctx) require.NoError(t, err) require.Equal(t, "755", strings.TrimSpace(out)) }) t.Run("check file permissions", func(t *testing.T) { out, err := ctr.WithExec([]string{"stat", "-c", "%a", "foo/bar.txt"}).Stdout(ctx)
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
core/integration/module_call_test.go
require.NoError(t, err) require.Equal(t, "644", strings.TrimSpace(out)) }) }) t.Run("check umask", func(t *testing.T) { ctr, err := modGen. WithNewFile("/entrypoint.sh", dagger.ContainerWithNewFileOpts{ Contents: `#!/bin/sh umask 027 exec "$@" `, Permissions: 0o750, }). WithEntrypoint([]string{"/entrypoint.sh"}). With(daggerCall("hello", "-o", "/tmp/foo/bar.txt")). Sync(ctx) require.NoError(t, err) t.Run("directory", func(t *testing.T) { out, err := ctr.WithExec([]string{"stat", "-c", "%a", "/tmp/foo"}).Stdout(ctx) require.NoError(t, err) require.Equal(t, "750", strings.TrimSpace(out)) }) t.Run("file", func(t *testing.T) { out, err := ctr.WithExec([]string{"stat", "-c", "%a", "/tmp/foo/bar.txt"}).Stdout(ctx) require.NoError(t, err) require.Equal(t, "640", strings.TrimSpace(out)) }) }) } func TestModuleCallByName(t *testing.T) {
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
core/integration/module_call_test.go
t.Parallel() c, ctx := connect(t) ctr := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work/mod-a"). With(daggerExec("mod", "init", "--name=mod-a", "--sdk=go")). WithNewFile("/work/mod-a/main.go", dagger.ContainerWithNewFileOpts{ Contents: `package main
closed
dagger/dagger
https://github.com/dagger/dagger
6,409
✨ Allow cache volumes as CLI parameters
### What are you trying to do? I have a module with the following constructor: ```go func New( // ... // Disable mounting cache volumes. disableCache Optional[bool], // Module cache volume to mount at /go/pkg/mod. modCache Optional[*CacheVolume], // Build cache volume to mount at ~/.cache/go-build. buildCache Optional[*CacheVolume], ) *Go { // ... } ``` Currently, running this module in the CLI fails due to CacheVolume being an unsupported CLI argument: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --help ✘ load call ERROR [1.21s] β”œ [0.56s] loading module β”œ [0.65s] loading objects ┃ Error: unsupported object type "CacheVolume" for flag: mod-cache ``` Given cache volumes are created by their names (and that other types of objects, like files, are also referenced simply by their path or ID), I think it would be useful to do the same for cache volumes. In this instance: ```shell ❯ dagger call -m "github.com/sagikazarmark/daggerverse/go@main" --mod-cache go-build ``` An alternative I can imagine is adding a pragma comment for ignoring certain arguments from the CLI, but including them in the generated code. That's a temporary measure, but would still be easier for module developers, so they can utilize constructors instead of falling back to method chaining for tasks like setting cache. ### Why is this important to you? _No response_ ### How are you currently working around this? I will probably remove those arguments from the constructor for now. I might add them to the module API, but honestly, I'd rather not.
https://github.com/dagger/dagger/issues/6409
https://github.com/dagger/dagger/pull/6520
0b91d2a3e04c81ad0dad799d34af30d3801ae76f
7350f0b8dd5ff74b7ae0ddfd05e35c37bf16712b
2024-01-12T07:04:04Z
go
2024-01-31T15:53:55Z
core/integration/module_call_test.go
import "context" type ModA struct {} func (m *ModA) Fn(ctx context.Context) string { return "hi from mod-a" } `, }). WithWorkdir("/work/mod-b"). With(daggerExec("mod", "init", "--name=mod-b", "--sdk=go")). WithNewFile("/work/mod-b/main.go", dagger.ContainerWithNewFileOpts{ Contents: `package main import "context" type ModB struct {} func (m *ModB) Fn(ctx context.Context) string { return "hi from mod-b" } `, }). WithWorkdir("/work"). With(daggerExec("mod", "init")). With(daggerExec("mod", "install", "--name", "foo", "./mod-a")). With(daggerExec("mod", "install", "--name", "bar", "./mod-b")) out, err := ctr.With(daggerCallAt("foo", "fn")).Stdout(ctx) require.NoError(t, err) require.Equal(t, "hi from mod-a", strings.TrimSpace(out)) out, err = ctr.With(daggerCallAt("bar", "fn")).Stdout(ctx) require.NoError(t, err) require.Equal(t, "hi from mod-b", strings.TrimSpace(out)) }
closed
dagger/dagger
https://github.com/dagger/dagger
6,312
Modules: `dag.Host()` name is extremely confusing
When module code uses `dag.Host()`, the "host" it refers to is the module container's "host", not the CLI caller's host. While this is technically consistent, it's very non-obvious at first glance and a constant source of confusion. I think at a minimum we need to change `Host` to something with a more obvious name. TBD if this change also impacts non-module SDKs or if it's somehow scoped just to the codegen for modules. There's certainly larger scope changes to the API that could also be worth discussing, but changing to a more clear name seems like the bare-minimum baseline thing to do here. --- As a side-note, support for Module code being able to read files/env vars/etc. from the *CLI caller's host* is a separate topic, discussed in this other issue https://github.com/dagger/dagger/issues/6112
https://github.com/dagger/dagger/issues/6312
https://github.com/dagger/dagger/pull/6535
c241d901a48f699a1d62f0daad882c88730e1fba
7a63c3d019530d1f08b2f72cc28e753d99b5896d
2023-12-21T19:46:28Z
go
2024-02-01T14:23:42Z
cmd/codegen/introspection/introspection.go
package introspection import ( _ "embed" ) var Query string type Response struct { Schema *Schema `json:"__schema"` } type Schema struct {
closed
dagger/dagger
https://github.com/dagger/dagger
6,312
Modules: `dag.Host()` name is extremely confusing
When module code uses `dag.Host()`, the "host" it refers to is the module container's "host", not the CLI caller's host. While this is technically consistent, it's very non-obvious at first glance and a constant source of confusion. I think at a minimum we need to change `Host` to something with a more obvious name. TBD if this change also impacts non-module SDKs or if it's somehow scoped just to the codegen for modules. There's certainly larger scope changes to the API that could also be worth discussing, but changing to a more clear name seems like the bare-minimum baseline thing to do here. --- As a side-note, support for Module code being able to read files/env vars/etc. from the *CLI caller's host* is a separate topic, discussed in this other issue https://github.com/dagger/dagger/issues/6112
https://github.com/dagger/dagger/issues/6312
https://github.com/dagger/dagger/pull/6535
c241d901a48f699a1d62f0daad882c88730e1fba
7a63c3d019530d1f08b2f72cc28e753d99b5896d
2023-12-21T19:46:28Z
go
2024-02-01T14:23:42Z
cmd/codegen/introspection/introspection.go
QueryType struct { Name string `json:"name"` } `json:"queryType"` MutationType struct { Name string `json:"name"` } `json:"mutationType"` SubscriptionType struct { Name string `json:"name"` } `json:"subscriptionType"` Types Types `json:"types"` } func (s *Schema) Query() *Type { return s.Types.Get(s.QueryType.Name) } func (s *Schema) Mutation() *Type { return s.Types.Get(s.MutationType.Name) } func (s *Schema) Subscription() *Type { return s.Types.Get(s.SubscriptionType.Name) } func (s *Schema) Visit() []*Type { v := Visitor{schema: s} return v.Run() } type TypeKind string const ( TypeKindScalar = TypeKind("SCALAR") TypeKindObject = TypeKind("OBJECT") TypeKindInterface = TypeKind("INTERFACE") TypeKindUnion = TypeKind("UNION")
closed
dagger/dagger
https://github.com/dagger/dagger
6,312
Modules: `dag.Host()` name is extremely confusing
When module code uses `dag.Host()`, the "host" it refers to is the module container's "host", not the CLI caller's host. While this is technically consistent, it's very non-obvious at first glance and a constant source of confusion. I think at a minimum we need to change `Host` to something with a more obvious name. TBD if this change also impacts non-module SDKs or if it's somehow scoped just to the codegen for modules. There's certainly larger scope changes to the API that could also be worth discussing, but changing to a more clear name seems like the bare-minimum baseline thing to do here. --- As a side-note, support for Module code being able to read files/env vars/etc. from the *CLI caller's host* is a separate topic, discussed in this other issue https://github.com/dagger/dagger/issues/6112
https://github.com/dagger/dagger/issues/6312
https://github.com/dagger/dagger/pull/6535
c241d901a48f699a1d62f0daad882c88730e1fba
7a63c3d019530d1f08b2f72cc28e753d99b5896d
2023-12-21T19:46:28Z
go
2024-02-01T14:23:42Z
cmd/codegen/introspection/introspection.go
TypeKindEnum = TypeKind("ENUM") TypeKindInputObject = TypeKind("INPUT_OBJECT") TypeKindList = TypeKind("LIST") TypeKindNonNull = TypeKind("NON_NULL") ) type Scalar string const ( ScalarInt = Scalar("Int") ScalarFloat = Scalar("Float") ScalarString = Scalar("String") ScalarBoolean = Scalar("Boolean") ) type Type struct { Kind TypeKind `json:"kind"` Name string `json:"name"` Description string `json:"description,omitempty"` Fields []*Field `json:"fields,omitempty"` InputFields []InputValue `json:"inputFields,omitempty"` EnumValues []EnumValue `json:"enumValues,omitempty"` } type Types []*Type func (t Types) Get(name string) *Type { for _, i := range t { if i.Name == name { return i } } return nil } type Field struct {
closed
dagger/dagger
https://github.com/dagger/dagger
6,312
Modules: `dag.Host()` name is extremely confusing
When module code uses `dag.Host()`, the "host" it refers to is the module container's "host", not the CLI caller's host. While this is technically consistent, it's very non-obvious at first glance and a constant source of confusion. I think at a minimum we need to change `Host` to something with a more obvious name. TBD if this change also impacts non-module SDKs or if it's somehow scoped just to the codegen for modules. There's certainly larger scope changes to the API that could also be worth discussing, but changing to a more clear name seems like the bare-minimum baseline thing to do here. --- As a side-note, support for Module code being able to read files/env vars/etc. from the *CLI caller's host* is a separate topic, discussed in this other issue https://github.com/dagger/dagger/issues/6112
https://github.com/dagger/dagger/issues/6312
https://github.com/dagger/dagger/pull/6535
c241d901a48f699a1d62f0daad882c88730e1fba
7a63c3d019530d1f08b2f72cc28e753d99b5896d
2023-12-21T19:46:28Z
go
2024-02-01T14:23:42Z
cmd/codegen/introspection/introspection.go
Name string `json:"name"` Description string `json:"description"` TypeRef *TypeRef `json:"type"` Args InputValues `json:"args"` IsDeprecated bool `json:"isDeprecated"` DeprecationReason string `json:"deprecationReason"` ParentObject *Type `json:"-"` } type TypeRef struct { Kind TypeKind `json:"kind"` Name string `json:"name,omitempty"` OfType *TypeRef `json:"ofType,omitempty"` } func (r TypeRef) IsOptional() bool { return r.Kind != TypeKindNonNull } func (r TypeRef) IsScalar() bool { ref := r if r.Kind == TypeKindNonNull { ref = *ref.OfType } if ref.Kind == TypeKindScalar { return true } if ref.Kind == TypeKindEnum { return true } return false }
closed
dagger/dagger
https://github.com/dagger/dagger
6,312
Modules: `dag.Host()` name is extremely confusing
When module code uses `dag.Host()`, the "host" it refers to is the module container's "host", not the CLI caller's host. While this is technically consistent, it's very non-obvious at first glance and a constant source of confusion. I think at a minimum we need to change `Host` to something with a more obvious name. TBD if this change also impacts non-module SDKs or if it's somehow scoped just to the codegen for modules. There's certainly larger scope changes to the API that could also be worth discussing, but changing to a more clear name seems like the bare-minimum baseline thing to do here. --- As a side-note, support for Module code being able to read files/env vars/etc. from the *CLI caller's host* is a separate topic, discussed in this other issue https://github.com/dagger/dagger/issues/6112
https://github.com/dagger/dagger/issues/6312
https://github.com/dagger/dagger/pull/6535
c241d901a48f699a1d62f0daad882c88730e1fba
7a63c3d019530d1f08b2f72cc28e753d99b5896d
2023-12-21T19:46:28Z
go
2024-02-01T14:23:42Z
cmd/codegen/introspection/introspection.go
func (r TypeRef) IsObject() bool { ref := r if r.Kind == TypeKindNonNull { ref = *ref.OfType } if ref.Kind == TypeKindObject { return true } return false } func (r TypeRef) IsList() bool { ref := r if r.Kind == TypeKindNonNull { ref = *ref.OfType } if ref.Kind == TypeKindList { return true } return false } type InputValues []InputValue func (i InputValues) HasOptionals() bool { for _, v := range i { if v.TypeRef.IsOptional() { return true } } return false } type InputValue struct {
closed
dagger/dagger
https://github.com/dagger/dagger
6,312
Modules: `dag.Host()` name is extremely confusing
When module code uses `dag.Host()`, the "host" it refers to is the module container's "host", not the CLI caller's host. While this is technically consistent, it's very non-obvious at first glance and a constant source of confusion. I think at a minimum we need to change `Host` to something with a more obvious name. TBD if this change also impacts non-module SDKs or if it's somehow scoped just to the codegen for modules. There's certainly larger scope changes to the API that could also be worth discussing, but changing to a more clear name seems like the bare-minimum baseline thing to do here. --- As a side-note, support for Module code being able to read files/env vars/etc. from the *CLI caller's host* is a separate topic, discussed in this other issue https://github.com/dagger/dagger/issues/6112
https://github.com/dagger/dagger/issues/6312
https://github.com/dagger/dagger/pull/6535
c241d901a48f699a1d62f0daad882c88730e1fba
7a63c3d019530d1f08b2f72cc28e753d99b5896d
2023-12-21T19:46:28Z
go
2024-02-01T14:23:42Z
cmd/codegen/introspection/introspection.go
Name string `json:"name"` Description string `json:"description"` DefaultValue *string `json:"defaultValue"` TypeRef *TypeRef `json:"type"` } type EnumValue struct { Name string `json:"name"` Description string `json:"description"` IsDeprecated bool `json:"isDeprecated"` DeprecationReason string `json:"deprecationReason"` }
closed
dagger/dagger
https://github.com/dagger/dagger
6,312
Modules: `dag.Host()` name is extremely confusing
When module code uses `dag.Host()`, the "host" it refers to is the module container's "host", not the CLI caller's host. While this is technically consistent, it's very non-obvious at first glance and a constant source of confusion. I think at a minimum we need to change `Host` to something with a more obvious name. TBD if this change also impacts non-module SDKs or if it's somehow scoped just to the codegen for modules. There's certainly larger scope changes to the API that could also be worth discussing, but changing to a more clear name seems like the bare-minimum baseline thing to do here. --- As a side-note, support for Module code being able to read files/env vars/etc. from the *CLI caller's host* is a separate topic, discussed in this other issue https://github.com/dagger/dagger/issues/6112
https://github.com/dagger/dagger/issues/6312
https://github.com/dagger/dagger/pull/6535
c241d901a48f699a1d62f0daad882c88730e1fba
7a63c3d019530d1f08b2f72cc28e753d99b5896d
2023-12-21T19:46:28Z
go
2024-02-01T14:23:42Z
core/integration/module_test.go
package core import ( "context" _ "embed" "encoding/json" "fmt" "go/format" "os" "os/exec" "path/filepath" "strings" "testing" "time" "github.com/dagger/dagger/core/modules" "github.com/dagger/dagger/dagql/idproto" "github.com/iancoleman/strcase" "github.com/moby/buildkit/identity" "github.com/stretchr/testify/require" "github.com/tidwall/gjson" "golang.org/x/sync/errgroup" "dagger.io/dagger" "github.com/dagger/dagger/cmd/codegen/introspection" ) func TestModuleGoInit(t *testing.T) { t.Parallel() t.Run("from scratch", func(t *testing.T) { t.Parallel() c, ctx := connect(t)
closed
dagger/dagger
https://github.com/dagger/dagger
6,312
Modules: `dag.Host()` name is extremely confusing
When module code uses `dag.Host()`, the "host" it refers to is the module container's "host", not the CLI caller's host. While this is technically consistent, it's very non-obvious at first glance and a constant source of confusion. I think at a minimum we need to change `Host` to something with a more obvious name. TBD if this change also impacts non-module SDKs or if it's somehow scoped just to the codegen for modules. There's certainly larger scope changes to the API that could also be worth discussing, but changing to a more clear name seems like the bare-minimum baseline thing to do here. --- As a side-note, support for Module code being able to read files/env vars/etc. from the *CLI caller's host* is a separate topic, discussed in this other issue https://github.com/dagger/dagger/issues/6112
https://github.com/dagger/dagger/issues/6312
https://github.com/dagger/dagger/pull/6535
c241d901a48f699a1d62f0daad882c88730e1fba
7a63c3d019530d1f08b2f72cc28e753d99b5896d
2023-12-21T19:46:28Z
go
2024-02-01T14:23:42Z
core/integration/module_test.go
modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=bare", "--sdk=go")) logGen(ctx, t, modGen.Directory(".")) out, err := modGen. With(daggerQuery(`{bare{containerEcho(stringArg:"hello"){stdout}}}`)). Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"bare":{"containerEcho":{"stdout":"hello\n"}}}`, out) }) t.Run("reserved go.mod name", func(t *testing.T) { t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=go", "--sdk=go")) logGen(ctx, t, modGen.Directory(".")) out, err := modGen. With(daggerQuery(`{go{containerEcho(stringArg:"hello"){stdout}}}`)). Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"go":{"containerEcho":{"stdout":"hello\n"}}}`, out) }) t.Run("uses expected Go module name, camel-cases Dagger module name", func(t *testing.T) { t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
closed
dagger/dagger
https://github.com/dagger/dagger
6,312
Modules: `dag.Host()` name is extremely confusing
When module code uses `dag.Host()`, the "host" it refers to is the module container's "host", not the CLI caller's host. While this is technically consistent, it's very non-obvious at first glance and a constant source of confusion. I think at a minimum we need to change `Host` to something with a more obvious name. TBD if this change also impacts non-module SDKs or if it's somehow scoped just to the codegen for modules. There's certainly larger scope changes to the API that could also be worth discussing, but changing to a more clear name seems like the bare-minimum baseline thing to do here. --- As a side-note, support for Module code being able to read files/env vars/etc. from the *CLI caller's host* is a separate topic, discussed in this other issue https://github.com/dagger/dagger/issues/6112
https://github.com/dagger/dagger/issues/6312
https://github.com/dagger/dagger/pull/6535
c241d901a48f699a1d62f0daad882c88730e1fba
7a63c3d019530d1f08b2f72cc28e753d99b5896d
2023-12-21T19:46:28Z
go
2024-02-01T14:23:42Z
core/integration/module_test.go
WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=My-Module", "--sdk=go")) logGen(ctx, t, modGen.Directory(".")) out, err := modGen. With(daggerQuery(`{myModule{containerEcho(stringArg:"hello"){stdout}}}`)). Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"myModule":{"containerEcho":{"stdout":"hello\n"}}}`, out) generated, err := modGen.File("go.mod").Contents(ctx) require.NoError(t, err) require.Contains(t, generated, "module main") }) t.Run("creates go.mod beneath an existing go.mod if root points beneath it", func(t *testing.T) { t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). WithNewFile("/work/go.mod", dagger.ContainerWithNewFileOpts{ Contents: "module example.com/test\n", }). WithNewFile("/work/foo.go", dagger.ContainerWithNewFileOpts{ Contents: "package foo\n", }). WithWorkdir("/work/ci"). With(daggerExec("mod", "init", "--name=beneathGoMod", "--sdk=go")) logGen(ctx, t, modGen.Directory(".")) out, err := modGen. With(daggerQuery(`{beneathGoMod{containerEcho(stringArg:"hello"){stdout}}}`)). Stdout(ctx)
closed
dagger/dagger
https://github.com/dagger/dagger
6,312
Modules: `dag.Host()` name is extremely confusing
When module code uses `dag.Host()`, the "host" it refers to is the module container's "host", not the CLI caller's host. While this is technically consistent, it's very non-obvious at first glance and a constant source of confusion. I think at a minimum we need to change `Host` to something with a more obvious name. TBD if this change also impacts non-module SDKs or if it's somehow scoped just to the codegen for modules. There's certainly larger scope changes to the API that could also be worth discussing, but changing to a more clear name seems like the bare-minimum baseline thing to do here. --- As a side-note, support for Module code being able to read files/env vars/etc. from the *CLI caller's host* is a separate topic, discussed in this other issue https://github.com/dagger/dagger/issues/6112
https://github.com/dagger/dagger/issues/6312
https://github.com/dagger/dagger/pull/6535
c241d901a48f699a1d62f0daad882c88730e1fba
7a63c3d019530d1f08b2f72cc28e753d99b5896d
2023-12-21T19:46:28Z
go
2024-02-01T14:23:42Z
core/integration/module_test.go
require.NoError(t, err) require.JSONEq(t, `{"beneathGoMod":{"containerEcho":{"stdout":"hello\n"}}}`, out) t.Run("names Go module after Dagger module", func(t *testing.T) { generated, err := modGen.File("go.mod").Contents(ctx) require.NoError(t, err) require.Contains(t, generated, "module main") }) }) t.Run("respects existing go.mod", func(t *testing.T) { t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). WithExec([]string{"go", "mod", "init", "example.com/test"}). With(daggerExec("mod", "init", "--name=hasGoMod", "--sdk=go")) logGen(ctx, t, modGen.Directory(".")) out, err := modGen. With(daggerQuery(`{hasGoMod{containerEcho(stringArg:"hello"){stdout}}}`)). Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"hasGoMod":{"containerEcho":{"stdout":"hello\n"}}}`, out) t.Run("preserves module name", func(t *testing.T) { generated, err := modGen.File("go.mod").Contents(ctx) require.NoError(t, err) require.Contains(t, generated, "module example.com/test") }) }) t.Run("respects parent go.mod if root points to it", func(t *testing.T) { t.Parallel()
closed
dagger/dagger
https://github.com/dagger/dagger
6,312
Modules: `dag.Host()` name is extremely confusing
When module code uses `dag.Host()`, the "host" it refers to is the module container's "host", not the CLI caller's host. While this is technically consistent, it's very non-obvious at first glance and a constant source of confusion. I think at a minimum we need to change `Host` to something with a more obvious name. TBD if this change also impacts non-module SDKs or if it's somehow scoped just to the codegen for modules. There's certainly larger scope changes to the API that could also be worth discussing, but changing to a more clear name seems like the bare-minimum baseline thing to do here. --- As a side-note, support for Module code being able to read files/env vars/etc. from the *CLI caller's host* is a separate topic, discussed in this other issue https://github.com/dagger/dagger/issues/6112
https://github.com/dagger/dagger/issues/6312
https://github.com/dagger/dagger/pull/6535
c241d901a48f699a1d62f0daad882c88730e1fba
7a63c3d019530d1f08b2f72cc28e753d99b5896d
2023-12-21T19:46:28Z
go
2024-02-01T14:23:42Z
core/integration/module_test.go
c, ctx := connect(t) generated := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). WithExec([]string{"go", "mod", "init", "example.com/test"}). WithNewFile("/work/foo.go", dagger.ContainerWithNewFileOpts{ Contents: "package foo\n", }). With(daggerExec("mod", "init", "-m=./child", "--name=child", "--sdk=go")). WithWorkdir("/work/child"). With(daggerExec("mod", "sync")). Directory("/work") parentEntries, err := generated.Entries(ctx) require.NoError(t, err) require.Equal(t, []string{"child", "dagger.json", "foo.go", "go.mod", "go.sum"}, parentEntries) childEntries, err := generated.Directory("child").Entries(ctx) require.NoError(t, err) require.NotContains(t, childEntries, "go.mod") t.Run("preserves parent module name", func(t *testing.T) { goMod, err := generated.File("go.mod").Contents(ctx) require.NoError(t, err) require.Contains(t, goMod, "module example.com/test") }) }) t.Run("respects existing go.mod even if root points to parent that has go.mod", func(t *testing.T) { t.Parallel() c, ctx := connect(t) generated := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
closed
dagger/dagger
https://github.com/dagger/dagger
6,312
Modules: `dag.Host()` name is extremely confusing
When module code uses `dag.Host()`, the "host" it refers to is the module container's "host", not the CLI caller's host. While this is technically consistent, it's very non-obvious at first glance and a constant source of confusion. I think at a minimum we need to change `Host` to something with a more obvious name. TBD if this change also impacts non-module SDKs or if it's somehow scoped just to the codegen for modules. There's certainly larger scope changes to the API that could also be worth discussing, but changing to a more clear name seems like the bare-minimum baseline thing to do here. --- As a side-note, support for Module code being able to read files/env vars/etc. from the *CLI caller's host* is a separate topic, discussed in this other issue https://github.com/dagger/dagger/issues/6112
https://github.com/dagger/dagger/issues/6312
https://github.com/dagger/dagger/pull/6535
c241d901a48f699a1d62f0daad882c88730e1fba
7a63c3d019530d1f08b2f72cc28e753d99b5896d
2023-12-21T19:46:28Z
go
2024-02-01T14:23:42Z
core/integration/module_test.go
WithWorkdir("/work"). WithExec([]string{"go", "mod", "init", "example.com/test"}). WithNewFile("/work/foo.go", dagger.ContainerWithNewFileOpts{ Contents: "package foo\n", }). WithWorkdir("/work/child"). WithExec([]string{"go", "mod", "init", "my-mod"}). WithWorkdir("/work"). With(daggerExec("mod", "init", "-m=./child", "--name=child", "--sdk=go")). WithWorkdir("/work/child"). With(daggerExec("mod", "sync")). Directory("/work") parentEntries, err := generated.Entries(ctx) require.NoError(t, err) require.Equal(t, []string{"child", "dagger.json", "foo.go", "go.mod"}, parentEntries) childEntries, err := generated.Directory("child").Entries(ctx) require.NoError(t, err) require.Contains(t, childEntries, "go.mod") require.Contains(t, childEntries, "go.sum") }) t.Run("respects existing main.go", func(t *testing.T) { t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). WithNewFile("/work/main.go", dagger.ContainerWithNewFileOpts{ Contents: `
closed
dagger/dagger
https://github.com/dagger/dagger
6,312
Modules: `dag.Host()` name is extremely confusing
When module code uses `dag.Host()`, the "host" it refers to is the module container's "host", not the CLI caller's host. While this is technically consistent, it's very non-obvious at first glance and a constant source of confusion. I think at a minimum we need to change `Host` to something with a more obvious name. TBD if this change also impacts non-module SDKs or if it's somehow scoped just to the codegen for modules. There's certainly larger scope changes to the API that could also be worth discussing, but changing to a more clear name seems like the bare-minimum baseline thing to do here. --- As a side-note, support for Module code being able to read files/env vars/etc. from the *CLI caller's host* is a separate topic, discussed in this other issue https://github.com/dagger/dagger/issues/6112
https://github.com/dagger/dagger/issues/6312
https://github.com/dagger/dagger/pull/6535
c241d901a48f699a1d62f0daad882c88730e1fba
7a63c3d019530d1f08b2f72cc28e753d99b5896d
2023-12-21T19:46:28Z
go
2024-02-01T14:23:42Z
core/integration/module_test.go
package main type HasMainGo struct {} func (m *HasMainGo) Hello() string { return "Hello, world!" } `, }). With(daggerExec("mod", "init", "--name=hasMainGo", "--sdk=go")) logGen(ctx, t, modGen.Directory(".")) out, err := modGen. With(daggerQuery(`{hasMainGo{hello}}`)). Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"hasMainGo":{"hello":"Hello, world!"}}`, out) }) t.Run("respects existing main.go even if it uses types not generated yet", func(t *testing.T) { t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). WithNewFile("/work/main.go", dagger.ContainerWithNewFileOpts{ Contents: ` package main type HasDaggerTypes struct {} func (m *HasDaggerTypes) Hello() *Container { return dag.Container(). From("` + alpineImage + `"). WithExec([]string{"echo", "Hello, world!"}) } `, }).