Skip to content

Fix gaps in core API spec - #3151

Closed
shykes wants to merge 1 commit into
dagger:mainfrom
shykes:api-fixes
Closed

shykes wants to merge 1 commit into
dagger:mainfrom
shykes:api-fixes

Conversation

@shykes

@shykes shykes commented Sep 26, 2022 •

Copy link
Copy Markdown
Contributor

As discussed with @aluzzardi @sipsma @vito :

  • Container { withFS }
  • Container { fs } (method rename to avoid capitalization nightmare)
  • Container { build }

@shykes
shykes changed the base branch from main to cloak September 26, 2022 23:36
Comment thread api/container.gql Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Bike shedding]

I see why it's this way, and the alternatives I have are not much better.

What bothers me is this chainable from is being more or less used as a "top level query with an empty selector" (e.g. container(from: XXX) vs container { from(XXX) })

In practice, this is the only correct incantation:

{
  container {
    from {
      ...
    }
}

Doing anything else, such as { container { withUser { from { ... } } } doesn't work. This is because, even though from looks like it can be chained, it actually doesn't care whatsoever about the parent value (as per the buildkit API).

Perhaps we could do something custom to merge the internal representation of a container with the one coming from llb.Image, but that's a big if (what does it even mean to container { withRoot(...) { from(...) { ... } }?)

Alternatives:

  • container(id: ContainerID, from: String) (both optional) and the user can decide to use one or another
    • However, that's weird. Can't find anything in the GitHub API that takes either THIS or THAT as selector for top-level queries
    • Even weirder in codegen
  • Top level query
    • Lazy: containerByID(id: ContainerID!): Container! / containerByImage(ref: String!): Container! <-- ugly
    • Different selector: container(id: ContainerID!): Container! / image(ref: String!): Container! <-- why not ...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good summary of the pros and cons of this approach, and possible alternatives. I think it's the least bad so far.

container(id: ContainerID, from: String) (both optional) and the user can decide to use one or another
However, that's weird. Can't find anything in the GitHub API that takes either THIS or THAT as selector for top-level queries
Even weirder in codegen

Yes, I agree it's weird. Feels like an implicit API and doesn't play to the strengths of GraphQL.

Lazy: containerByID(id: ContainerID!): Container! / containerByImage(ref: String!): Container! <-- ugly

Yup, ugly :)

Different selector: container(id: ContainerID!): Container! / image(ref: String!): Container! <-- why not ...

I don't like top-level image because it's not clear what kind of image we're talking about. IMO there should be a high bar of clarity and uniqueness to adding a top-level query field. "container" passes that bar but "image" doesn't, in my opinion.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way here's another variation I tried:

// id may be one of:
//  1. ID computed from `id` field in a previous query
//  2. OCI-compatible remote image address
container(id: ContainerID)

@vito vito Sep 30, 2022 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is OK now that withFS has been added.

If it weren't there, I would agree it's a bit weird to have container {} if the only practical sub-query for it is from. But now that withFS is there, they both just become diifferent ways to set the rootfs. Only one sets just the rootfs, and the other sets the rootfs + config.

In principle someone might want to use withFS from scratch to use a flat rootfs directory downloaded or built from something other than a registry. They'd probably need to set up $PATH next, but that's doable.

In fact even without withFS I can think of one way you could end up nesting from: you could start with a /src mount point containing your Go + JS app, then run go build to build your Go bits, and then yarn build to build your JS bits, all in one query:

container {
  from(address: "golang:1.19") {
    withMountedDirectory(path: "/src", source: $repo) {
      withWorkdir(path: "/src") {
        exec(args: ["go", "build", "./cmd/cloak"]) {
          from(address: "node") {
            withWorkdir(path: "/src") { # admittedly it's odd having to do this again
              exec(args: ["yarn", "build"]) {
                directory(path: "/src") {
                  id
                }
              }
            }
          }
        }
      }
    }
  }
}

Is that a pattern we want to encourage? I dunno. But it'd be cool if it "just worked", and I think it might. (edit: oh, nope, we just discard the parent container at the moment - but this would be an easy fix.) (edit 2: ok, it works now)

The point here is there's more to a container than just rootfs + config, since we also propagate the mount points along.

Comment thread api/container.gql Resolved
Comment thread api/container.gql Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO this should be part of directory as it always takes a directory as first argument.

It's the same principle we've applied to all other fields. In principle, these should be a mutation taking a container or directory as first argument. But we've decided instead to have them as fields of the type they would usually take as argument, to allow chaining.

In this case it's neither a mutation nor it allows chaining.

e.g.

git {
  build { # <-- can't be done
  }
}
{ 
  container {
    exec(...) {
      directory(path: "/out) {
        build { # can't be done
        }
      }
    }
  }
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a one-way door that we are not yet ready to cross, because it enshrines the concept of extensions being allowed / expected to add higher-level fields (like dockerBuild) to lower-level types (like Directory), something we are not yet ready to decide on IMO.

Yes our docker build implementation is built-in, but it sets a clear precedent for adding more build methods down the road:

  • Why Directory { build } and not Directory { dockerBuild }? After all there are other ways to build from a directory.
  • If Directory { dockerBuild }, why not Directory { yarnBuild }?
  • etc.

This may in fact be the pattern we choose for extensions. My point is that Directory { build } would force us into a decision too early.

The downside is that we lose an opportunity to chain in certain queries, but that constraints already exists anyway (and we can always cross the one-way door later).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One problem is that implementing docker build with a container will not be very straightforward as you can't inherently provide mounts alongside the context you send to the dockerfile frontend.

You could simulate normal read-write directory mounts, but you'd probably just have to ignore cache+tmpfs mounts entirely (or doing something truly insane like rewrite the Dockerfile to always include those with the context fs, which just isn't really viable imo).

A possible intermediate solution is to not extend Container or Directory with this and instead just add a top-level dockerbuild(dir: DirectoryID!). I don't like that either to be honest, but it at least would skirt around having to make a decision here.

@netlify

netlify Bot commented Sep 27, 2022 •

Copy link
Copy Markdown

👷 Deploy request for cloak-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 28409e6

Signed-off-by: Solomon Hykes <[email protected]>
@shykes

This comment was marked as resolved.

@shykes
shykes requested a review from aluzzardi September 29, 2022 16:10
@shykes

shykes commented Sep 30, 2022

Copy link
Copy Markdown
Contributor Author

Ping @aluzzardi @sipsma @vito we've got a bike shed to paint :)

@jlongtine

This comment was marked as resolved.

@sipsma

This comment was marked as resolved.

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.

5 participants