diff --git a/README.md b/README.md index 538c53beba58ae99b47a059e57e0ed9b91cc2125..8d1d174d3227127da7be888b79116a8495a3db1e 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,9 @@ - Python 3.6 - [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 @@ -17,10 +20,12 @@ Available commands: build Build local version of site clean Remove generated files 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 publish Publish to production via rsync regenerate Automatically regenerate site upon file modification serve Serve site at http://localhost:8080/ + sitespeed Run sitespeed test against the local dev server ``` diff --git a/fabfile.py b/fabfile.py index fc2c6111f6b4f67cc378732c4720a8437fb84ef7..e5ebef53185ac540e0cb6f6348702cfcb437ad14 100644 --- a/fabfile.py +++ b/fabfile.py @@ -1,7 +1,9 @@ -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 multiprocessing +import os +env.use_ssh_config = True # Local path configuration (can be absolute or relative to fabfile) env.deploy_path = 'output' DEPLOY_PATH = env.deploy_path @@ -10,10 +12,12 @@ DEPLOY_PATH = env.deploy_path production = 'www.shore.co.il' dest_path = '/var/www/htdocs/www.shore.co.il/blog/' +UID = os.getuid() + def clean(): """Remove generated files""" - local(f'rm -r __pycache__/ {DEPLOY_PATH}/*') + local(f'rm -rf __pycache__/ {DEPLOY_PATH}/* sitespeed-result/ lighthouse-result/') def build(): @@ -34,9 +38,11 @@ def serve(): def dev(): """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() regenerate() + server_process.terminate() + server_process.join(timeout=3) def preview(): @@ -55,3 +61,28 @@ def publish(): delete=True, 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)