Add integration path in paths and set it to ~/.local/bin on Linux

Signed-off-by: David Cassany <dcassany@suse.com>
This commit is contained in:
David Cassany
2021-10-06 21:51:07 +02:00
parent 19d9f2087b
commit 724b31e991
12 changed files with 49 additions and 23 deletions

View File

@@ -124,7 +124,7 @@ async function doFirstRun() {
return;
}
await window.openFirstRun();
if (os.platform() === 'darwin') {
if (os.platform() === 'darwin' || os.platform() === 'linux') {
await Promise.all([
linkResource('helm', true),
linkResource('kim', true), // TODO: Remove when we stop shipping kim
@@ -510,10 +510,20 @@ async function getVersion() {
* @param state -- true to symlink, false to delete
*/
async function linkResource(name: string, state: boolean): Promise<Error | null> {
const linkPath = path.join('/usr/local/bin', name);
const linkPath = path.join(paths.integration, name);
let err: Error | null = await new Promise((resolve) => {
fs.mkdir(paths.integration, { recursive: true }, resolve);
});
if (err) {
console.error(`Error creating the directory ${ paths.integration }: ${ err.message }`);
return err;
}
if (state) {
const err: Error | null = await new Promise((resolve) => {
err = await new Promise((resolve) => {
fs.symlink(resources.executable(name), linkPath, 'file', resolve);
});
@@ -523,7 +533,7 @@ async function linkResource(name: string, state: boolean): Promise<Error | null>
return err;
}
} else {
const err: Error | null = await new Promise((resolve) => {
err = await new Promise((resolve) => {
fs.unlink(linkPath, resolve);
});

View File

@@ -53,6 +53,7 @@ flatpak:
- --filesystem=xdg-data/rancher-desktop:create
- --filesystem=~/.kube:create
- --filesystem=~/.kuberlr:create
- --filesystem=~/.local/bin:create
- --device=kvm
- --device=dri
- --share=ipc

View File

@@ -22,6 +22,7 @@ finish-args:
- --filesystem=xdg-data/rancher-desktop:create
- --filesystem=~/.kube:create
- --filesystem=~/.kuberlr:create
- --filesystem=~/.local/bin:create
- --talk-name=org.freedesktop.Notifications
- --own-name=org.kde.*
modules:

View File

@@ -4515,7 +4515,7 @@ troubleshooting:
integrations:
darwin:
title: Supporting Utilities
description: Create symbolic links to tools in /usr/local/bin
description: Create symbolic links to tools in
windows:
title: WSL Integration
description: "Expose Rancher Desktop's Kubernetes configuration to Windows Subsystem for Linux (WSL) distros"

View File

@@ -26,6 +26,7 @@ import Component from 'vue-class-component';
import Banner from '@/components/Banner.vue';
import Card from '@/components/Card.vue';
import Checkbox from '@/components/form/Checkbox.vue';
import paths from '@/utils/paths';
const IntegrationProps = Vue.extend({
props: {
@@ -59,7 +60,7 @@ class Integration extends IntegrationProps {
* asynchronously, to prevent the user from retrying to toggle too quickly.
*/
protected busy: Record<string, boolean> = {};
protected GlobalFailureIntegrationName = '/usr/local/bin';
protected GlobalFailureIntegrationName = paths.integration;
get globalError() {
return this.integrations[this.GlobalFailureIntegrationName];

View File

@@ -2,6 +2,7 @@ import path from 'path';
import fs from 'fs';
import Logging from '@/utils/logging';
import paths from '@/utils/paths';
import resources from '@/resources';
import PathConflictManager from '@/main/pathConflictManager';
import * as window from '@/window';
@@ -9,7 +10,7 @@ import * as window from '@/window';
// TODO: Remove 'kim' when we stop shipping kim
const INTEGRATIONS = ['helm', 'kim', 'kubectl', 'nerdctl'];
const console = Logging.background;
const PUBLIC_LINK_DIR = '/usr/local/bin';
const PUBLIC_LINK_DIR = paths.integration;
/*
* There are probably going to be only two kinds of integrations: WSL for Windows,

View File

@@ -41,12 +41,7 @@ export default {
},
data() {
// Linux integration are not yet available
if (os.platform() === 'linux') {
return { routes: ['/General', '/K8s', '/Images', '/Troubleshooting'] };
} else {
return { routes: ['/General', '/K8s', '/Integrations', '/Images', '/Troubleshooting'] };
}
return { routes: ['/General', '/K8s', '/Integrations', '/Images', '/Troubleshooting'] };
},
head() {
@@ -68,12 +63,7 @@ export default {
mounted() {
ipcRenderer.invoke('k8s-supports-port-forwarding').then((supported) => {
if (supported) {
// Linux integrations are not yet available
if (os.platform() === 'linux') {
this.$data.routes = ['/General', '/K8s', '/PortForwarding', '/Images', '/Troubleshooting'];
} else {
this.$data.routes = ['/General', '/K8s', '/Integrations', '/PortForwarding', '/Images', '/Troubleshooting'];
}
this.$data.routes = ['/General', '/K8s', '/Integrations', '/PortForwarding', '/Images', '/Troubleshooting'];
}
});
},

View File

@@ -5,6 +5,7 @@ import timers from 'timers';
import * as window from '@/window';
import pathConflict from '@/utils/pathConflict';
import Logging from '@/utils/logging';
import paths from '@/utils/paths';
const console = Logging.background;
const DebounceInterval = 500; // msec
@@ -40,7 +41,7 @@ export default class PathConflictManager {
let results: Array<string> = [];
try {
results = this.pathConflicts[binaryName] = await pathConflict('/usr/local/bin', binaryName);
results = this.pathConflicts[binaryName] = await pathConflict(paths.integration, binaryName);
} catch (err) {
console.log(`Error gathering conflicts for file ${ binaryName }`, err);
// And leave results as an empty array, to clear the current warnings
@@ -60,7 +61,7 @@ export default class PathConflictManager {
return;
}
const currentPathDirectories = currentPathAsString.split(path.delimiter)
.filter(dir => path.resolve(dir) !== '/usr/local/bin');
.filter(dir => path.resolve(dir) !== paths.integration);
const namesOfInterest = ['helm', 'kim', 'kubectl', 'nerdctl'];
for (const dirName of currentPathDirectories) {

View File

@@ -25,6 +25,7 @@ class DarwinObsoletePaths implements Paths {
cache = path.join(os.homedir(), 'Library', 'Caches', APP_NAME);
lima = path.join(os.homedir(), 'Library', 'State', APP_NAME, 'lima');
hyperkit = path.join(os.homedir(), 'Library', 'State', APP_NAME, 'driver');
integration = '/usr/local/bin';
get wslDistro(): string {
throw new Error('wslDistro not available for darwin');
}
@@ -67,6 +68,10 @@ class Win32ObsoletePaths implements Paths {
get hyperkit(): string {
throw new Error('hyperkit not available for win32');
}
get integration(): string {
throw new Error('integration path not available for win32');
}
}
/**
* Remove the given directory if it is empty, and also any parent directories

View File

@@ -7,6 +7,7 @@ import os from 'os';
import { ipcRenderer } from 'electron';
import Vue from 'vue';
import Integration from '@/components/Integration.vue';
import paths from '@/utils/paths';
declare module 'vue/types/vue' {
interface t {
@@ -30,7 +31,7 @@ export default Vue.extend({
},
computed: {
hasIntegration() {
return /^win|^darwin$/.test(os.platform());
return /^win|^darwin|^linux$/.test(os.platform());
},
integrationTitle(): string {
if (os.platform() !== 'win32') {
@@ -41,7 +42,7 @@ export default Vue.extend({
},
integrationDescription(): string {
if (os.platform() !== 'win32') {
return this.t('integrations.darwin.description');
return `${ this.t('integrations.darwin.description') } ${ paths.integration }`;
}
return this.t('integrations.windows.description', { }, true);

View File

@@ -37,6 +37,10 @@ describe('paths', () => {
win32: Error(),
darwin: '%HOME%/Library/State/rancher-desktop/driver/',
},
integration: {
win32: Error(),
darwin: '/usr/local/bin',
},
};
const table = Object.entries(cases).flatMap(

View File

@@ -20,6 +20,8 @@ export interface Paths {
wslDistroData: string;
/** Directory holding Lima state (macOS-specific). */
lima: string;
/** Directory holding provided binary resources */
integration: string;
/** @deprecated Directory holding hyperkit state (macOS-specific) */
hyperkit: string;
}
@@ -33,6 +35,7 @@ export class DarwinPaths implements Paths {
cache = path.join(os.homedir(), 'Library', 'Caches', APP_NAME);
lima = path.join(os.homedir(), 'Library', 'Application Support', APP_NAME, 'lima');
hyperkit = path.join(os.homedir(), 'Library', 'State', APP_NAME, 'driver');
integration = '/usr/local/bin';
get wslDistro(): string {
throw new Error('wslDistro not available for darwin');
}
@@ -75,6 +78,10 @@ export class Win32Paths implements Paths {
get hyperkit(): string {
throw new Error('hyperkit not available for Windows');
}
get integration(): string {
throw new Error('integration path not available for Windows');
}
}
/**
@@ -108,6 +115,10 @@ export class LinuxPaths implements Paths {
return path.join(this.dataHome, APP_NAME, 'lima');
}
get integration(): string {
return path.join(os.homedir(), '.local', 'bin');
}
get hyperkit(): string {
throw new Error('hyperkit not available for Linux');
}