Skip to content

Commit

Permalink
Merge pull request #185 from katalon-studio/master
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
quidl authored Mar 5, 2024
2 parents 6ccafb0 + cd217ba commit 062564a
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 6 deletions.
9 changes: 8 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ RUN chmod a+x ./docker/scripts/build_agent.sh
RUN ./docker/scripts/build_agent.sh

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

# Install java version 8
RUN apt-get update && \
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.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "katalon-agent",
"version": "v2.0.3",
"version": "v2.1.0",
"description": "",
"main": "cli.js",
"scripts": {
Expand Down 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
3 changes: 3 additions & 0 deletions src/core/api/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ const KS_OLD_RELEASES_URL =
const KS_RELEASES_URL =
'https://download.katalon.com/katalon-studio/releases.json';

const KRE_LATEST_OPTION_VALUE = 'latest';

module.exports = {
TESTOPS_BASE_URL,
PATHS,
Expand All @@ -51,4 +53,5 @@ module.exports = {
FILTERED_ERROR_CODE,
KS_OLD_RELEASES_URL,
KS_RELEASES_URL,
KRE_LATEST_OPTION_VALUE,
};
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',
},
);
},
};
20 changes: 17 additions & 3 deletions src/service/katalon-studio.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
/* eslint-disable no-param-reassign */
const _ = require('lodash');
const fs = require('fs');
const path = require('path');
const { filter, maxBy } = require('lodash');

const api = require('../core/api');
const defaultLogger = require('../config/logger');
const os = require('../core/os');
const { KatalonStudioDownloader } = require('./remote-downloader');
const utils = require('../core/utils');
const { KRE_LATEST_OPTION_VALUE } = require('../core/api/constants');

function find(startPath, filter, callback) {
if (!fs.existsSync(startPath)) {
Expand Down Expand Up @@ -43,9 +46,15 @@ function getKsLocation(ksVersionNumber, ksLocation) {

return api.getKSReleases().then(({ body }) => {
const osVersion = os.getVersion();
const ksVersion = body.find(
(item) => item.version === ksVersionNumber && item.os === osVersion,
);
let ksVersion;

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);
}

const userhome = os.getUserHome();
const ksLocationParentDir = path.join(userhome, '.katalon', ksVersionNumber);
Expand Down Expand Up @@ -82,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 062564a

Please sign in to comment.