Add support for Cypress tests with Podman (#10603)

pull/28217/head
Michael Weimann 2023-04-14 13:02:59 +02:00 committed by GitHub
parent 6b451afc50
commit bdd6d8d661
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 1 deletions

View File

@ -26,7 +26,7 @@ import PluginConfigOptions = Cypress.PluginConfigOptions;
// A cypress plugin to run docker commands
export function dockerRun(opts: {
export async function dockerRun(opts: {
image: string;
containerName: string;
params?: string[];
@ -38,6 +38,11 @@ export function dockerRun(opts: {
if (params?.includes("-v") && userInfo.uid >= 0) {
// On *nix we run the docker container as our uid:gid otherwise cleaning it up its media_store can be difficult
params.push("-u", `${userInfo.uid}:${userInfo.gid}`);
if (await isPodman()) {
// keep the user ID if the docker command is actually podman
params.push("--userns=keep-id");
}
}
const args = [
@ -129,6 +134,19 @@ export function dockerIp(args: { containerId: string }): Promise<string> {
});
}
/**
* Detects whether the docker command is actually podman.
* To do this, it looks for "podman" in the output of "docker --help".
*/
export function isPodman(): Promise<boolean> {
return new Promise<boolean>((resolve, reject) => {
childProcess.execFile("docker", ["--help"], (err, stdout) => {
if (err) reject(err);
else resolve(stdout.toLowerCase().includes("podman"));
});
});
}
/**
* @type {Cypress.PluginConfig}
*/