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

Add support for nerdctl on macos. #594

Merged
merged 7 commits into from
Sep 15, 2021

Conversation

mattfarina
Copy link
Contributor

This includes:

  • nerdctl as a CLI that can be added to the path like the other
    tools.
  • An updated version of alpine-lima that includes nerdctl and the
    other binaries it needs.
  • ~ is mounted so that nerdctl build can access the files to build.
    nerdctl build will not work for locations outside of ~.
  • A .profile file exporting an environment variable to tell nerdctl
    where the containerd socket is as k3s puts it in a non-standard
    location.

Note, in the future we should look at taring up the build directory
and sending it to the VM. That would be a more substancial effort
to accomplish.

Related to #566

Thanks to Jan for all the pointers in creating this and the alpine-lima
build.

if ! LIMA_HOME="$HOME/Library/State/rancher-desktop/lima" ${scriptdir}/../lima/bin/limactl ls --json | grep '"name":"rancher-desktop"' | grep -q '"status":"Running"'; then
echo "Rancher Desktop is not running. Please start Rancher Desktop to use nerdctl";
else
LIMA_HOME="$HOME/Library/State/rancher-desktop/lima" ${scriptdir}/../lima/bin/limactl shell rancher-desktop nerdctl $@
Copy link
Member

Choose a reason for hiding this comment

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

Needs quotes in case arguments contain spaces:

Suggested change
LIMA_HOME="$HOME/Library/State/rancher-desktop/lima" ${scriptdir}/../lima/bin/limactl shell rancher-desktop nerdctl $@
LIMA_HOME="$HOME/Library/State/rancher-desktop/lima" ${scriptdir}/../lima/bin/limactl shell rancher-desktop nerdctl "$@"

arch: 'x86_64',
}],
cpus: this.cfg?.numberCPUs || 4,
memory: (this.cfg?.memoryInGB || 4) * 1024 * 1024 * 1024,
mounts: [{ location: path.join(paths.cache(), 'k3s'), writable: false }],
mounts: [{ location: path.join(paths.cache(), 'k3s'), writable: false },{location: "~", writable: false }],
Copy link
Member

Choose a reason for hiding this comment

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

Maybe also add a writable location, so that users can put data back on the host without having to use limactl copy? The sample configurations for lima share /tmp/lima between host and VM: https://github.com/lima-vm/lima/blob/master/pkg/limayaml/default.yaml#L45-L46

@@ -0,0 +1 @@
export CONTAINERD_ADDRESS=/run/k3s/containerd/containerd.sock

Choose a reason for hiding this comment

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

Users may expect export CONTAINERD_NAMESPACE=k8s.io too, if they expect nerdctl ps to show k3s containers.

Copy link
Member

Choose a reason for hiding this comment

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

I believe this is supposed to be used for native container development à la docker-compose, in which case keeping images separate would be a feature.

I would keep it separate for now, and maybe later add a checkbox in the GUI to set the default namespace?

Choose a reason for hiding this comment

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

SGTM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@AkihiroSuda Thanks for checking in on this. I had thought about the namespace part. But, we want to expose full nerdctl to people who just want to work with containers. We will document using the Kubernetes namespace for those who want it for that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be in src/assets/scripts/… instead?

Do we need this as a separate file, or is putting it inside of the nerdctl script enough (as in, /usr/bin/env CONTAINERD_ADDRESS=… nerdctl …)? Having a separate script makes more sense if we expect other things to need it, but I don't believe we expect users to manually run limactl shell (except as a troubleshooting step under our direction).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've set it up this way because I've been using nerdctl within the VM for troubleshooting. This just makes it easier.

Copy link
Member

@jandubois jandubois Sep 15, 2021

Choose a reason for hiding this comment

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

We will soon be able to put the thing into lima.yaml as

env:
 CONTAINERD_ADDRESS=/run/k3s/containerd/containerd.sock

and it will automatically be added to /etc/environment and be available everywhere in the guest.

This doesn't work right now because our Alpine image uses an sshd that has been compiled without pam support (and also there is no sshd.pamd file either that enables pam_env for ssh sessions). Will work on this soonish, but for now using .profile seems fine.

scripts/download/lima.mjs Outdated Show resolved Hide resolved
@mattfarina mattfarina marked this pull request as draft September 8, 2021 18:52
@mattfarina mattfarina marked this pull request as ready for review September 8, 2021 21:40
This includes:
- nerdctl as a CLI that can be added to the path like the other
  tools.
- An updated version of alpine-lima that includes nerdctl and the
  other binaries it needs.
- ~ is mounted so that nerdctl build can access the files to build.
  nerdctl build will not work for locations outside of ~.
- A .profile file exporting an environment variable to tell nerdctl
  where the containerd socket is as k3s puts it in a non-standard
  location.

Note, in the future we should look at taring up the build directory
and sending it to the VM. That would be a more substancial effort
to accomplish.

Related to rancher-sandbox#566

Thanks to Jan for all the pointers in creating this and the alpine-lima
build.

Signed-off-by: Matt Farina <[email protected]>
Based on feedback from Jan.

Signed-off-by: Matt Farina <[email protected]>
Signed-off-by: Matt Farina <[email protected]>
Feedback from Jan

Signed-off-by: Matt Farina <[email protected]>
Copy link
Member

@jandubois jandubois left a comment

Choose a reason for hiding this comment

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

LGTM

@jandubois jandubois merged commit 301f1ec into rancher-sandbox:main Sep 15, 2021
@mattfarina mattfarina deleted the macos-nerdctl branch September 15, 2021 18:23
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