Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to build and push an image? #143

Closed
the-sun-will-rise-tomorrow opened this issue Aug 4, 2024 · 2 comments
Closed

How to build and push an image? #143

the-sun-will-rise-tomorrow opened this issue Aug 4, 2024 · 2 comments

Comments

@the-sun-will-rise-tomorrow
Copy link

the-sun-will-rise-tomorrow commented Aug 4, 2024

Hi, thank you for this cool project! Sorry, I have some dumb questions:

If the goal is to define an image with Nix and then push it to a registry, am I correct that we need to:

  1. Ensure containerd with nix-snapshotter integration is set up and running
  2. Create the image definition using pkgs.nix-snapshotter.buildImage
  3. Run docker tag nix:0${image} my.registry.com/name:tag
  4. Run docker push my.registry.com/name:tag

and if it's not feasible to have containerd running in the current environment (e.g. it is a CI environment without any services or user namespace support), then build a VM to do all of the above and run it.

Is this accurate?

Would this allow skipping local instantiation of the Nix store paths for layers that are already on the target registry?

I tried to do the above with nix2container but ran into some trouble due to what I think is compression. Do you know if using nix-snapshotter + docker push would fare better?

Thanks!

@elpdt852
Copy link
Collaborator

Run the nix binary produced by an expression like ${redis.copyToRegistry {}}/bin/copy-to-registry:

nix-snapshotter/README.md

Lines 346 to 348 in 7b251c9

# Running "${redis.copyToRegistry {}}/bin/copy-to-registry" will copy it to
# an OCI-compliant Registry. It will try to use your Docker credentials to push
# if the target is DockerHub.

See the function signature:

# Copies an OCI archive to an OCI registry.
copyToRegistry = image: {
imageName ? image.name,
imageTag ? image.tag,
plainHTTP ? false,
}:

You don't need a docker daemon or containerd to push images to registries. This binary will copy the image directly to a registry given the imageName = "my.registry.com/name.

Some clarifications:

  • nix:0${image} is the image name used when nix-snapshotter is configured as a Kubelet Image Service for use with Kubernetes when you want to move image resolution also to the nix store (removing the need for a Docker Registry). If you want to push to a regular registry, build your image with resolvedByNix = false.
  • Nix store paths aren't uploaded to the target registry, it assumes your Nix store paths are uploaded to a Nix binary cache and the Nix daemon sitting next to containerd is configured to use it as a substituter.

@the-sun-will-rise-tomorrow
Copy link
Author

Nix store paths aren't uploaded to the target registry, it assumes your Nix store paths are uploaded to a Nix binary cache and the Nix daemon sitting next to containerd is configured to use it as a substituter.

Got it, thank you!

@the-sun-will-rise-tomorrow the-sun-will-rise-tomorrow closed this as not planned Won't fix, can't repro, duplicate, stale Aug 15, 2024
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

No branches or pull requests

2 participants