Skip to content

Replace cloak.yaml with dagger.gql #3016

Closed

Description

@shykes

Overview

Currently the cloak prototype is configured by a project file called cloak.yaml.

We propose replacing this file with dagger.gql. The file would be functionally equivalent, but with 3 important differences:

  1. It avoids encoding a temporary project codename into user's repositories. This assumes "cloak" is simply a future release of Dagger, like Europa was for Dagger 0.2.
  2. It uses the GrapqhQL query language instead of YAML. Since Cloak is decidedly a GraphQL-centric engine, it makes sense that GQL should be the default, and the burden should be on other options (including YAML) to show that they are decidedly better.
  3. In addition to "cosmetic" changes of syntax and filename, we also propose slight changes in terminology, to reflect the deeper changes we are discussing in the overall DX, and hopefully stabilize our vocabulary.

Benefits

Benefits of this change include:

  1. Consistency. Dagger developers need to learn GQL queries anyway. Why not reuse and reinforce that knowledge for their configuration file too?

  2. Tooling. The same tooling can be used when writing the project config and dagger queries. For example the API playground can detect errors, auto-complete etc. This applies to future tooling as well, so the benefits compound over time.

  3. No YAML DSL. Parts of the current yaml file are re-inventing parts of the Dagger API, in order to specify how to fetch an extension. With a GQL file, you can simply use the API directly.

  4. Creates a "magnet" for more graphql content. A common best practice in graphql is to write and maintain an "operations file" to save and organize your queries and mutations. dagger.gql can naturally become your operations file. This opens possibility (all optional) for dagger to help load queries; share them; document them etc. For example Netlify Graph defines a very promising workflow around sharing and reusing example queries for learning and collaboration. cc @marcosnils @crjm @slumbering .

Spec

FIXME. See highlights and examples for now.

Design highlights

  • Special query names. Extensions and SDK have special meaning. Other operations in the document are ignored. Same pattern as main function co-existing with other functions in the same file.
  • Extensions makes use of Aliases to define all extensions in one query. This looks superficially familiar even without knowing graphql, or how aliases work. Later developers will learn how aliases really work, but it's not necessary to get started.
  • "Extension" is used interchangeably with "dependency". There is no such thing as a project "having its own extensions". A project may have an API, in which case it needs an SDK query to configure how to build it.

Other options which were explored and abandonned:

  • Use of custom directives
  • Use of mutations + input type

Terminology

graph LR;

subgraph projectA
   fileA["dagger.gql"]
end

subgraph projectB
   fileB["dagger.gql"]
end

subgraph projectC
   fileC["dagger.gql"]
end
Loading

Example

Dagger file for a frontend project:

query Extensions {
  yarn: git(url: "ssh://[email protected]/dagger/cloak") {
    branch(name: "main") {
      tree {
        directory(path: "examples/yarn") {
          id
        }
      }
    }
  }

  netlify: git(url: "ssh://[email protected]/dagger/cloak") {
    branch(name: "main") {
      tree {
        directory(path: "examples/netlify") {
          id
        }
      }
    }
  }

  vercel: workdir {
    directory(path: "./extensions/vercel") {
      id
    }
  }
}

query SDK {
    universe {
        sdk {
            typescript(version: "1.14", path: "./api") {
                id
            }
        }
    }
}

Top-level Dagger file in a monorepo shared by a frontend, backend and machine learning team:

query Extensions {
    frontend: workdir(path: "./frontend") {
        id
    }
    backend: workdir(path: "./backend") {
        id
    }
    ml: workdir(path: "./ml") {
        id
    }
}

Activity

  1. shykes commented on Sep 14, 2022

    @shykes
    ContributorAuthor
  2. added this to the Cloak GA milestone on Sep 16, 2022
  3. transferred this issue fromdagger/cloakon Sep 16, 2022
  4. sipsma commented on Sep 28, 2022

    @sipsma
    Contributor

    100% onboard with all of this, it's certainly better than yaml and great in that we can get the full power of our API for configuring projects.

    Just notes for the implementer of this (possibly me):

    1. The change to get rid of the difference between project extensions and dependencies will require some subtle changes to the extension loading process.
      • Currently dependencies point to a different cloak.yaml somewhere
      • Now, you directly point to extensions that you want to use (not to a different dagger.gql)
      • This means that when you load an extension, you need to find its SDK (so you know what runtime to use and make it executable). This will require reimplementing the "find-up" logic but now inside the cloak server and on top of LLB (whereas that find-up logic previously happened in the local engine on local dirs).
      • Nevermind, see comment here: Replace cloak.yaml with dagger.gql #3016 (comment)
    2. We'll need to submit graphql queries from within the implementation of other queries; fortunately @aluzzardi already has an example of doing this here as part of the secret support:

      dagger/router/router.go

      Lines 68 to 80 in d0f4a4e

      func (r *Router) Do(ctx context.Context, query string, variables map[string]any) *graphql.Result {
      r.l.RLock()
      schema := *r.s
      r.l.RUnlock()
      params := graphql.Params{
      Context: ctx,
      Schema: schema,
      RequestString: query,
      VariableValues: variables,
      }
      return graphql.Do(params)
      }
  5. sipsma commented on Sep 28, 2022

    @sipsma
    Contributor

    Oh also, as mentioned in discord, updating all of this is also a good opportunity to figure out how the current project schema (prototype-quality, not thoroughly designed) could be updated to integrate with the new API (Container/Directory/etc.). Not strictly necessary, but we will be touching that whole part of the codebase so worth consideration.

  6. shykes commented on Sep 28, 2022

    @shykes
    ContributorAuthor
    1. The change to get rid of the difference between project extensions and dependencies will require some subtle changes to the extension loading process.

      • Currently dependencies point to a different cloak.yaml somewhere
      • Now, you directly point to extensions that you want to use (not to a different dagger.gql)

    Actually, in this proposal I am using the word "extension" as a synonym to "dependency" (think "vscode extension"). So as I imagine it, the directory for each extension must contain its own dagger.gql. Otherwise, as you note we would be missing SDK information (and possibly other project-specific information in the future).

    • This means that when you load an extension, you need to find its SDK (so you know what runtime to use and make it executable). This will require reimplementing the "find-up" logic but now inside the cloak server and on top of LLB (whereas that find-up logic previously happened in the local engine on local dirs).

    Given my previous comment, I think perhaps this is not needed after all? Not sure as I don't completely understand it :)

  7. sipsma commented on Sep 28, 2022

    @sipsma
    Contributor

    Actually, in this proposal I am using the word "extension" as a synonym to "dependency" (think "vscode extension"). So as I imagine it, the directory for each extension must contain its own dagger.gql. Otherwise, as you note we would be missing SDK information (and possibly other project-specific information in the future).

    Ahhh okay, that sounds familiar now from the discussions previously, thanks. I was still imagining that we have the same model where dagger.gql serves as the project config for the entire directory tree under it.

    We can avoid that for now actually though. If we start by just colocating dagger.gql with extensions like you're saying, that's simpler at the moment and also doesn't stop us from re-implementing the older behavior in the future (I think it would be a completely backwards compatible update actually).

    So yeah ignore what I said before.

  8. aluzzardi commented on Sep 28, 2022

    @aluzzardi
    Contributor

    re: the conversation we just had about multi-tenancy.

    One downside of switching to GraphQL is it will be harder to machine generate manifests (and parse as well).

    This will limit possibilities such as the playground generating a list of extensions to be provided alongside the request (e.g. as a header).

  9. sipsma commented on Sep 28, 2022

    @sipsma
    Contributor

    This will limit possibilities such as the playground generating a list of extensions to be provided alongside the request (e.g. as a header).

    Couldn't it just provide the contents of dagger.gql as a header value? Agree that there are less libraries for programmatically generating graphql than there are for yaml, but in our very particular case we have to create a whole editor for crafting graphql queries anyways, so unless I'm not thinking of something it shouldn't expand the scope of what the playground has to do very much.

  10. jpadams commented on Sep 28, 2022

    @jpadams
    Contributor

    @kpenfound and I were chatting about using this file to contain metadata for Universe marketplace as well. Something like GitHub's action.yml.

    https://github.com/actions/setup-dotnet/blob/main/action.yml#L1-L6

    cc @slumbering

  11. mircubed commented on Oct 3, 2022

    @mircubed
    Contributor

    @sipsma this is in the GA bucket, but do we need this for preview release?

  12. sipsma commented on Oct 3, 2022

    @sipsma
    Contributor

    @mircubed Yeah I think we should try to get this in the preview. Otherwise we will be asking all users to completely rewrite all of their configs after preview.

  13. mircubed commented on Oct 4, 2022

    @mircubed
    Contributor

    @sipsma after talking with @aluzzardi it seems like you are the only one who can own this, so are you going to have time? If not, is there a way to make this a smaller issue to tackle for preview and then leave some work in another issue to complete before GA?

  14. self-assigned this
    on Oct 4, 2022
  15. sipsma commented on Oct 4, 2022

    @sipsma
    Contributor

    @mircubed Short answer: yes it should be doable but it will be close.

    Long answer: My current top goal is to finish code-first schema support for go
    . I think it will be out of draft tomorrow. Then I will be able to start on dagger.gql (while also having to go back and address comments on previous PR).

    So that gives me starting thursday of this week and the next week (7 weekdays). I currently imagine that the implementation of dagger.gql should take 2 days (assuming there's lots of distractions as usual, not 100% focused work), so multiplying x2 gives 4 days, so then that leaves 3 days to review+merge+update docs?

    So there's risk to it, but it feels within reason.

    is there a way to make this a smaller issue to tackle for preview

    I will allow myself to take shortcuts and not implement features if time starts running short. The main thing has to be that it's a graphql format and not yaml anymore. That's the transition that will be painful for users to make and is thus needed pre-preview. If there's niceties missing from the graphql format for some reason that'll be acceptable.

  16. shykes commented on Oct 5, 2022

    @shykes
    ContributorAuthor

    Logging concerns from @aluzzardi today, originally posted on discord:

    With everything that's happening, I'm less convinced about dagger.gql.

    • With codegen and xdx, users can use dagger without a single line of GraphQL (neither query nor schema). dagger.gql brings us in the opposite direction where users have to write GraphQL anyway for the manifest
    • GraphQL is hard(er) to programmatically generate. Burden for tooling (e.g. Adding a text editor in playground for dagger.gql -> easy. Adding a UI on top -> hard) e.g. the "Add to Project" that was just mentioned.
    • Unclear to me how to add extra stuff in there, if need be. Hypothetical example: if we wanted to add something about resources (e.g. cpu/memory limit, etc) where would it go? Not immediately obvious how to design that query
    • [old concern, still there] About static analysis. Hard to do by imposing limitations (what the query can do, e.g. no containers etc), impossible without limitations
    • Removes possibility (or at least, makes it harder) to parameterize things "cli side". By being queries it assumes everything will be handled by the graphql server, the CLI is just a dumb passthrough. If we wanted the cli to understand the manifest, it would require to parse and understand gql. Example: for instance this removes the possibility for codegen being done by the CLI, since it won't be able to understand the "sdk" part of the manifest
  17. sipsma commented on Oct 5, 2022

    @sipsma
    Contributor

    My reply at the time in discord:

    dagger.gql brings us in the opposite direction where users have to write GraphQL anyway for the manifest

    I don't like this either, but I still consider this a step up from forcing use of a yaml DSL on top of our graphql api.

    I also find it interesting that since we are creating language abstractions on top of graphql queries, there may be a door where we someday support specifying the dagger.gql queries with actual languages too. That's a quarter-baked idea, extremely hypothetical, but it is an example of the potential benefit of dogfooding what we're building rather than just bolting yaml on top.

    • GraphQL is hard(er) to programmatically generate. Burden for tooling (e.g. Adding a text editor in playground for dagger.gql -> easy. Adding a UI on top -> hard)

    Doesn't the playground need a graphql query editor anyways though? I'd rather re-use that than have to support a yaml editor too. But I may be misunderstanding the concern.

    • Unclear to me how to add extra stuff in there, if need be. Hypothetical example: if we wanted to add something about resources (e.g. cpu/memory limit, etc) where would it go? Not immediately obvious how to design that query

    Wouldn't we have the same questions with yaml?

    If we wanted the cli to understand the manifest, it would require to parse and understand gql.

    This is possible and not that bad IMO. It's not as nice as yaml unmarshal but the vektah gql library has been pretty reasonable to use I think.

    I also think we want codegen in the API anyways so I'm not sure this would be a concern for very long

  18. sipsma commented on Oct 6, 2022

    @sipsma
    Contributor

    There was a long discussion in discord, we ultimately decided to go a different route that @aluzzardi suggested to:

    1. Use a boring json format for the actual config file
    2. Emphasize use of the CLI and/or web browser UI to interact with the file (crud operations)

    This allows us to focus on making the UX wrappers nice and care less about making the format itself easily human readable/writable/interoperable. The file will still be possible to read/edit by a human (i.e. not binary), but we won't optimize for that experience.

    Other nice side effects mentioned in discord:

    1. Migration to different formats in future is much easier
    2. Easy to put lock file functionality in there too
    3. Easy to hook other functionality into updates (i.e. codegen on dagger add <extension>)
    4. Still possible to support arbitrary queries (i.e. something along lines of dagger add <<EOF <graphql query> )
    5. Still copy-paste shareable, it's just that now dagger cli commands will be copy-pasted rather than snippets of some file format

    The other changes around dagger.gql involving simplifications to extensions vs dependencies, scripts, etc. should all still apply here though.

    We will see if we get the CLI changes in for preview. There is risk they are tied w/ cloud-side changes (i.e. ux of updating this file in a browser), so we may defer those and just have a hand edited file in the short term. Will see once I try tomorrow.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions