Skip to content

Container: add various config-related APIs - #3219

Merged
sipsma merged 6 commits into
dagger:cloakfrom
vito:container-more-configs
Oct 6, 2022
Merged

sipsma merged 6 commits into
dagger:cloakfrom
vito:container-more-configs

Conversation

@vito

@vito vito commented Oct 3, 2022 •

Copy link
Copy Markdown
Contributor

part of #3183

based on #3217 which is based on #3205 - will rebase after both are merged rebased on cloak so it's independent now

Implements the following APIs:

container {
  user
  withUser
  entrypoint
  withEntrypoint
  variable
  withoutVariable
  publish
}

note: this also means an image's USER and ENTRYPOINT are now respected.

@netlify

netlify Bot commented Oct 3, 2022 •

Copy link
Copy Markdown

👷 Deploy request for cloak-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 7f414c3

@vito
vito force-pushed the container-more-configs branch 4 times, most recently from e74d952 to cd7a63a Compare October 4, 2022 16:31
@vito
vito requested review from aluzzardi, shykes and sipsma October 4, 2022 16:32
vito added 3 commits October 4, 2022 15:51
note: this needed some trickery to make sure the shim is able to write
to /dagger/{stdout,stderr,exitCode}. the strategy is to use llb.Mkdir to
create a world-writable directory and then mount that to /dagger instead
of just llb.Scratch.

Signed-off-by: Alex Suraci <[email protected]>
also respects entrypoint if configured in image

Signed-off-by: Alex Suraci <[email protected]>
@vito
vito force-pushed the container-more-configs branch from cd7a63a to d0df5a2 Compare October 4, 2022 19:52
Signed-off-by: Alex Suraci <[email protected]>

@aluzzardi aluzzardi left a comment

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.

LGTM

One small spec nit, nothing to do with the implementation

require.NoError(t, err)

testRef := "127.0.0.1:5000/testimagepush:latest"
testRef := core.ContainerAddress("127.0.0.1:5000/testimagepush:latest")

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.

nit (on the spec, not the implementation): I think this should be a string rather than a scalar. Scalars define new types and are mostly useful for things that are "passthrough" to the client (e.g. an ID, which the user is supposed to retrieve and pass to another query, not create manually).

Container addresses however are "manually" entered by the user and I think having a scalar is not helping (and the user needs to do casting in their code to use it)

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'm inclined to agree. Opened #3257 for reaching consensus on this.

@sipsma sipsma left a comment

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 we should add the numeric uid test (here or follow-up), but otherwise LGTM!

Comment thread core/container.go
"directory": router.ErrResolver(ErrNotImplementedYet),
"user": router.ErrResolver(ErrNotImplementedYet),
"withUser": router.ErrResolver(ErrNotImplementedYet),
"user": router.ToResolver(s.user),

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.

We should make follow ups for withGroup and withSupplementaryGroup(s). Not blocking at all for this PR of course or even that high priority, just something we'll want eventually.

I just noticed that buildkit LLB is missing those though. So we'd have to either contribute upstream (ideal) or implement it via the shim (less ideal but fine if needed).

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 might actually work as-is, since it looks like the OCI config spec has it embedded in the User field like user:group:

https://github.com/opencontainers/image-spec/blob/main/config.md#properties

Not sure about supplementary groups though.

I'll add a test for this along with setting numeric UID/GID.

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.

You're right, good catch, this also just reignited a memory that I at one point had to deal with all this in old dagger, so I apparently knew about the user:group thing at one point and forgot: #2542 😂

Supplementary groups are fine to be missing for now I think; the use cases become much more obscure with them (wheel and various ones for devices like gpu and kvm are what I'm aware of, but that's just not important for us right now).

Comment thread core/container.go
// create /dagger mount point for the shim to write to
llb.AddMount(
metaMount,
// because the shim might run as non-root, we need to make a

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.

Just a note: I'm actually not sure whether we'd really want the shim to run as the same user in the long run. Some of the ideas we have for it in the future involve networking stuff that might require root in the network namespace.

This is totally fine for now since updating the shim to do setuid is a lot more work and this implementation is not breaking anything now. Just wanted to bring it up for future thought. cc @aluzzardi

container {
from(address: "alpine:3.16.2") {
user
withUser(name: "daemon") {

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.

Can we add a test that this works with numeric uids too? It will still be a string type but like "123".

I double checked and believe that is what buildkit supports underneath many layers, so worth checking it works for us up here too: https://github.com/sipsma/buildkit/blob/61307b8f2e73d681721b51856c10cb8606e5ea70/executor/oci/user.go#L20-L20

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.

Using numeric IDs works, but I'm not fully onboard with supporting it since relying on numeric IDs feels a little brittle, and the parameter is called name. Is there a use case for sticking with numeric IDs?

@sipsma sipsma Oct 5, 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.

Yeah use of a non-numeric name requires the presence of /etc/passwd (which buildkit reads to map the name to a UID), which not all images have (minimal ones that just contain static binaries for instance). Also sometimes you don't want a dependency on /etc/passwd (which can change from base image to base image) and want to just have a consistent UID setting across many possible base images.

@sipsma

sipsma commented Oct 5, 2022

Copy link
Copy Markdown
Contributor

@vito I just thought of a couple things while reviewing the other PR related to image push:

  1. When you push a container, it won't include the mounts. That makes sense to me because I know the implementation but I highly suspect that may end up confusing users. I know people ask in the buildkit slack+github why cache mounts aren't included in their exported images fairly often.
    • I'm not totally sure what to do with this information, just calling it out. I suppose the bare minimum is to just make sure this is documented.
    • It's technically possible for us to include all the mounts with the image through the use of copies and mergeop, but I don't know if we want to do that.
  2. If your container rootfs is a subdir of some other state, will the resulting image be that subdir? Or the "full" original dir?
    • From what I can tell looking at the code, it will be the full original dir, which I highly suspect will be confusing and surprising.
    • This is something we can actually fix relatively straightforwardly (copy the subdir to its own scratch state at root, push that state as the image), so I think we should do that as a followup here.

@vito

vito commented Oct 5, 2022

Copy link
Copy Markdown
Contributor Author

When you push a container, it won't include the mounts. That makes sense to me because I know the implementation but I highly suspect that may end up confusing users. I know people ask in the buildkit slack+github why cache mounts aren't included in their exported images fairly often.

Interesting - I wonder why people want to export cache mounts. 🤔

IMO this is a major feature since it lets you push tiny images built using large intermediate layers that are mounted in and then discarded. A lot of Dockerfiles do this with a complicated multi-stage + copying scheme, so it's kind of neat that Dagger makes it feel more natural. But it should absolutely be documented and framed as such. I've opened #3260 to track this.

To your point, we may need to support intentionally copying a Directory into an image too - for example, someone may need to aggregate a bunch of assets they downloaded and publish them in an image together. You could do it by mounting it somewhere and running cp but it's a little hokey.

If your container rootfs is a subdir of some other state, will the resulting image be that subdir? Or the "full" original dir?

Good point. Am I right that this will only be a concern once we implement withFS? Right now a rootfs will always be initialized with container { from } so I think it's OK, but this is definitely something we'll need to address once we support setting arbitrary directories as the rootfs.

@sipsma

sipsma commented Oct 5, 2022

Copy link
Copy Markdown
Contributor

Good point. Am I right that this will only be a concern once we implement withFS? Right now a rootfs will always be initialized with container { from } so I think it's OK, but this is definitely something we'll need to address once we support setting arbitrary directories as the rootfs.

Ah yes, I thought we already implemented that for some reason, but it's not an issue until that possibility exists.

To your point, we may need to support intentionally copying a Directory into an image too - for example, someone may need to aggregate a bunch of assets they downloaded and publish them in an image together. You could do it by mounting it somewhere and running cp but it's a little hokey.

Yeah I guess it would be the same as Directory.withDirectory but on Container? Yeah we should do that for sure I think, I actually thought we had that already.

Interesting - I wonder why people want to export cache mounts. 🤔

Pretty sure they were using python or nodejs and wanted to include the package cache with the image. Whether that's really a good idea or not is a different question :-)

@vito

vito commented Oct 5, 2022 •

Copy link
Copy Markdown
Contributor Author

@sipsma Ready for another look! (Assuming tests pass...)

Main differences:

  • test setting user:group name
  • test setting uid + gid
  • make withEntrypoint, withUser, withWorkdir, withoutVariable args required

Yeah I guess it would be the same as Directory.withDirectory but on Container? Yeah we should do that for sure I think, I actually thought we had that already.

Opened #3264 for this

Pretty sure they were using python or nodejs and wanted to include the package cache with the image. Whether that's really a good idea or not is a different question :-)

Ah that makes sense, since those might be runtime dependencies. They probably want to vendor them but also not have to fetch them from scratch on every build.

@sipsma
sipsma merged commit e322b51 into dagger:cloak Oct 6, 2022
@vito
vito deleted the container-more-configs branch October 6, 2022 00:06
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