Skip to content

dagger.json - #3281

Merged
sipsma merged 7 commits into
dagger:cloakfrom
sipsma:dagger-json
Oct 13, 2022
Merged

sipsma merged 7 commits into
dagger:cloakfrom
sipsma:dagger-json

Conversation

@sipsma

@sipsma sipsma commented Oct 6, 2022 •

Copy link
Copy Markdown
Contributor

Related: #3016

Follow-ups

  1. Support for URI (or similar) approach when specifying projects #3351
  2. Announce breaking change to community once merged?
    • Actually now that extensions are being deferred for public launch, maybe not? We need to decide what to do about all the existing extensions+users trying them.

TODO

  • Make dagger.json optional (cloak.yaml should be optional #3275)
  • Rebase on new cloak->dagger commits and code-first schema PR (once that's merged soon)
  • Docs (just updated the existing extension guides for now, since that's the only time they are needed)
  • Fix gitdeps example in the repo
  • More testing (add new tests here, validate against external repos like todoapp and other extensions)
  • The format of extensions like {"local": "path/to/local"} is weird, made sense in yaml but not json, worth a quick re-assessment
  • Going to try making a CLI wrapper for CRUD operations quick. If this devolves into many subproblems, discussions, other open design threads, etc. then I will save that for a follow up.
  • Remove the find-up behavior (for now, pending further discussion)

Format

Example w/ an SDK

{
  "name": "myproject",
  "extensions": {
    "alpine": {
      "local": {
        "path": "examples/alpine/dagger.json"
      }
    },
    "netlify": {
      "git": {
        "remote": "https://github.com/sipsma/foo",
        "ref": "bar",
        "path": "path/to/netlify/dagger.json"
      }
    }
  },
  "sdk": "go"
}
  • One important part of the format is that extensions is keyed by the extension name (whereas previously in the yaml you just provided a list of locations). This is a good thing I think: it reflects the fact that extensions are currently identified uniquely in the router by their name alone and there thus can only be one with a given name at a time.

  • Other than that, I am not a huge fan of the weird "location" and "params" keys; it exists mostly because it was a convenient format to achieve some semblance of polymorphism in the go code for parsing all this while still using static types to the extent possible. Happy to adjust it if needed.

sdk field

"sdk" is an optional field. The behavior of loading a project will change depending on whether it is present or not:

  1. If it is present - you are defining a new API, so when clients load it, only that new API will be presented to them.
  2. If it is not present - there is no new API defined, so instead clients loading dagger.json will be presented the merged API of the extensions defined in dagger.json.

This is the only relatively clean way I found in the short term to achieve the behavior described here (and that was present previously due to distinction between dependencies and extensions) while staying logically consistent.

Note that there's a huge caveat to all of the above: until this issue has been fixed, none of the above matters because there is only a single global schema. The code has been written such that the above behavior should appear once we've addressed that issue though, so it's extremely important we are all on the same page about it rather than surprised later.

Let me know if this makes sense, it's very subtle, I can provide a full concrete example if helpful.

Loading Behavior

  • dagger.json can only be used for one extension now. No more scripts field either
  • Removed the "find-up" behavior (for now, can discuss more, sometimes it's nice sometimes it's annoying)

CLI interface

Threw together a very basic CLI interface. Happy to adjust and clean this up, but want to get initial feedback before too much work.

dagger project

Dumps the current json (can support more formats in future)

dagger project init

dagger project init --name foobar --sdk go
  • creates a new dagger.json in your cwd
  • sdk is optional

dagger project add

local:

dagger project add local --path path/to/dagger.json

git:

dagger project add git --remote https://github.com/sipsma/foo --ref bar --path path/to/dagger.json
  • The "name" key is found by actually loading the dagger.json specified (in the case of git this requires use of the engine and project API, which is pretty convenient)
  • If there's another extension with the same name key, the current behavior is to just overwrite it. Can change that though

dagger project rm

dagger project rm --name netlify
  • remove the extension with the given name from the extensions field in dagger.json
  • --name should probably just a positional arg, it's a flag for consistency atm but writing this now that seems silly. Will update

@netlify

netlify Bot commented Oct 6, 2022 •

Copy link
Copy Markdown

👷 Deploy request for cloak-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 79c42ea11c4aa6d4a9e84458232e784c4d279d5d

@aluzzardi

Copy link
Copy Markdown
Contributor

/cc @jpadams @kpenfound

This is the WIP cloak.yaml --> dagger.json PR.

  1. This is where universe would fit in as a a dependency (e.g. git, local, ... universe?)
  2. Perhaps some of the file format could be shared between the two

@shykes

This comment was marked as duplicate.

@aluzzardi

Copy link
Copy Markdown
Contributor

Overall looks good. Open questions on format, CLI, and other nitpickery:

Format:

    "netlify": {
      "location": "git",
      "params": {
        "remote": "https://github.com/sipsma/foo",
        "ref": "bar",
        "path": "path/to/netlify/dagger.json"
      }
    }

Brainstorming here, but how would we feel like encoding this as a string and "restructuring" later rather than storing the structure?

Example from package.json https://docs.npmjs.com/cli/v8/configuring-npm/package-json#dependencies

{
  "name": "baz",
  "dependencies": {
    "bar": "file:../foo/bar"
  }
}

They support git URLs (with #<commit-ish> ref information), GitHub, local, npm (e.g. our "universe").

Similar to what go.mod does (minus the npm/registry part).

Same feedback about the CLI: rather than dagger project add git --remote https://github.com/sipsma/foo --ref bar --path path/to/dagger.json, we could re-use this "string" syntax (just like yarn add <git remote url>)

=== If remaining with the current structured approach, one nitpick ===

Rather than a location string + params any (hard to manually read/write), I'd suggest something like this instead:

type Extension struct {
    Git *GitParams `json:"git,omitempty"`
    Local *LocalParams `json:"local,omitempty"`
 }

That way this:

{
    "netlify": {
      "location": "git",
      "params": {
        "remote": "https://github.com/sipsma/foo",
        "ref": "bar",
        "path": "path/to/netlify/dagger.json"
      }
    }
}

could be written as:

{
    "netlify": {
      "git": {
        "remote": "https://github.com/sipsma/foo",
        "ref": "bar",
        "path": "path/to/netlify/dagger.json"
      }
    }
}

(yeah the Go code would less nice since we'd need to switch over all the pointers and check which is not nil to figure out location, but IMHO it's nicer to read/write/document/validate)

@shykes

shykes commented Oct 12, 2022

Copy link
Copy Markdown
Contributor

@aluzzardi I’d say if it’s good enough for package.json, it’s good enough for us :) (for the parts that are actually semantically equivalent in both files of course)

@sipsma

sipsma commented Oct 12, 2022 •

Copy link
Copy Markdown
Contributor Author

@aluzzardi

Brainstorming here, but how would we feel like encoding this as a string and "restructuring" later rather than storing the structure?

I think we should definitely support that for the CLI interface (independently came up in this comment) but what's the advantage of doing that in the json file? The json config is meant to be human readable but not optimized for human writing (CLI should be main interface), which is where our approach deviates from package.json. Having structured data in a string in json seems more complicated than just using the structure of json directly. It also makes it more complicated to parse information out (have deser json and then deser strings inside it).

But again, all for supporting that on the CLI interface level. I do think the --flag format should remain there too because it's often easier to programmatically setup flags than it is to programmatically construct a structured string, but the structured strings is nicer to write by hand manually.

@sipsma
sipsma force-pushed the dagger-json branch 5 times, most recently from ba7bf09 to 10ddc51 Compare October 13, 2022 03:08
@sipsma
sipsma marked this pull request as ready for review October 13, 2022 03:10
@sipsma sipsma changed the title WIP: dagger.json dagger.json Oct 13, 2022
@sipsma

sipsma commented Oct 13, 2022

Copy link
Copy Markdown
Contributor Author

@aluzzardi know there's many other priorities and this one is now lower, but updated from your comments:

  1. Went back to "local": { ... } and "git": { ... } format like you suggested (I actually had that originally, tried the other way but agree now in retrospect the first way is simplest)
  2. Did not change to use "structured strings" in the json file directly (see my previous comment for why), but I did make a follow up issue for supporting that here on the CLI level here: Support for URI (or similar) approach when specifying projects #3351

Also, I ended up including a fix to make dagger.json optional here since otherwise there's tons of useless configs all over.

So if you have a spare min to look again, appreciate it. If it's feasible to merge this before I go on PTO next week that would be ideal since otherwise it's going to go stale.

@sipsma
sipsma merged commit d988bac into dagger:cloak Oct 13, 2022
@sipsma sipsma mentioned this pull request May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants