diff options
author | Mx Kookie <kookie@spacekookie.de> | 2020-10-31 19:50:28 +0100 |
---|---|---|
committer | Mx Kookie <kookie@spacekookie.de> | 2020-10-31 19:50:28 +0100 |
commit | 73514c05d892c0bf048cd07026a198fbbd0d3420 (patch) | |
tree | bc73a93461a47c8d3b92c1f3c3b1da947fe4785a /infra/website/fabfile.py | |
parent | c4625b175f8200f643fd6e11010932ea44c78433 (diff) | |
parent | 275bec94f9f9e221bfddeb06ca7d5b87068eb7a0 (diff) |
Add 'infra/website/' from commit '275bec94f9f9e221bfddeb06ca7d5b87068eb7a0'
git-subtree-dir: infra/website
git-subtree-mainline: c4625b175f8200f643fd6e11010932ea44c78433
git-subtree-split: 275bec94f9f9e221bfddeb06ca7d5b87068eb7a0
Diffstat (limited to 'infra/website/fabfile.py')
-rwxr-xr-x | infra/website/fabfile.py | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/infra/website/fabfile.py b/infra/website/fabfile.py new file mode 100755 index 000000000000..d46a16e0bc39 --- /dev/null +++ b/infra/website/fabfile.py @@ -0,0 +1,94 @@ +from fabric.api import * +import fabric.contrib.project as project +import os +import shutil +import sys +import SocketServer + +from pelican.server import ComplexHTTPRequestHandler + +# Local path configuration (can be absolute or relative to fabfile) +env.deploy_path = 'output' +DEPLOY_PATH = env.deploy_path + +# Remote server configuration +production = 'spacekookie@lonelyrobot.io:22' +dest_path = '/var/www' + +# Rackspace Cloud Files configuration settings +env.cloudfiles_username = 'my_rackspace_username' +env.cloudfiles_api_key = 'my_rackspace_api_key' +env.cloudfiles_container = 'my_cloudfiles_container' + +# Github Pages configuration +env.github_pages_branch = "gh-pages" + +# Port for `serve` +PORT = 4000 + +def clean(): + """Remove generated files""" + if os.path.isdir(DEPLOY_PATH): + shutil.rmtree(DEPLOY_PATH) + os.makedirs(DEPLOY_PATH) + +def build(): + """Build local version of site""" + local('pelican -s pelicanconf.py') + +def rebuild(): + """`clean` then `build`""" + clean() + build() + +def regenerate(): + """Automatically regenerate site upon file modification""" + local('pelican -r -s pelicanconf.py') + +def serve(): + """Serve site at http://localhost:4000/""" + os.chdir(env.deploy_path) + + class AddressReuseTCPServer(SocketServer.TCPServer): + allow_reuse_address = True + + server = AddressReuseTCPServer(('', PORT), ComplexHTTPRequestHandler) + + sys.stderr.write('Serving on port {0} ...\n'.format(PORT)) + server.serve_forever() + +def reserve(): + """`build`, then `serve`""" + build() + serve() + +def preview(): + """Build production version of site""" + local('pelican -s publishconf.py') + +def cf_upload(): + """Publish to Rackspace Cloud Files""" + rebuild() + with lcd(DEPLOY_PATH): + local('swift -v -A https://auth.api.rackspacecloud.com/v1.0 ' + '-U {cloudfiles_username} ' + '-K {cloudfiles_api_key} ' + 'upload -c {cloudfiles_container} .'.format(**env)) + +@hosts(production) +def publish(): + """Publish to production via rsync""" + local('pelican -s publishconf.py') + project.rsync_project( + remote_dir=dest_path, + exclude=".DS_Store", + local_dir=DEPLOY_PATH.rstrip('/') + '/', + delete=True, + extra_opts='-c', + ) + +def gh_pages(): + """Publish to GitHub Pages""" + rebuild() + local("ghp-import -b {github_pages_branch} {deploy_path}".format(**env)) + local("git push origin {github_pages_branch}".format(**env)) |