Created
July 26, 2013 18:13
-
-
Save mike-douglas/6090997 to your computer and use it in GitHub Desktop.
A Fabric task for deploying static websites hosted with NGINX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fabric.api import ( | |
task, | |
settings, | |
env, | |
) | |
from fabric.contrib.project import rsync_project | |
from fabtools import require | |
from fabtools.vagrant import vagrant | |
env.nginx_template = ''' | |
server { | |
listen %(port)d; | |
server_name %(server_name)s %(server_alias)s; | |
root %(docroot)s; | |
access_log /var/log/nginx/%(server_name)s.log; | |
}''' | |
env.host = 'YOUR_HOST' | |
env.domain_name = 'YOUR_DOMAIN_NAME' | |
env.server_alias = '*.YOUR_DOMAIN_NAME' | |
env.deploy_user = 'DEPLOYMENT_USER' | |
env.deploy_dir = '/home/DEPLOYMENT_USER/www' | |
env.local_dir = './output/' | |
env.deploy_excludes = ['fabfile.py*', '.git', '.*', 'requirements.txt'] | |
@task | |
def deploy(): | |
with settings(user=env.deploy_user): | |
rsync_project(local_dir=env.local_dir, | |
remote_dir=env.deploy_dir, | |
delete=True, | |
exclude=env.deploy_excludes) | |
require.nginx.server() | |
require.nginx.site(env.domain_name, | |
template_contents=env.nginx_template, | |
port=80, | |
server_alias=env.server_alias, | |
docroot=env.deploy_dir) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment