Skip to content

Commit

Permalink
Merge pull request #2123 from epam/feat/improve_e2e_image
Browse files Browse the repository at this point in the history
Improve e2e.Dockerfile
  • Loading branch information
siarheiyelin authored Apr 5, 2024
2 parents d1bbe24 + b4d2a63 commit 0f6bda9
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 49 deletions.
File renamed without changes.
5 changes: 3 additions & 2 deletions uui-e2e-tests/e2e.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ FROM mcr.microsoft.com/playwright:v1.42.1-jammy
WORKDIR /app

COPY package.json ./
COPY tsconfig.json ./

RUN yarn

CMD [ "<param-1>", "<param-2>" ]
ENTRYPOINT [ "yarn" ]

CMD [ "<param>" ]
6 changes: 3 additions & 3 deletions uui-e2e-tests/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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=<cmd>``` option.
To override the default behavior, you might explicitly specify any tool via ```.env.docker``` file using ```UUI_DOCKER_CONTAINER_ENGINE=<cmd>``` option.
Please make sure that this tool is compatible with Docker's CLI.
# Running tests in local environment
Expand All @@ -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).
Expand Down
61 changes: 19 additions & 42 deletions uui-e2e-tests/scripts/cmd/cmdRunPwDocker.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -28,7 +27,7 @@ function main() {
exitOnErr: true,
});
spawnProcessSync({
cmd: UUI_DOCKER_CONTAINER_MGMT,
cmd: CONTAINER_ENGINE_CMD,
args: [
'rm',
DOCKER_CONTAINER_NAME,
Expand All @@ -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',
Expand All @@ -55,46 +54,24 @@ 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,
});
}

function getVolumesMapArgs() {
const volumesMap: Record<string, string> = {
'./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<string[]>((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<string[]>((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;
}
2 changes: 1 addition & 1 deletion uui-e2e-tests/scripts/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
24 changes: 24 additions & 0 deletions uui-e2e-tests/scripts/containerEngineUtils.ts
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 1 addition & 1 deletion uui-e2e-tests/scripts/envFileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

Expand Down

0 comments on commit 0f6bda9

Please sign in to comment.