Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit bdd6d8d

Browse files
authored
Add support for Cypress tests with Podman (#10603)
1 parent 6b451af commit bdd6d8d

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

cypress/plugins/docker/index.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import PluginConfigOptions = Cypress.PluginConfigOptions;
2626

2727
// A cypress plugin to run docker commands
2828

29-
export function dockerRun(opts: {
29+
export async function dockerRun(opts: {
3030
image: string;
3131
containerName: string;
3232
params?: string[];
@@ -38,6 +38,11 @@ export function dockerRun(opts: {
3838
if (params?.includes("-v") && userInfo.uid >= 0) {
3939
// On *nix we run the docker container as our uid:gid otherwise cleaning it up its media_store can be difficult
4040
params.push("-u", `${userInfo.uid}:${userInfo.gid}`);
41+
42+
if (await isPodman()) {
43+
// keep the user ID if the docker command is actually podman
44+
params.push("--userns=keep-id");
45+
}
4146
}
4247

4348
const args = [
@@ -129,6 +134,19 @@ export function dockerIp(args: { containerId: string }): Promise<string> {
129134
});
130135
}
131136

137+
/**
138+
* Detects whether the docker command is actually podman.
139+
* To do this, it looks for "podman" in the output of "docker --help".
140+
*/
141+
export function isPodman(): Promise<boolean> {
142+
return new Promise<boolean>((resolve, reject) => {
143+
childProcess.execFile("docker", ["--help"], (err, stdout) => {
144+
if (err) reject(err);
145+
else resolve(stdout.toLowerCase().includes("podman"));
146+
});
147+
});
148+
}
149+
132150
/**
133151
* @type {Cypress.PluginConfig}
134152
*/

0 commit comments

Comments
 (0)