Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Cypress tests with Podman #10603

Merged
merged 1 commit into from
Apr 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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