From bc2c0974c9398c3d5f3ec412b2b7a4312431ff31 Mon Sep 17 00:00:00 2001 From: Matt Farina Date: Wed, 8 Sep 2021 13:37:55 -0400 Subject: [PATCH 1/7] 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 | 4 +++- src/resources.ts | 1 + 5 files changed, 17 insertions(+), 2 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 44e4500d504..6fc895b4333 100644 --- a/src/k8s-engine/lima.ts +++ b/src/k8s-engine/lima.ts @@ -49,6 +49,7 @@ enum Integrations { HELM = 'helm', KIM = 'kim', KUBECTL = 'kubectl', + NERDCTL = 'nerdctl', } /** @@ -362,7 +363,7 @@ export default class LimaBackend extends events.EventEmitter implements K8s.Kube }], 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 }, }); @@ -482,6 +483,7 @@ 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) { From d778999c72a571e77b66387149941b08fb256cab Mon Sep 17 00:00:00 2001 From: Matt Farina Date: Wed, 8 Sep 2021 13:45:23 -0400 Subject: [PATCH 2/7] Improving the nerdctl detection of running rd Based on feedback from Jan. Signed-off-by: Matt Farina --- resources/darwin/bin/nerdctl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/darwin/bin/nerdctl b/resources/darwin/bin/nerdctl index bc5e431e73d..400de381b63 100755 --- a/resources/darwin/bin/nerdctl +++ b/resources/darwin/bin/nerdctl @@ -4,7 +4,7 @@ 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 +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 $@ From 17498aa420b3704c206c5a5b7b4b77070359bf39 Mon Sep 17 00:00:00 2001 From: Matt Farina Date: Wed, 8 Sep 2021 14:34:29 -0400 Subject: [PATCH 3/7] Updating the nerdctl script based on Jan's feedback Signed-off-by: Matt Farina --- resources/darwin/bin/nerdctl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/resources/darwin/bin/nerdctl b/resources/darwin/bin/nerdctl index 400de381b63..9c2a59b6788 100755 --- a/resources/darwin/bin/nerdctl +++ b/resources/darwin/bin/nerdctl @@ -1,11 +1,12 @@ #!/bin/bash +set -eu -o pipefail 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 --json | grep '"name":"rancher-desktop"' | grep -q '"status":"Running"'; then +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 $@ + LIMA_HOME="$HOME/Library/State/rancher-desktop/lima" "${scriptdir}/../lima/bin/limactl" shell rancher-desktop nerdctl "$@" fi From 1285d2274bba1a24d545840a74b58834ba37de09 Mon Sep 17 00:00:00 2001 From: Matt Farina Date: Wed, 8 Sep 2021 14:36:46 -0400 Subject: [PATCH 4/7] lint fixes Signed-off-by: Matt Farina --- src/k8s-engine/lima.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/k8s-engine/lima.ts b/src/k8s-engine/lima.ts index 6fc895b4333..e07e257feeb 100644 --- a/src/k8s-engine/lima.ts +++ b/src/k8s-engine/lima.ts @@ -363,7 +363,7 @@ export default class LimaBackend extends events.EventEmitter implements K8s.Kube }], cpus: this.cfg?.numberCPUs || 4, memory: (this.cfg?.memoryInGB || 4) * 1024 * 1024 * 1024, - mounts: [{ location: path.join(paths.cache, 'k3s'), writable: false },{location: "~", writable: false }], + mounts: [{ location: path.join(paths.cache, 'k3s'), writable: false }, { location: '~', writable: false }], ssh: { localPort: await this.sshPort }, k3s: { version: desiredVersion }, }); From 9ebeb67b10822e3ae3f69f00fd0de1d23a9088ae Mon Sep 17 00:00:00 2001 From: Matt Farina Date: Wed, 8 Sep 2021 14:39:54 -0400 Subject: [PATCH 5/7] Exposing a writable volume via temp Feedback from Jan Signed-off-by: Matt Farina --- src/k8s-engine/lima.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/k8s-engine/lima.ts b/src/k8s-engine/lima.ts index e07e257feeb..8d504355ad4 100644 --- a/src/k8s-engine/lima.ts +++ b/src/k8s-engine/lima.ts @@ -363,7 +363,11 @@ export default class LimaBackend extends events.EventEmitter implements K8s.Kube }], cpus: this.cfg?.numberCPUs || 4, memory: (this.cfg?.memoryInGB || 4) * 1024 * 1024 * 1024, - mounts: [{ location: path.join(paths.cache, 'k3s'), writable: false }, { location: '~', writable: false }], + mounts: [ + { location: path.join(paths.cache, 'k3s'), writable: false }, + { location: '~', writable: false }, + { location: '/tmp/rancher-desktop', writable: true }, + ], ssh: { localPort: await this.sshPort }, k3s: { version: desiredVersion }, }); From 285fb1a1d305c3be6db849529909da3e85ee723e Mon Sep 17 00:00:00 2001 From: Matt Farina Date: Wed, 8 Sep 2021 17:39:04 -0400 Subject: [PATCH 6/7] Updating the lima alpine version Signed-off-by: Matt Farina --- scripts/download/lima.mjs | 4 ++-- src/k8s-engine/lima.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/download/lima.mjs b/scripts/download/lima.mjs index 716e26222ae..3828afec8bc 100644 --- a/scripts/download/lima.mjs +++ b/scripts/download/lima.mjs @@ -10,8 +10,8 @@ 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.3'; -const alpineLimaEdition = 'std'; +const alpineLimaTag = 'v0.1.4'; +const alpineLimaEdition = 'rd'; const alpineLimaVersion = '3.13.5'; async function getLima() { diff --git a/src/k8s-engine/lima.ts b/src/k8s-engine/lima.ts index 8d504355ad4..65924d94fd8 100644 --- a/src/k8s-engine/lima.ts +++ b/src/k8s-engine/lima.ts @@ -357,8 +357,8 @@ export default class LimaBackend extends events.EventEmitter implements K8s.Kube const currentConfig = await this.currentConfig; 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'), + images: [{ + location: resources.get(os.platform(), 'alpline-lima-v0.1.4-rd-3.13.5.iso'), arch: 'x86_64', }], cpus: this.cfg?.numberCPUs || 4, From 7505928dbe90673e102da0b2c4f9eb94dab09742 Mon Sep 17 00:00:00 2001 From: Matt Farina Date: Fri, 10 Sep 2021 17:03:11 -0400 Subject: [PATCH 7/7] Updating nerdctl script to new storage location Signed-off-by: Matt Farina --- resources/darwin/bin/nerdctl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/darwin/bin/nerdctl b/resources/darwin/bin/nerdctl index 9c2a59b6788..a9cde485a34 100755 --- a/resources/darwin/bin/nerdctl +++ b/resources/darwin/bin/nerdctl @@ -5,8 +5,8 @@ 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 --json | grep '"name":"rancher-desktop"' | grep -q '"status":"Running"'; then +if ! LIMA_HOME="$HOME/Library/Application Support/rancher-desktop/lima" "${scriptdir}/../lima/bin/limactl" ls --json | grep '"name":"0"' | 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 "$@" + LIMA_HOME="$HOME/Library/Application Support/rancher-desktop/lima" "${scriptdir}/../lima/bin/limactl" shell 0 nerdctl "$@" fi