Skip to content

Commit

Permalink
Docker test (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
soulgalore authored May 25, 2024
1 parent 511193d commit 664b603
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 6 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Test running tests using Docker
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
- uses: actions/checkout@v4
- name: Install Chrome
run: |
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
sudo apt-get update
sudo apt-get --only-upgrade install google-chrome-stable
google-chrome --version
- name: Start dependencies
run: docker-compose -f docker-compose.yml up -d
- name: Start the server
run: |
npm install --prefix server
node server/app.js > server.log 2>&1 &
- name: Start the testrunner
run: |
npm install --prefix testrunner
node testrunner/app.js --config test/config/dockertestrunner.yaml > testrunner.log 2>&1 &
- name: Show versions
run: |
docker --version
- name: Run a test
run: |
git clone https://github.com/sitespeedio/sitespeed.io.git
cd sitespeed.io
npm install
bin/sitespeed.js https://www.wikipedia.org -n 1 --api.hostname 127.0.0.1 --api.location docker --headless --api.json
- name: Display Server log
if: failure() || success()
run: cat server.log
- name: Display testrunner log
if: failure() || success()
run: cat testrunner.log
39 changes: 39 additions & 0 deletions test/config/dockertestrunner.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# The location information is passed on the the server
location:
# The name of this location
name: "docker"
# The type of tests that you can run
setup:
- name: "Desktop Browsers"
type: "desktop"
browsers: ["chrome", "firefox", "edge"]
connectivity: ["native", "3g", "4g", "cable"]
useDocker: true

# Where to connect to the message broker that is a Redis like thing
redis:
port: null
host: null
password: jgsay7f2fgfgda6acCa7g()jaba51!

# Verbose log level or not
logging:
verbose: true

# The default sitespeed.io configuration file used by the sitespeed.io instance
# It will be merged by the server sitespeed.io config and what you add in the
# cli or gui
# sitespeedioConfigFile:

# The working directory for the testrunner, where it temporary will put it files
# By default it used the os.tmpdir
# workingDirectory: "."

# The sitespeed.io executable. The default is a globally installed sitespeed.io
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
docker:
container: "sitespeedio/sitespeed.io-autobuild:main"
16 changes: 10 additions & 6 deletions testrunner/src/testrunners/docker-testrunner.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { writeFile, readFile, mkdir, rm } from 'node:fs/promises';
import path from 'node:path';
// import os from 'node:os';

import { execa } from 'execa';
import log from 'intel';
Expand All @@ -10,17 +11,18 @@ import { queueHandler } from '../queue/queuehandler.js';
const { join } = path;

export default async function runJob(job) {
const baseWorkingDirectory = nconf.get('workingDirectory');
const dockerContainer = nconf.get('docker:container');

const logger = log.getLogger(`sitespeedio.dockertestrunner.${job.id}`);
const dockerLogger = log.getLogger(
`sitespeedio.dockertestrunner.process.${job.id}`
);
const workingDirectory = join(baseWorkingDirectory, job.queue.name, job.id);

let workingDirectory;
try {
logger.info('Start with job');
const baseWorkingDirectory = './'; // nconf.get('workingDirectory') || os.tmpdir();
const dockerContainer = nconf.get('docker:container');

workingDirectory = join(baseWorkingDirectory, job.queue.name, job.id);

await mkdir(workingDirectory, { recursive: true });
const configFileName = `${job.queue.name}-${job.id}-config.json`;
const resultFileName = `${job.queue.name}-${job.id}-result.json`;
Expand Down Expand Up @@ -104,7 +106,9 @@ export default async function runJob(job) {
} catch (error) {
logger.error('Failed to execute job: %s', error.message, job.data.url);
job.log('Job failed:' + error.message);
await cleanupWorkingDirectory(workingDirectory, logger);
if (workingDirectory) {
await cleanupWorkingDirectory(workingDirectory, logger);
}
throw error;
}
}
Expand Down

0 comments on commit 664b603

Please sign in to comment.