Skip to content

Commit

Permalink
Add support for nerdctl on macos.
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
mattfarina committed Sep 8, 2021
1 parent e6ca291 commit a53379a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
11 changes: 11 additions & 0 deletions resources/darwin/bin/nerdctl
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions resources/scripts/profile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export CONTAINERD_ADDRESS=/run/k3s/containerd/containerd.sock
2 changes: 1 addition & 1 deletion scripts/download/lima.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
7 changes: 5 additions & 2 deletions src/k8s-engine/lima.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ enum Integrations {
HELM = 'helm',
KIM = 'kim',
KUBECTL = 'kubectl',
NERDCTL = 'nerdctl',
}

/**
Expand Down Expand Up @@ -355,12 +356,12 @@ export default class LimaBackend extends events.EventEmitter implements K8s.Kube
const baseConfig: Partial<LimaConfiguration> = 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 },
});
Expand Down Expand Up @@ -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 });
}
Expand Down
1 change: 1 addition & 0 deletions src/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const adjustNameWithDir: Record<string, string> = {
helm: path.join('bin', 'helm'),
kim: path.join('bin', 'kim'),
kubectl: path.join('bin', 'kubectl'),
nerdctl: path.join('bin', 'nerdctl'),
};

function fixedSourceName(name: string) {
Expand Down

0 comments on commit a53379a

Please sign in to comment.