Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it possible configure sitespeed.io in the default yaml file. #92

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion server/config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,14 @@ admin:
# you have on your Redis/KeyDb instance you can tune this
queue:
removeOnComplete: 50
removeOnFail: 50
removeOnFail: 50

sitespeed.io:
s3:
endpoint: "http://127.0.0.1:9000"
bucketname: "sitespeedio"
key: "sitespeedio"
secret: "tracksofmytears"
region: "motown"

resultBaseURL: "http://127.0.0.1:9000/sitespeedio"
10 changes: 0 additions & 10 deletions server/config/sitespeed.json

This file was deleted.

1 change: 1 addition & 0 deletions server/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"error.validation.missinglocation": "Missing location",
"error.validation.missingtesttype": "Missing testType",
"error.validation.nomatchingtestwithid": "There are no test with id %s",
"error.missingresultbaseurl":"Missing resultBaseURL setup for sitespeeed.io. You need to fix that in your configuration.",
"error.testfailed": "The test failed to run",
"error.parsingscript": "Could not parse the script",
"error.urlnotvalid": "The URL %s is not a valid URL",
Expand Down
26 changes: 24 additions & 2 deletions server/src/routes/html/result.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import nconf from 'nconf';
import log from 'intel';

import { Router } from 'express';
import { getConfigByTestId } from '../../configs.js';
Expand All @@ -8,6 +9,7 @@ import { getText } from '../../util/text.js';
import { getTest } from '../../database/index.js';

export const result = Router();
const logger = log.getLogger('sitespeedio.server');

result.get('/:id', async function (request, response) {
const id = request.params.id;
Expand All @@ -17,7 +19,17 @@ result.get('/:id', async function (request, response) {
if (job) {
const status = await job.getState();
if (status === 'completed') {
return response.redirect(job.returnvalue.pageSummaryUrl);
if (job.returnvalue.pageSummaryUrl) {
return response.redirect(job.returnvalue.pageSummaryUrl);
} else {
logger.error('Missing resultBaseURL setup for sitespeeed.io');
return response.render('error', {
id: id,
nconf,
message: getText('error.missingresultbaseurl'),
getText
});
}
} else if (status === 'failed') {
const { logs } = await workQueue.getJobLogs(id);
return response.render('error', {
Expand Down Expand Up @@ -75,7 +87,17 @@ result.get('/:id', async function (request, response) {
getText
});
} else if (testResult.status === 'completed') {
return response.redirect(testResult.result_url);
if (testResult.result_url) {
return response.redirect(testResult.result_url);
} else {
logger.error('Missing resultBaseURL setup for sitespeeed.io');
return response.render('error', {
id: id,
nconf,
message: getText('error.missingresultbaseurl'),
getText
});
}
} else if (testResult.status === 'failed') {
return response.render('error', {
status: testResult,
Expand Down
8 changes: 2 additions & 6 deletions server/src/util/add-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
getDeviceQueue
} from '../queuehandler.js';
import { setConfigById } from '../configs.js';
import { getBaseFilePath } from './fileutil.js';

import { updateStatus } from '../database/index.js';

Expand All @@ -30,12 +29,9 @@ async function getDefaultSitespeedConfiguration() {
const result = await readFile(
path.resolve(nconf.get('defaultSitespeedioConfigFile'))
);
log.info('Using configiguration from defaultSitespeedioConfigFile');
return JSON.parse(result.toString());
}
const result = await readFile(
path.resolve(getBaseFilePath('./config/sitespeed.json'))
);
return JSON.parse(result.toString());
} else return nconf.get('sitespeed.io') || {};
}

const uniqueNamesConfig = {
Expand Down
4 changes: 2 additions & 2 deletions testrunner/npm-shrinkwrap.json

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

1 change: 1 addition & 0 deletions testrunner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"nconf": "0.12.1",
"execa": "9.4.0",
"lodash.get": "4.4.2",
"lodash.merge": "4.6.2",
"intel": "1.2.0",
"joi": "17.13.3",
"js-yaml": "4.1.0"
Expand Down
12 changes: 8 additions & 4 deletions testrunner/src/testrunners/docker-testrunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import os from 'node:os';
import { execa } from 'execa';
import log from 'intel';
import nconf from 'nconf';
import merge from 'lodash.merge';

import { queueHandler } from '../queue/queuehandler.js';

Expand Down Expand Up @@ -47,24 +48,27 @@ export default async function runJob(job) {
job.data.config.extends = nconf.get('sitespeedioConfigFile');
}

const testrunnerConfig = nconf.get('sitespeed.io') || {};
const config = merge({}, testrunnerConfig, job.data.config);

// If we use baseline setup the directory by default
if (
(job.data.extras && job.data.extras.includes('--compare.')) ||
job.data.config.compare
config.compare
) {
// This is inside the container and we always use /baseline
if (job.data.config.compare) {
job.data.config.compare.baselinePath = '/baseline';
config.compare.baselinePath = '/baseline';
} else {
job.data.config.compare = {
config.compare = {
baselinePath: '/baseline'
};
}
}

await writeFile(
join(workingDirectory, configFileName),
JSON.stringify(job.data.config)
JSON.stringify(config)
);

const parameters = setupDockerParameters(
Expand Down
6 changes: 5 additions & 1 deletion testrunner/src/testrunners/testrunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { execa } from 'execa';
import log from 'intel';
import nconf from 'nconf';
import get from 'lodash.get';
import merge from 'lodash.merge';

import { queueHandler } from '../queue/queuehandler.js';
import { getBaseFilePath } from '../util.js';
Expand Down Expand Up @@ -117,7 +118,10 @@ function prepareSitespeedConfig(job) {
nconf.get('sitespeedioConfigFile') === undefined
? getBaseFilePath('./config/sitespeedDefault.json')
: path.resolve(nconf.get('sitespeedioConfigFile'));
return jobConfig;

const testrunnerConfig = nconf.get('sitespeed.io') || {};
const config = merge({}, testrunnerConfig, jobConfig);
return config;
}

async function runTest(job, workingDirectory, configFileName, logger) {
Expand Down
3 changes: 2 additions & 1 deletion testrunner/src/validateconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ const configSchema = Joi.object({
workingDirectory: Joi.string().optional(),
executable: Joi.string().required(),
docker: dockerSchema.required(),
queue: queueSchema.optional()
queue: queueSchema.optional(),
sitespeedio: Joi.object().optional().unknown(true)
});

export function validate(config) {
Expand Down