From a53379a26ce552049507af10742775d9718dcada Mon Sep 17 00:00:00 2001 From: Matt Farina Date: Wed, 8 Sep 2021 13:37:55 -0400 Subject: [PATCH] Add support for nerdctl on macos. 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. Signed-off-by: Matt Farina --- resources/darwin/bin/nerdctl | 11 +++++++++++ resources/scripts/profile | 1 + scripts/download/lima.mjs | 2 +- src/k8s-engine/lima.ts | 7 +++++-- src/resources.ts | 1 + 5 files changed, 19 insertions(+), 3 deletions(-) create mode 100755 resources/darwin/bin/nerdctl create mode 100644 resources/scripts/profile diff --git a/resources/darwin/bin/nerdctl b/resources/darwin/bin/nerdctl new file mode 100755 index 00000000000..bc5e431e73d --- /dev/null +++ b/resources/darwin/bin/nerdctl @@ -0,0 +1,11 @@ +#!/bin/bash + +scriptdir="${BASH_SOURCE[0]}" +[ -L "${scriptdir}" ] && scriptname="$(readlink "${scriptdir}")" +scriptdir="$(cd "$(dirname "${scriptname}")" && pwd)" + +if ! LIMA_HOME="$HOME/Library/State/rancher-desktop/lima" ${scriptdir}/../lima/bin/limactl ls | grep -q -E "rancher-desktop +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 $@ +fi diff --git a/resources/scripts/profile b/resources/scripts/profile new file mode 100644 index 00000000000..c6168a5ea05 --- /dev/null +++ b/resources/scripts/profile @@ -0,0 +1 @@ +export CONTAINERD_ADDRESS=/run/k3s/containerd/containerd.sock diff --git a/scripts/download/lima.mjs b/scripts/download/lima.mjs index b665b07859e..716e26222ae 100644 --- a/scripts/download/lima.mjs +++ b/scripts/download/lima.mjs @@ -10,7 +10,7 @@ const limaRepo = 'https://github.com/rancher-sandbox/lima-and-qemu'; const limaTag = 'v1.3'; const alpineLimaRepo = 'https://github.com/lima-vm/alpine-lima'; -const alpineLimaTag = 'v0.1.2'; +const alpineLimaTag = 'v0.1.3'; const alpineLimaEdition = 'std'; const alpineLimaVersion = '3.13.5'; diff --git a/src/k8s-engine/lima.ts b/src/k8s-engine/lima.ts index f248724704c..956f6bdf243 100644 --- a/src/k8s-engine/lima.ts +++ b/src/k8s-engine/lima.ts @@ -46,6 +46,7 @@ enum Integrations { HELM = 'helm', KIM = 'kim', KUBECTL = 'kubectl', + NERDCTL = 'nerdctl', } /** @@ -355,12 +356,12 @@ export default class LimaBackend extends events.EventEmitter implements K8s.Kube const baseConfig: Partial = currentConfig || {}; const config: LimaConfiguration = merge(baseConfig, DEFAULT_CONFIG as LimaConfiguration, { images: [{ - location: resources.get(os.platform(), 'alpline-lima-v0.1.2-std-3.13.5.iso'), + location: resources.get(os.platform(), 'alpline-lima-v0.1.3-std-3.13.5.iso'), 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 }], ssh: { localPort: await this.sshPort }, k3s: { version: desiredVersion }, }); @@ -480,6 +481,8 @@ export default class LimaBackend extends events.EventEmitter implements K8s.Kube await this.ssh('chmod', 'a+x', 'bin/install-k3s'); await fs.promises.chmod(path.join(paths.cache(), 'k3s', fullVersion, 'k3s'), 0o755); await this.ssh('sudo', 'bin/install-k3s', fullVersion, path.join(paths.cache(), 'k3s')); + + await this.lima('copy', resources.get('scripts', 'profile'), `${ MACHINE_NAME }:~/.profile`); } finally { await fs.promises.rm(workdir, { recursive: true }); } diff --git a/src/resources.ts b/src/resources.ts index 152174a8d81..c9737169c79 100644 --- a/src/resources.ts +++ b/src/resources.ts @@ -7,6 +7,7 @@ const adjustNameWithDir: Record = { helm: path.join('bin', 'helm'), kim: path.join('bin', 'kim'), kubectl: path.join('bin', 'kubectl'), + nerdctl: path.join('bin', 'nerdctl'), }; function fixedSourceName(name: string) {