Skip to content

Commit

Permalink
Add support for Cypress tests with Podman (#10603)
Browse files Browse the repository at this point in the history
  • Loading branch information
weeman1337 committed Apr 14, 2023
1 parent 6b451af commit bdd6d8d
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion cypress/plugins/docker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand All @@ -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 = [
Expand Down Expand Up @@ -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}
*/
Expand Down

0 comments on commit bdd6d8d

Please sign in to comment.