Skip to content

Duck typing for CLI verbs #6230

Closed as not planned
Closed as not planned

Description

@sipsma

(converting a linear issue created+written by @shykes to GH since it relates to other public GH issues)

Context

The Dagger CLI has powerful "verbs" for executing a pipeline of Zenith functions, then doing something with the result. So far the following verbs exist:

  • dagger call: generic verb for executing a pipeline, streaming logs, and reporting errors
  • dagger download: save the result of the pipeline to the local filesystem. Supports string, File, Directory
  • dagger up: run the result as a service
  • dagger shell: execute the result as a container, with an interactive terminal attached

Verbs work by detecting the type of the pipeline result, and deciding what to do based on the type.

Problem

Dagger CLI verbs don't support custom types defined by a module. This forces modules to add unnecessary complexity.

For example, in my docker-compose module:

  • To bring up a service, I have to type dagger shell -m github.com/shykes/daggerverse/docker-clompose example service --name db up
    • Note the last up. This converts the custom ComposeService to the core Service, which is required for dagger up to work
    • This adds verbosity, and feels redundant
  • Instead I would like this work: dagger shell -m github.com/shykes/daggerverse/docker-compose example service --name db
    • Note the absence of the redundant up at the end

Solution

Implement duck-typing for CLI verbs. Instead of checking for specific core types, check for the required capabilities of those core types: certain required functions and their signatures.

  • Core types will continue to work as before, since they match the requirements
  • Custom types have a chance be picked up by the verbs, if they implement the right interface

Example:dagger up

My guess is that dagger up requires pipeline results to implement the following interface (graphql notation; from memory, may be not exactly accurate):

  • start: Bool!
  • ports: [Port!]
  • hostname: String!
  • endpoint

Knowing the interface, I could implement it in my DockerComposeService (probably by passing through to the underlying core service, but not necessarily!).


Related Issues:

Activity

  1. added
    area/cli
    and removed on Jun 4, 2024
  2. helderco commented on Jul 5, 2024

    @helderco
    Contributor

    Closing because we moved away from this design, to conciliate those verbs in dagger call.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/cli

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions