diff --git a/uui-e2e-tests/.env.local b/uui-e2e-tests/.env.docker similarity index 100% rename from uui-e2e-tests/.env.local rename to uui-e2e-tests/.env.docker diff --git a/uui-e2e-tests/e2e.Dockerfile b/uui-e2e-tests/e2e.Dockerfile index 48d901ee29..e709dcb5d0 100644 --- a/uui-e2e-tests/e2e.Dockerfile +++ b/uui-e2e-tests/e2e.Dockerfile @@ -3,8 +3,9 @@ FROM mcr.microsoft.com/playwright:v1.42.1-jammy WORKDIR /app COPY package.json ./ -COPY tsconfig.json ./ RUN yarn -CMD [ "", "" ] +ENTRYPOINT [ "yarn" ] + +CMD [ "" ] diff --git a/uui-e2e-tests/readme.md b/uui-e2e-tests/readme.md index 31c72faaec..67fd595b87 100644 --- a/uui-e2e-tests/readme.md +++ b/uui-e2e-tests/readme.md @@ -31,7 +31,7 @@ You might need to restart computer after that. #### Option 1: Colima 1. Install Colima via CLI: ```shell - # Install "docker" because Colima needs it + # Install "docker" because Colima needs docker CLI client. Colima does not use docker to run containers. brew install docker # Install Colima itself @@ -51,7 +51,7 @@ You might need to restart computer after that. ## Usage of alternative tools not mentioned in this guide By default, if "podman" is detected, then it is used to build/run containers; otherwise "docker" is used as fallback; -To override the default behavior, you might explicitly specify any tool via ```.env.local``` file using ```UUI_DOCKER_CONTAINER_ENGINE=``` option. +To override the default behavior, you might explicitly specify any tool via ```.env.docker``` file using ```UUI_DOCKER_CONTAINER_ENGINE=``` option. Please make sure that this tool is compatible with Docker's CLI. # Running tests in local environment @@ -65,7 +65,7 @@ Please make sure that this tool is compatible with Docker's CLI. * Cons: Requires full build. Port ```5000``` might be occupied on macOS by some system utilities. * Any external UUI server * Pros: Good performance (though it depends on network speed). -2. [Optional step] Change ```.env.local``` file to set non-standard ```UUI_APP_BASE_URL``` +2. [Optional step] Change ```.env.docker``` file to set non-standard ```UUI_APP_BASE_URL``` ## NPM tasks to use Note: If the tasks are run for the very first time, it might take some time to download necessary docker images (up to 10 min, depends on network speed). diff --git a/uui-e2e-tests/scripts/cmd/cmdRunPwDocker.ts b/uui-e2e-tests/scripts/cmd/cmdRunPwDocker.ts index b9c88bbc49..e1947a2e46 100644 --- a/uui-e2e-tests/scripts/cmd/cmdRunPwDocker.ts +++ b/uui-e2e-tests/scripts/cmd/cmdRunPwDocker.ts @@ -1,22 +1,21 @@ -import { spawnProcessSync, hasCliArg, isCmdSuccessful } from '../cliUtils'; +import { spawnProcessSync, hasCliArg } from '../cliUtils'; import { - CLI_ARGS, CONTAINER_ENGINES, + CLI_ARGS, DOCKER_CONTAINER_NAME, DOCKER_FILES, - DOCKER_IMAGE_TAGS, ENV_FILES, + DOCKER_IMAGE_TAGS, YARN_TASKS, } from '../constants'; import { currentMachineIpv4 } from '../ipUtils'; -import { readEnvFile } from '../envFileUtils'; -import { Logger } from '../../src/utils/logger'; +import { getContainerEngineCmd } from '../containerEngineUtils'; -const UUI_DOCKER_CONTAINER_MGMT = getContainerMgmtTool(); +const CONTAINER_ENGINE_CMD = getContainerEngineCmd(); main(); function main() { spawnProcessSync({ - cmd: UUI_DOCKER_CONTAINER_MGMT, + cmd: CONTAINER_ENGINE_CMD, args: [ 'build', '-t', @@ -28,7 +27,7 @@ function main() { exitOnErr: true, }); spawnProcessSync({ - cmd: UUI_DOCKER_CONTAINER_MGMT, + cmd: CONTAINER_ENGINE_CMD, args: [ 'rm', DOCKER_CONTAINER_NAME, @@ -37,7 +36,7 @@ function main() { }); const updateSnapshots = hasCliArg(CLI_ARGS.PW_DOCKER_UPDATE_SNAPSHOTS); spawnProcessSync({ - cmd: UUI_DOCKER_CONTAINER_MGMT, + cmd: CONTAINER_ENGINE_CMD, args: [ 'run', '--name', @@ -55,7 +54,6 @@ function main() { '-e', `UUI_DOCKER_HOST_MACHINE_IP=${currentMachineIpv4}`, DOCKER_IMAGE_TAGS.TEST, - 'yarn', updateSnapshots ? YARN_TASKS.DOCKER_TEST_E2E_UPDATE : YARN_TASKS.DOCKER_TEST_E2E, ], exitOnErr: true, @@ -63,38 +61,17 @@ function main() { } function getVolumesMapArgs() { - const volumesMap: Record = { - './scripts': '/app/scripts', - './src': '/app/src', - './tests': '/app/tests', - './playwright.config.ts': '/app/playwright.config.ts', - './.env.ci': '/app/.env.ci', - './.env.local': '/app/.env.local', - }; - return Object.keys(volumesMap).reduce((acc, key) => { - const value = volumesMap[key]; - acc.push('-v'); - acc.push(`${key}:${value}`); + // files/folders to mount volumes + return [ + './scripts', + './src', + './tests', + './playwright.config.ts', + './.env.docker', + './tsconfig.json', + ].reduce((acc, from) => { + const to = `/app/${from.replace('./', '')}`; + acc.push('-v', `${from}:${to}`); return acc; }, []); } - -function getContainerMgmtTool(): string { - const envFile = readEnvFile(); - let cmdEffective: string = envFile.UUI_DOCKER_CONTAINER_ENGINE; - if (cmdEffective) { - Logger.info(`The "${cmdEffective}" container engine is explicitly specified in "${ENV_FILES.LOCAL}"; It will be used.`); - return cmdEffective; - } else { - const isPodmanInstalled = isCmdSuccessful({ cmd: CONTAINER_ENGINES.podman, args: ['-v'] }); - if (isPodmanInstalled) { - Logger.info(`The "${CONTAINER_ENGINES.podman}" CLI detected.`); - cmdEffective = CONTAINER_ENGINES.podman; - } else { - // fallback - cmdEffective = CONTAINER_ENGINES.docker; - } - Logger.info(`No container engine is explicitly specified in "${ENV_FILES.LOCAL}"; "${cmdEffective}" will be used.`); - } - return cmdEffective; -} diff --git a/uui-e2e-tests/scripts/constants.ts b/uui-e2e-tests/scripts/constants.ts index e2b6188005..1f8bb6b7f1 100644 --- a/uui-e2e-tests/scripts/constants.ts +++ b/uui-e2e-tests/scripts/constants.ts @@ -17,7 +17,7 @@ export const HOST_IP_PH = '{{HOST_NAME}}'; export const ENV_FILES = { CI: '.env.ci', - LOCAL: '.env.local', + DOCKER: '.env.docker', }; export const CONTAINER_ENGINES = { diff --git a/uui-e2e-tests/scripts/containerEngineUtils.ts b/uui-e2e-tests/scripts/containerEngineUtils.ts new file mode 100644 index 0000000000..ac0b04fe64 --- /dev/null +++ b/uui-e2e-tests/scripts/containerEngineUtils.ts @@ -0,0 +1,24 @@ +import { readEnvFile } from './envFileUtils'; +import { Logger } from '../src/utils/logger'; +import { CONTAINER_ENGINES, ENV_FILES } from './constants'; +import { isCmdSuccessful } from './cliUtils'; + +export function getContainerEngineCmd(): string { + const envFile = readEnvFile(); + let cmdEffective: string = envFile.UUI_DOCKER_CONTAINER_ENGINE; + if (cmdEffective) { + Logger.info(`The "${cmdEffective}" container engine is explicitly specified in "${ENV_FILES.DOCKER}"; It will be used.`); + return cmdEffective; + } else { + const isPodmanInstalled = isCmdSuccessful({ cmd: CONTAINER_ENGINES.podman, args: ['-v'] }); + if (isPodmanInstalled) { + Logger.info(`The "${CONTAINER_ENGINES.podman}" CLI detected.`); + cmdEffective = CONTAINER_ENGINES.podman; + } else { + // fallback + cmdEffective = CONTAINER_ENGINES.docker; + } + Logger.info(`No container engine is explicitly specified in "${ENV_FILES.DOCKER}"; "${cmdEffective}" will be used.`); + } + return cmdEffective; +} diff --git a/uui-e2e-tests/scripts/envFileUtils.ts b/uui-e2e-tests/scripts/envFileUtils.ts index 7df99b757a..3ace74231c 100644 --- a/uui-e2e-tests/scripts/envFileUtils.ts +++ b/uui-e2e-tests/scripts/envFileUtils.ts @@ -5,7 +5,7 @@ import { ENV_FILES, HOST_IP_PH } from './constants'; const { isCi, UUI_DOCKER_HOST_MACHINE_IP = 'localhost' } = readEnvParams(); -const envFileName = isCi ? ENV_FILES.CI : ENV_FILES.LOCAL; +const envFileName = isCi ? ENV_FILES.CI : ENV_FILES.DOCKER; type TEnvParams = { UUI_APP_BASE_URL: string, UUI_DOCKER_CONTAINER_ENGINE: string };