mirror of
https://github.com/rancher-sandbox/rancher-desktop.git
synced 2021-10-13 00:04:06 +03:00
Manage an instance of docker as a symlink to nerdctl
Signed-off-by: Eric Promislow <epromislow@suse.com>
This commit is contained in:
@@ -135,6 +135,8 @@ async function doFirstRun() {
|
||||
linkResource('helm', true),
|
||||
linkResource('kim', true),
|
||||
linkResource('kubectl', true),
|
||||
linkResource('nerdctl', true),
|
||||
linkResource('docker', true),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,6 +136,15 @@ export default async function main(platform) {
|
||||
}
|
||||
await download(kimURL, kimPath, { expectedChecksum: kimSHA[0].split(/\s+/, 1)[0] });
|
||||
|
||||
if (kubePlatform === 'darwin') {
|
||||
// Symlink nerdctl to docker
|
||||
try {
|
||||
await fs.promises.symlink(path.join(binDir, exeName('nerdctl')), path.join(binDir, exeName('docker')), 'file');
|
||||
} catch (err) {
|
||||
console.log(`Failed to symlink nerdctl to docker in ${ binDir }`, err);
|
||||
}
|
||||
}
|
||||
|
||||
// Download Trivy
|
||||
// Always run this in the VM, so download the *LINUX* version into binDir
|
||||
// and move it over to the wsl/lima partition at runtime.
|
||||
|
||||
@@ -12,3 +12,6 @@ set -o errexit -o nounset
|
||||
mkdir -p "/mnt/wsl/rancher-desktop/bin/"
|
||||
cp "${1}" "/mnt/wsl/rancher-desktop/bin/nerdctl"
|
||||
chmod u+s "/mnt/wsl/rancher-desktop/bin/nerdctl"
|
||||
if [ ! -f "/mnt/wsl/rancher-desktop/bin/docker" ] ; then
|
||||
ln -s "/mnt/wsl/rancher-desktop/bin/nerdctl" "/mnt/wsl/rancher-desktop/bin/docker"
|
||||
fi
|
||||
|
||||
@@ -871,7 +871,7 @@ export default class LimaBackend extends events.EventEmitter implements K8s.Kube
|
||||
|
||||
if (state) {
|
||||
try {
|
||||
await fs.promises.symlink(desiredPath, linkPath, 'file');
|
||||
await fs.promises.symlink(desiredPath, linkPath);
|
||||
} catch (err) {
|
||||
const message = `Error creating symlink for ${ linkPath }:`;
|
||||
|
||||
@@ -890,5 +890,35 @@ export default class LimaBackend extends events.EventEmitter implements K8s.Kube
|
||||
return `${ message } ${ err.message }`;
|
||||
}
|
||||
}
|
||||
if (path.basename(linkPath) === 'nerdctl') {
|
||||
await this.manageDockerSymlink(path.dirname(linkPath), state);
|
||||
}
|
||||
}
|
||||
|
||||
async manageDockerSymlink(targetDir: string, state: boolean): Promise<void> {
|
||||
const desiredPath = resources.executable(path.basename('docker'));
|
||||
const linkPath = path.join(targetDir, 'docker');
|
||||
|
||||
if (state) {
|
||||
try {
|
||||
await fs.promises.symlink(desiredPath, linkPath);
|
||||
} catch (err) {
|
||||
console.log(`Failed to create symlink from ${ desiredPath } to ${ linkPath }:`, err);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
const actualSourcePath = await fs.promises.readlink(linkPath);
|
||||
|
||||
if (actualSourcePath === desiredPath) {
|
||||
try {
|
||||
await fs.promises.unlink(linkPath);
|
||||
} catch (err) {
|
||||
console.log(`Failed to remove link from ${ desiredPath } to ${ linkPath }:`, err);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
// Ignore other cases: no docker in targetDir, or not a symlink
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import { app } from 'electron';
|
||||
import memoize from 'lodash/memoize';
|
||||
|
||||
const adjustNameWithDir: Record<string, string> = {
|
||||
docker: path.join('bin', 'docker'),
|
||||
helm: path.join('bin', 'helm'),
|
||||
kim: path.join('bin', 'kim'),
|
||||
kubectl: path.join('bin', 'kubectl'),
|
||||
|
||||
Reference in New Issue
Block a user