Skip to content

Commit

Permalink
Unix integration: Symlink docker CLI plugins to bin
Browse files Browse the repository at this point in the history
To make it easier for `rdctl factory-reset`, point the docker CLI plugins
to the integrations directory (`~/.rd/bin/`), and in from there into the
executables we ship, rather than pointing at the executables directly.

Signed-off-by: Mark Yen <mark.yen@suse.com>
  • Loading branch information
mook-as committed Sep 11, 2024
1 parent 6693cfc commit 33750b5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describeUnix('UnixIntegrationManager', () => {
const pluginPath = path.join(dockerCLIPluginDest, name);
const expectedValue = path.join(dockerCLIPluginSource, name);

await expect(fs.promises.readlink(pluginPath, 'utf8')).resolves.toEqual(expectedValue);
await expect(fs.promises.readlink(pluginPath, 'utf8')).resolves.toEqual(binPath);
await expect(fs.promises.readlink(binPath, 'utf8')).resolves.toEqual(expectedValue);
}
});
Expand All @@ -90,7 +90,7 @@ describeUnix('UnixIntegrationManager', () => {
test('should update an existing docker CLI plugin that is a dangling symlink', async() => {
const existingPluginPath = path.join(dockerCLIPluginDest, 'docker-compose');
const nonExistentPath = '/somepaththatshouldnevereverexist';
const expectedTarget = path.join(dockerCLIPluginSource, 'docker-compose');
const expectedTarget = path.join(integrationDir, 'docker-compose');

await fs.promises.mkdir(dockerCLIPluginDest, { mode: 0o755 });
await fs.promises.symlink(nonExistentPath, existingPluginPath);
Expand All @@ -102,13 +102,13 @@ describeUnix('UnixIntegrationManager', () => {
expect(newTarget).toEqual(expectedTarget);
});

test('should update an existing docker CLI plugin whose target is integrations directory', async() => {
test('should update an existing docker CLI plugin whose target is resources directory', async() => {
const existingPluginPath = path.join(dockerCLIPluginDest, 'docker-compose');
const integrationsPath = path.join(integrationDir, 'docker-compose');
const expectedTarget = path.join(dockerCLIPluginSource, 'docker-compose');
const sourceDir = path.join(dockerCLIPluginSource, 'docker-compose');
const expectedTarget = path.join(integrationDir, 'docker-compose');

await fs.promises.mkdir(dockerCLIPluginDest, { mode: 0o755 });
await fs.promises.symlink(integrationsPath, existingPluginPath);
await fs.promises.symlink(sourceDir, existingPluginPath);

await integrationManager.enforce();

Expand Down
4 changes: 3 additions & 1 deletion pkg/rancher-desktop/integrations/unixIntegrationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ export default class UnixIntegrationManager implements IntegrationManager {

// create or remove the plugin links
for (const name of pluginNames) {
const sourcePath = path.join(this.dockerCLIPluginSource, name);
// We create symlinks to the integration directory instead of the file
// directly, to avoid factory reset having to deal with it.
const sourcePath = path.join(this.integrationDir, name);
const destPath = path.join(this.dockerCLIPluginDest, name);

if (!await this.weOwnDockerCliFile(destPath)) {
Expand Down

0 comments on commit 33750b5

Please sign in to comment.