From 00b11b8dcee5550dd15c5a2b00a237139b4c8f00 Mon Sep 17 00:00:00 2001 From: Kim Turley Date: Wed, 2 Aug 2017 10:43:11 -0400 Subject: [PATCH 1/7] Stream api added to README and urls corrected --- builder/README.md | 4 ++++ builder/docker_run.sh | 2 +- builder/server.js | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/builder/README.md b/builder/README.md index fdd1a38..2aed938 100644 --- a/builder/README.md +++ b/builder/README.md @@ -25,4 +25,8 @@ curl -X POST \ https://builder-dot-lighthouse-ci.appspot.com/ci ``` +```bash +curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET 'https://builder-dot-lighthouse-ci.appspot.com/stream?format=json&url=https://staging.example.com' +``` + where `format` is one of `json`, `html`. diff --git a/builder/docker_run.sh b/builder/docker_run.sh index 844dc0c..c167351 100755 --- a/builder/docker_run.sh +++ b/builder/docker_run.sh @@ -1,3 +1,3 @@ #!/bin/bash -docker run -d -p 8080:8080 --cap-add=SYS_ADMIN lighthouse_ci +docker run -p 8080:8080 --cap-add=SYS_ADMIN lighthouse_ci diff --git a/builder/server.js b/builder/server.js index 77d6723..b35dccd 100644 --- a/builder/server.js +++ b/builder/server.js @@ -70,7 +70,7 @@ function runLighthouseAsEventStream(req, res, next) { }); child.on('close', statusCode => { - const serverOrigin = `https://${req.host}/`; + const serverOrigin = `http://${req.host}:${PORT}/`; res.write(`data: done ${serverOrigin + file}\n\n`); res.status(410).end(); console.log(log); From 3999ed8a2468ee90a38c0f2dee932cc04df344a1 Mon Sep 17 00:00:00 2001 From: Kim Turley Date: Wed, 2 Aug 2017 11:36:02 -0400 Subject: [PATCH 2/7] Use headless Chome as the default --- builder/README.md | 5 ++++- builder/docker_build.sh | 2 +- builder/server.js | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/builder/README.md b/builder/README.md index 2aed938..2c0a4ef 100644 --- a/builder/README.md +++ b/builder/README.md @@ -26,7 +26,10 @@ curl -X POST \ ``` ```bash -curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET 'https://builder-dot-lighthouse-ci.appspot.com/stream?format=json&url=https://staging.example.com' +curl -i \ + -H "Accept: application/json" \ + -H "Content-Type: application/json" \ + -X GET 'https://builder-dot-lighthouse-ci.appspot.com/stream?format=json&url=https://staging.example.com' ``` where `format` is one of `json`, `html`. diff --git a/builder/docker_build.sh b/builder/docker_build.sh index d9fbe7c..bf6947d 100755 --- a/builder/docker_build.sh +++ b/builder/docker_build.sh @@ -4,4 +4,4 @@ # docker build -t lighthouse_ci . --build-arg CACHEBUST=$(date +%d) # Build for non-headless Chrome version. -docker build -f Dockerfile.nonheadless -t lighthouse_ci . --build-arg CACHEBUST=$(date +%d) +docker build -f Dockerfile.headless -t lighthouse_ci . --build-arg CACHEBUST=$(date +%d) diff --git a/builder/server.js b/builder/server.js index b35dccd..84b62c1 100644 --- a/builder/server.js +++ b/builder/server.js @@ -58,7 +58,7 @@ function runLighthouseAsEventStream(req, res, next) { const file = `report.${Date.now()}.${extension}`; const fileSavePath = './reports/'; - const args = [`--output-path=${fileSavePath + file}`, `--output=${format}`, '--port=9222']; + const args = [`--output-path=${fileSavePath + file}`, `--output=${format}`, '--chrome-flags="--headless"']; const child = spawn('lighthouse', [...args, url]); let log = ''; From 869f41808c98bc5abffdb8e35beee44a33e31d1b Mon Sep 17 00:00:00 2001 From: Kim Turley Date: Wed, 2 Aug 2017 12:44:13 -0400 Subject: [PATCH 3/7] Missing reports path and headless chrome params --- builder/server.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/builder/server.js b/builder/server.js index 84b62c1..0594bb1 100644 --- a/builder/server.js +++ b/builder/server.js @@ -17,8 +17,9 @@ function runLH(url, format = 'domhtml', res, next) { const extension = format === 'domhtml' ? 'html' : format; const file = `report.${Date.now()}.${extension}`; + const fileSavePath = './reports/'; - const args = [`--output-path=${file}`, `--output=${format}`, '--port=9222']; + const args = [`--output-path=${fileSavePath + file}`, `--output=${format}`, '--port=9222', '--chrome-flags="--no-sandbox --headless"']; const child = spawn('lighthouse', [...args, url]); child.stderr.on('data', data => { @@ -58,10 +59,10 @@ function runLighthouseAsEventStream(req, res, next) { const file = `report.${Date.now()}.${extension}`; const fileSavePath = './reports/'; - const args = [`--output-path=${fileSavePath + file}`, `--output=${format}`, '--chrome-flags="--headless"']; + const args = [`--output-path=${fileSavePath + file}`, `--output=${format}`, '--port=9222', '--chrome-flags="--no-sandbox --headless"']; const child = spawn('lighthouse', [...args, url]); - let log = ''; + let log = 'lighthouse ' + args.join(' ') + ' ' + url + '\n'; child.stderr.on('data', data => { const str = data.toString(); From 8c8d33d8d259befb9f952165bd41f5caf21d8f4d Mon Sep 17 00:00:00 2001 From: Kim Turley Date: Wed, 2 Aug 2017 12:55:07 -0400 Subject: [PATCH 4/7] Set chrome debugging port --- builder/server.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builder/server.js b/builder/server.js index 0594bb1..5584e62 100644 --- a/builder/server.js +++ b/builder/server.js @@ -19,7 +19,7 @@ function runLH(url, format = 'domhtml', res, next) { const file = `report.${Date.now()}.${extension}`; const fileSavePath = './reports/'; - const args = [`--output-path=${fileSavePath + file}`, `--output=${format}`, '--port=9222', '--chrome-flags="--no-sandbox --headless"']; + const args = [`--output-path=${fileSavePath + file}`, `--output=${format}`, '--port=9222', '--chrome-flags="--remote-debugging-port=9222 --no-sandbox --headless"']; const child = spawn('lighthouse', [...args, url]); child.stderr.on('data', data => { @@ -59,7 +59,7 @@ function runLighthouseAsEventStream(req, res, next) { const file = `report.${Date.now()}.${extension}`; const fileSavePath = './reports/'; - const args = [`--output-path=${fileSavePath + file}`, `--output=${format}`, '--port=9222', '--chrome-flags="--no-sandbox --headless"']; + const args = [`--output-path=${fileSavePath + file}`, `--output=${format}`, '--port=9222', '--chrome-flags="--remote-debugging-port=9222 --no-sandbox --headless"']; const child = spawn('lighthouse', [...args, url]); let log = 'lighthouse ' + args.join(' ') + ' ' + url + '\n'; From 9eaa37179923f00b1d0f284ce229aa868f99d38e Mon Sep 17 00:00:00 2001 From: Kim Turley Date: Wed, 2 Aug 2017 13:08:06 -0400 Subject: [PATCH 5/7] Add no sandbox param to chrome --- builder/chromeuser-script.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/builder/chromeuser-script.sh b/builder/chromeuser-script.sh index 0212600..dd65a7f 100644 --- a/builder/chromeuser-script.sh +++ b/builder/chromeuser-script.sh @@ -4,4 +4,5 @@ nohup google-chrome \ --headless \ --disable-gpu \ + --no-sandbox \ --remote-debugging-port=9222 'about:blank' & From 3251ffde1c6542e830eb1a6859fc7306eaf0f246 Mon Sep 17 00:00:00 2001 From: Kim Turley Date: Wed, 2 Aug 2017 13:21:02 -0400 Subject: [PATCH 6/7] Remove unecessary params --- builder/server.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builder/server.js b/builder/server.js index 5584e62..6956c87 100644 --- a/builder/server.js +++ b/builder/server.js @@ -19,7 +19,7 @@ function runLH(url, format = 'domhtml', res, next) { const file = `report.${Date.now()}.${extension}`; const fileSavePath = './reports/'; - const args = [`--output-path=${fileSavePath + file}`, `--output=${format}`, '--port=9222', '--chrome-flags="--remote-debugging-port=9222 --no-sandbox --headless"']; + const args = [`--output-path=${fileSavePath + file}`, `--output=${format}`, '--port=9222']; const child = spawn('lighthouse', [...args, url]); child.stderr.on('data', data => { @@ -59,7 +59,7 @@ function runLighthouseAsEventStream(req, res, next) { const file = `report.${Date.now()}.${extension}`; const fileSavePath = './reports/'; - const args = [`--output-path=${fileSavePath + file}`, `--output=${format}`, '--port=9222', '--chrome-flags="--remote-debugging-port=9222 --no-sandbox --headless"']; + const args = [`--output-path=${fileSavePath + file}`, `--output=${format}`, '--port=9222']; const child = spawn('lighthouse', [...args, url]); let log = 'lighthouse ' + args.join(' ') + ' ' + url + '\n'; From 55e6fa5062091be16281ca59822bdacf633f2150 Mon Sep 17 00:00:00 2001 From: Kim Turley Date: Wed, 16 Aug 2017 10:27:05 -0400 Subject: [PATCH 7/7] Use port 8085 instead to prevent conflicts with other services --- builder/Dockerfile.headless | 4 ++-- builder/Dockerfile.nonheadless | 4 ++-- builder/docker_run.sh | 2 +- builder/server.js | 2 +- frontend/public/app.js | 2 +- frontend/server.js | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/builder/Dockerfile.headless b/builder/Dockerfile.headless index 02b20f4..dd9c409 100644 --- a/builder/Dockerfile.headless +++ b/builder/Dockerfile.headless @@ -51,8 +51,8 @@ RUN yarn install COPY server.js / RUN chmod +x /server.js -# Expose port 8080 -EXPOSE 8080 +# Expose port 8085 +EXPOSE 8085 ## PART 4: Final setup ## =================== diff --git a/builder/Dockerfile.nonheadless b/builder/Dockerfile.nonheadless index 2a0633a..a7b08cf 100644 --- a/builder/Dockerfile.nonheadless +++ b/builder/Dockerfile.nonheadless @@ -58,8 +58,8 @@ RUN yarn install COPY server.js / RUN chmod +x /server.js -# Expose port 8080 -EXPOSE 8080 +# Expose port 8085 +EXPOSE 8085 ## PART 4: Final setup ## =================== diff --git a/builder/docker_run.sh b/builder/docker_run.sh index c167351..b32821c 100755 --- a/builder/docker_run.sh +++ b/builder/docker_run.sh @@ -1,3 +1,3 @@ #!/bin/bash -docker run -p 8080:8080 --cap-add=SYS_ADMIN lighthouse_ci +docker run -it -p 8085:8085 --cap-add=SYS_ADMIN lighthouse_ci diff --git a/builder/server.js b/builder/server.js index 6956c87..94f34a7 100644 --- a/builder/server.js +++ b/builder/server.js @@ -6,7 +6,7 @@ const spawn = require('child_process').spawn; const bodyParser = require('body-parser'); const API_KEY_HEADER = 'X-API-KEY'; -const PORT = 8080; +const PORT = 8085; // Handler for CI. function runLH(url, format = 'domhtml', res, next) { diff --git a/frontend/public/app.js b/frontend/public/app.js index 34a6d5e..216c713 100644 --- a/frontend/public/app.js +++ b/frontend/public/app.js @@ -13,7 +13,7 @@ const startOver = document.querySelector('#startover'); // const params = new URLSearchParams(location.search); // let setTimeoutId_; const ENDPOINT_ORIGIN = location.hostname === 'localhost' ? - 'http://localhost:8080' : 'https://builder-dot-lighthouse-ci.appspot.com'; + 'http://localhost:8085' : 'https://builder-dot-lighthouse-ci.appspot.com'; // /** // * @param {number} score diff --git a/frontend/server.js b/frontend/server.js index c185938..be5a925 100644 --- a/frontend/server.js +++ b/frontend/server.js @@ -243,7 +243,7 @@ app.post('/run_on_chrome', async (req, res) => { // }); // }); -const PORT = process.env.PORT || 8080; +const PORT = process.env.PORT || 8085; app.listen(PORT, () => { console.log(`App listening on port ${PORT}`); console.log('Press Ctrl+C to quit.');