Skip to content

Commit

Permalink
Pass on extra parameters to the Docker container (#19)
Browse files Browse the repository at this point in the history
* Pass on extra parameters to the Docker container

* A better validation
  • Loading branch information
soulgalore authored Jun 17, 2024
1 parent d2d5425 commit 389cdb0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions testrunner/config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,7 @@ executable: "sitespeed.io"
# If you run sitespeed.io using Docker this is the container that is used.
# If you use the latest, make sure to docker pull the container once a day
# to get the latest version
# extraparameters will be passed omn to Docker, between docker run and the container name
docker:
container: "sitespeedio/sitespeed.io:latest"
extraparameters:
14 changes: 14 additions & 0 deletions testrunner/src/testrunners/docker-testrunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ import { queueHandler } from '../queue/queuehandler.js';

const { join } = path;

const parseDockerExtraParameters = parameters => {
if (!parameters) {
return [];
}
return parameters.split(' ').map(parameter => parameter.trim());
};

export default async function runJob(job) {
const logger = log.getLogger(`sitespeedio.dockertestrunner.${job.id}`);
const dockerLogger = log.getLogger(
Expand All @@ -21,6 +28,10 @@ export default async function runJob(job) {
const baseWorkingDirectory = os.tmpdir();
const dockerContainer = nconf.get('docker:container');

const dockerExtraParameters = parseDockerExtraParameters(
nconf.get('docker:extraparameters')
);

workingDirectory = join(baseWorkingDirectory, job.queue.name, job.id);
const insideDockerDirectory = join(
'/sitespeed.io/',
Expand All @@ -45,6 +56,7 @@ export default async function runJob(job) {
const parameters = setupDockerParameters(
job,
dockerContainer,
dockerExtraParameters,
baseWorkingDirectory,
insideDockerDirectory,
configFileName,
Expand Down Expand Up @@ -136,6 +148,7 @@ async function handleScriptingFile(job, workingDirectory) {
function setupDockerParameters(
job,
dockerContainer,
dockerExtraParameters,
baseWorkingDirectory,
insideDockerDirectory,
configFileName,
Expand All @@ -146,6 +159,7 @@ function setupDockerParameters(
'--rm',
'--volume',
`${baseWorkingDirectory}:/sitespeed.io`,
...dockerExtraParameters,
dockerContainer,
'--config',
join(insideDockerDirectory, configFileName),
Expand Down
3 changes: 2 additions & 1 deletion testrunner/src/validateconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ const loggingSchema = Joi.object({

// Docker schema
const dockerSchema = Joi.object({
container: Joi.string().optional()
container: Joi.string().optional(),
extraparameters: Joi.string().allow(null).optional()
});

// Complete config schema
Expand Down

0 comments on commit 389cdb0

Please sign in to comment.