Skip to content

Commit

Permalink
Merge pull request #180 from katalon-studio/TES-5830
Browse files Browse the repository at this point in the history
[TES-5830] Update and publish docker agent
  • Loading branch information
quidl authored Feb 21, 2024
2 parents 28103e8 + 96d9b93 commit cd217ba
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ RUN chmod a+x ./docker/scripts/build_agent.sh
RUN ./docker/scripts/build_agent.sh

# Build docker image
# Install and inherit java version 17 from katalonstudio/katalon:9.2.0
FROM katalonstudio/katalon:9.2.0

Check failure on line 14 in Dockerfile

View check run for this annotation

Wiz Cloud Security / Wiz IaC Scanner

Missing User Instruction

Rule ID: c67d9fc8-4b03-4de0-a4a2-53ac67eddf6a Severity: High Resource: FROM={{katalonstudio/katalon:9.2.0}} File Type: Dockerfile Expected: The 'Dockerfile' should contain the 'USER' instruction Found: The 'Dockerfile' does not contain any 'USER' instruction A user should be specified in the dockerfile, otherwise the image will run as root

Check notice on line 14 in Dockerfile

View check run for this annotation

Wiz Cloud Security / Wiz IaC Scanner

Healthcheck Instruction Missing

Rule ID: 940e61e0-64c3-41c9-887d-e97ce8aca1ff Severity: Low Resource: FROM={{katalonstudio/katalon:9.2.0}} File Type: Dockerfile Expected: Dockerfile should contain instruction 'HEALTHCHECK' Found: Dockerfile doesn't contain instruction 'HEALTHCHECK' Ensure that HEALTHCHECK is being used. The HEALTHCHECK instruction tells Docker how to test a container to check that it is still working

# Install java version 8
RUN apt-get update && \

Check warning on line 17 in Dockerfile

View check run for this annotation

Wiz Cloud Security / Wiz IaC Scanner

Apt Get Install Pin Version Not Defined

Rule ID: 6d31143c-85fb-44a4-8327-9604d00550f8 Severity: Medium Resource: FROM={{katalonstudio/katalon:9.2.0}}.RUN={{apt-get update && apt-get -y install openjdk-8-jdk --no-install-recommends && apt-get clean}} File Type: Dockerfile Expected: Package 'openjdk-8-jdk' has version defined Found: Package 'openjdk-8-jdk' does not have version defined When installing a package, its pin version should be defined
apt-get -y install openjdk-8-jdk --no-install-recommends && \
apt-get clean

# Agent arguement
ARG AGENT_VERSION

Expand Down Expand Up @@ -45,6 +51,7 @@ ENV X11_DISPLAY=''
ENV KEEP_FILES=''
ENV NO_KEEP_FILES=''
ENV AUTO_UPGRADE_ENVIRONMENT=false
ENV IS_DOCKER_AGENT=true

# PATH Environment
ENV PATH "$GRADLE_BIN:$PATH:$KATALON_AGENT_DIR"
Expand Down
7 changes: 6 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"axios": "^0.27.2",
"commander": "^7.0.0",
"decompress": "^4.2.1",
"compare-versions": "^6.1.0",
"find": "^0.3.0",
"fs-extra": "^9.1.0",
"glob": "^7.2.3",
Expand Down
36 changes: 36 additions & 0 deletions src/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ const moment = require('moment');
const path = require('path');
const tmp = require('tmp');
const fs = require('fs');
const childProcess = require('child_process');
const { compare } = require('compare-versions');
const { KRE_LATEST_OPTION_VALUE } = require('./api/constants');

const packageJson = require('../../package.json');

module.exports = {
Expand Down Expand Up @@ -97,4 +101,36 @@ module.exports = {
});
return arStr.join(' ');
},

runCommand(command, args, options = {}) {
const result = childProcess.spawnSync(command, args, options);
if (result.status !== 0) {
throw new Error(result.stderr.toString());
}
return result;
},

switchJavaVersion(ksVersionNumber) {
let javaPath;
const java17Path = '/usr/lib/jvm/java-17-openjdk-amd64/bin/java';
const java8Path = '/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java';

if (ksVersionNumber === KRE_LATEST_OPTION_VALUE || compare(ksVersionNumber, '9.0.0', '>=')) {
javaPath = java17Path;
} else {
javaPath = java8Path;
}

this.runCommand(
'update-alternatives',
[
'--set',
'java',
javaPath,
],
{
stdio: 'inherit',
},
);
},
};
7 changes: 7 additions & 0 deletions src/service/katalon-studio.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-param-reassign */
const _ = require('lodash');
const fs = require('fs');
const path = require('path');
Expand Down Expand Up @@ -50,6 +51,7 @@ function getKsLocation(ksVersionNumber, ksLocation) {
if (ksVersionNumber === KRE_LATEST_OPTION_VALUE) {
const kreOsVersions = filter(body, ({ os }) => os === osVersion);
ksVersion = maxBy(kreOsVersions, 'version');
ksVersionNumber = ksVersion.version;
} else {
ksVersion = body.find((item) => item.version === ksVersionNumber && item.os === osVersion);
}
Expand Down Expand Up @@ -89,6 +91,11 @@ module.exports = {
return getKsLocation(ksVersionNumber, ksLocation).then(({ ksLocationParentDir }) => {
logger.info(`Katalon Folder: ${ksLocationParentDir}`);

if (process.env.IS_DOCKER_AGENT) {
logger.info(`Check and switch java version for Docker mode to compitable KRE version: ${ksVersionNumber}`);
utils.switchJavaVersion(ksVersionNumber);
}

let ksExecutable =
find(ksLocationParentDir, /katalonc$|katalonc\.exe$/) ||
find(ksLocationParentDir, /katalon$|katalon\.exe$/);
Expand Down

0 comments on commit cd217ba

Please sign in to comment.