From bdd6d8d661cad769bb182ac6b0350706996b41d2 Mon Sep 17 00:00:00 2001 From: Michael Weimann Date: Fri, 14 Apr 2023 13:02:59 +0200 Subject: [PATCH] Add support for Cypress tests with Podman (#10603) --- cypress/plugins/docker/index.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/cypress/plugins/docker/index.ts b/cypress/plugins/docker/index.ts index e3c1cad7bd2..9f755da6742 100644 --- a/cypress/plugins/docker/index.ts +++ b/cypress/plugins/docker/index.ts @@ -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 { }); } +/** + * 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 { + return new Promise((resolve, reject) => { + childProcess.execFile("docker", ["--help"], (err, stdout) => { + if (err) reject(err); + else resolve(stdout.toLowerCase().includes("podman")); + }); + }); +} + /** * @type {Cypress.PluginConfig} */