Created
January 4, 2018 21:46
-
-
Save silent1mezzo/268b93d53106c0094b13d5585755f180 to your computer and use it in GitHub Desktop.
An example deployment using Fabric and Symlinks
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
import os | |
import random | |
import requests | |
import json | |
import datetime | |
from fabric.api import * | |
""" | |
Set up servers locations. This can be programatically generated too. | |
""" | |
env.roledefs = { | |
'training': ['10.0.0.1'], | |
'web': ['10.0.1.1', '10.0.1.2'], | |
} | |
""" | |
Set up various environment variables for the application path, virtualenv, | |
pip and requirements files for later use. | |
""" | |
RELEASE_TIMESTAMP = datetime.datetime.today().strftime('%Y%m%d%H%M%S') | |
env.directory = '/var/www/app' | |
env.repo_url = "GIT URL FOR REPO" | |
env.release_dir = '{}-{}'.format(env.directory, RELEASE_TIMESTAMP) | |
PRODUCTION = "production" | |
TRAINING = "training" | |
def git_clone(): | |
run("git clone {} .".format(env.repo_url)) | |
@roles("web") | |
@parallel | |
def update_frontend(): | |
# Take ownership of project | |
sudo('mkdir -p {}'.format(env.release_dir)) | |
with cd(env.release_dir): | |
git_clone() | |
run('npm set progress=false') | |
run('npm install') | |
@roles("web") | |
@parallel | |
def build_frontend(): | |
with cd(env.release_dir): | |
run('npm run build') | |
@roles("web") | |
@parallel | |
def restart_frontend(): | |
sudo('ln -sfn {} {}'.format(env.release_dir, env.directory)) | |
sudo("service nginx restart") | |
""" | |
Here's the entry point for our fabfile. We can run this by typing `fab deploy` (for training) | |
or `fab deploy:production` to deploy to production. | |
""" | |
def deploy(environment=TRAINING): | |
execute('update_frontend') | |
execute('build_frontend') | |
execute('restart_frontend') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment