Skip to content
Snippets Groups Projects
Commit d676d0a8 authored by nimrod's avatar nimrod
Browse files

Added Lighthouse and Sitespeed.io tests (Fabric tasks).

parent a9c3cc1a
Branches
No related tags found
No related merge requests found
...@@ -6,6 +6,9 @@ ...@@ -6,6 +6,9 @@
- Python 3.6 - Python 3.6
- [Pipenv](https://pipenv.org) - [Pipenv](https://pipenv.org)
- [Docker](https://www.docker.com/) (Only needed for running the lighthouse and
sitespeed tests)
- [direnv](http://direnv.net/) (Just for ease of use)
## Usage ## Usage
...@@ -17,10 +20,12 @@ Available commands: ...@@ -17,10 +20,12 @@ Available commands:
build Build local version of site build Build local version of site
clean Remove generated files clean Remove generated files
dev Auto-regenerate files and serve at http://localhost:8080/ dev Auto-regenerate files and serve at http://localhost:8080/
lighthouse Run Chrome's Lighthouse report against the local dev server
preview Build production version of site preview Build production version of site
publish Publish to production via rsync publish Publish to production via rsync
regenerate Automatically regenerate site upon file modification regenerate Automatically regenerate site upon file modification
serve Serve site at http://localhost:8080/ serve Serve site at http://localhost:8080/
sitespeed Run sitespeed test against the local dev server
``` ```
......
from fabric.api import lcd, env, local, hosts from fabric.api import lcd, env, local, hosts, warn_only
import fabric.contrib.project as project import fabric.contrib.project as project
import multiprocessing import multiprocessing
import os
env.use_ssh_config = True
# Local path configuration (can be absolute or relative to fabfile) # Local path configuration (can be absolute or relative to fabfile)
env.deploy_path = 'output' env.deploy_path = 'output'
DEPLOY_PATH = env.deploy_path DEPLOY_PATH = env.deploy_path
...@@ -10,10 +12,12 @@ DEPLOY_PATH = env.deploy_path ...@@ -10,10 +12,12 @@ DEPLOY_PATH = env.deploy_path
production = 'www.shore.co.il' production = 'www.shore.co.il'
dest_path = '/var/www/htdocs/www.shore.co.il/blog/' dest_path = '/var/www/htdocs/www.shore.co.il/blog/'
UID = os.getuid()
def clean(): def clean():
"""Remove generated files""" """Remove generated files"""
local(f'rm -r __pycache__/ {DEPLOY_PATH}/*') local(f'rm -rf __pycache__/ {DEPLOY_PATH}/* sitespeed-result/ lighthouse-result/')
def build(): def build():
...@@ -34,9 +38,11 @@ def serve(): ...@@ -34,9 +38,11 @@ def serve():
def dev(): def dev():
"""Auto-regenerate files and serve at http://localhost:8080/""" """Auto-regenerate files and serve at http://localhost:8080/"""
server_process = multiprocessing.Process(target=serve) server_process = multiprocessing.Process(target=serve, daemon=True)
server_process.start() server_process.start()
regenerate() regenerate()
server_process.terminate()
server_process.join(timeout=3)
def preview(): def preview():
...@@ -55,3 +61,28 @@ def publish(): ...@@ -55,3 +61,28 @@ def publish():
delete=True, delete=True,
extra_opts='-c', extra_opts='-c',
) )
def sitespeed():
"""Run sitespeed test against the local dev server"""
build()
with warn_only():
local('docker run --rm --privileged --net=host gliderlabs/hostlocal')
server_process = multiprocessing.Process(target=serve, daemon=True)
server_process.start()
local(f'docker run --rm --shm-size=1g -u {UID} -v "$PWD:/sitespeed.io" sitespeedio/sitespeed.io http://169.254.255.254:8080/')
server_process.terminate()
server_process.join(timeout=3)
def lighthouse():
"""Run Chrome's Lighthouse report against the local dev server"""
build()
with warn_only():
local('docker run --rm --privileged --net=host gliderlabs/hostlocal')
server_process = multiprocessing.Process(target=serve, daemon=True)
server_process.start()
local('mkdir -p lighthouse-result')
local('docker run --rm -u {UID} -v "$PWD/lighthouse-result:/home/chrome/reports" --cap-add=SYS_ADMIN --user=1000 justinribeiro/lighthouse lighthouse --chrome-flags="--headless --no-sandbox --disable-gpu" http://169.254.255.254:8080/')
server_process.terminate()
server_process.join(timeout=3)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment