forked from podman-desktop/podman-desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add warnings and info to provider, add warn re. docker socket
### What does this PR do? * Reworks the plugin and extension API's to provide the ability to pass "up" information and warnings about the provider * Adds a warning check for Podman to see if the docker socket is actually Podman in disguise and to warn the user ### Screenshot/screencast of this PR <!-- Please include a screenshot or a screencast explaining what is doing this PR --> ### What issues does this PR fix or reference? <!-- Please include any related issue from Podman Desktop repository (or from another issue tracker). --> Fixes podman-desktop#905 Fixes podman-desktop#758 ### How to test this PR? If you have podman and docker installed: 1. `yarn watch` 2. Start Podman Desktop 3. Start Docker Desktop (Podman Desktop should now warn you that the socket is not being used by Podman) 4. Quit Docker Desktop 5. `podman machine stop && podman machine start` or restart via UI on Podman Desktop in order for `podman machine` to re-enable using the /var/run/docker.sock 6. Warning should now clear If only using podman: 1. `yarn watch` 2. Use the podman provider 3. `sudo rm -f /var/run/docker.sock` or mv 4. Warning should appear that cannot find the docker socket <!-- Please explain steps to reproduce --> Signed-off-by: Charlie Drage <[email protected]>
- Loading branch information
Showing
13 changed files
with
335 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/********************************************************************** | ||
* Copyright (C) 2022 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
***********************************************************************/ | ||
|
||
import type * as extensionApi from '@tmpwip/extension-api'; | ||
|
||
// This function gets any "essential" information with regards to the Podman plugin that the user should know. | ||
// For example: the Podman version, the Podman API version, how many containers, etc. | ||
// With this information, you can help the user to understand what is going on with the plugin. | ||
export async function getInformation(): Promise<extensionApi.ProviderInformation[]> { | ||
const infos: extensionApi.ProviderInformation[] = []; | ||
|
||
/* Test information | ||
// TO REMOVE: | ||
// Purposely pass in test information to the provider. | ||
const testInfo: extensionApi.ProviderInformation = { | ||
name: 'Status', | ||
details: 'Current status of the provider', | ||
}; | ||
infos.push(testInfo); | ||
*/ | ||
|
||
return infos; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/********************************************************************** | ||
* Copyright (C) 2022 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
***********************************************************************/ | ||
|
||
import type * as extensionApi from '@tmpwip/extension-api'; | ||
import * as os from 'node:os'; | ||
import * as http from 'node:http'; | ||
|
||
// Explanations | ||
const detailsExplanation = 'Podman is not emulating the default Docker socket path: '; | ||
const detailsNotWorking = '. Docker-specific tools may not work.'; | ||
|
||
// Default socket paths | ||
const windowsSocketPath = '//./pipe/docker_engine'; | ||
const defaultSocketPath = '/var/run/docker.sock'; | ||
|
||
// Passes any warnings with regards to the plugin to the user. | ||
export async function getWarning(): Promise<extensionApi.ProviderInformation[]> { | ||
console.log('getWarning() called'); | ||
const warnings: extensionApi.ProviderInformation[] = []; | ||
|
||
// FIRST CHECK | ||
// Check to see if the user is running the disguised Podman socket and warn if not | ||
const isPodman = await isDisguisedPodman(getSocketPath()); | ||
if (!isPodman) { | ||
let details: string; | ||
|
||
// Set the details message based on the OS | ||
switch (os.platform()) { | ||
case 'win32': | ||
details = detailsExplanation.concat(windowsSocketPath, detailsNotWorking); | ||
break; | ||
case 'darwin': | ||
// Due to how `podman-mac-helper` does not (by default) map the emulator to /var/run/docker.sock, we need to explain | ||
// that the user must go on the Podman Desktop website for more information. This is because the user must manually | ||
// map the socket to /var/run/docker.sock if not done by `podman machine` already (podman machine automatically maps the socket if Docker is not running) | ||
details = detailsExplanation.concat( | ||
defaultSocketPath, | ||
detailsNotWorking, | ||
' See troubleshooting page on podman-desktop.io for more information.', | ||
); | ||
break; | ||
default: | ||
details = detailsExplanation.concat(defaultSocketPath, detailsNotWorking); | ||
break; | ||
} | ||
|
||
// Create the message and push it to the array | ||
const podmanWarn: extensionApi.ProviderInformation = { | ||
name: 'Docker Socket Compatibility', | ||
details: details, | ||
}; | ||
warnings.push(podmanWarn); | ||
} | ||
|
||
return warnings; | ||
} | ||
|
||
// Async function that checks to see if the current Docker socket is a disguised Podman socket | ||
export async function isDisguisedPodman(socketPath: string): Promise<boolean> { | ||
const podmanPingUrl = { | ||
path: '/libpod/_ping', | ||
socketPath, | ||
}; | ||
return new Promise<boolean>(resolve => { | ||
const req = http.get(podmanPingUrl, res => { | ||
res.on('data', () => { | ||
// do nothing | ||
}); | ||
|
||
res.on('end', () => { | ||
if (res.statusCode === 200) { | ||
resolve(true); | ||
} else { | ||
resolve(false); | ||
} | ||
}); | ||
}); | ||
|
||
req.once('error', err => { | ||
console.debug('Error while pinging docker as podman', err); | ||
resolve(false); | ||
}); | ||
}); | ||
} | ||
|
||
// Function that checks whether you are running windows, mac or linux and returns back | ||
// the correct Docker socket location | ||
export function getSocketPath(): string { | ||
let socketPath: string = defaultSocketPath; | ||
if (os.platform() === 'win32') { | ||
socketPath = windowsSocketPath; | ||
} | ||
return socketPath; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.