P5-4836 deploy api to production (new hostname)

This commit is contained in:
Niklas Fondberg
2020-02-27 13:06:58 +01:00
committed by GitHub
parent d2c567a7cd
commit b08aa76acc
9 changed files with 677 additions and 20 deletions
Vendored
+18 -19
View File
@@ -1,24 +1,23 @@
from fabric.api import *
from fabric.api import env, lcd, local, abort
env.user = 'ubuntu'
env.key_filename = '~/.ssh/ukad.pem'
def basic_environment_settings():
env.stack_name = 'api'
env.hosts = (
'ec2-52-50-174-196.eu-west-1.compute.amazonaws.com', #api2-dev
)
def staging():
basic_environment_settings()
env.environment = 'staging'
def production():
basic_environment_settings()
env.environment = 'production'
def cloudformation_update():
if env.environment != 'staging':
abort('Only staging is deployed soo far')
with lcd('./cloudformation/'):
local('make update-stack ENVIRONMENT_NAME={0} STACK_NAME={1}'.format(env.environment, env.stack_name))
def deploy():
branch = local('git rev-parse --abbrev-ref HEAD', capture=True)
local('git archive --format tar.gz -o /tmp/api.tar.gz {0}'.format(branch), capture=False)
put('/tmp/api.tar.gz', '/tmp/api.tar.gz')
with warn_only():
sudo('service nginx stop')
sudo('service api-uwsgi stop')
with cd('/srv/api'):
run('tar xzf /tmp/api.tar.gz')
run('rm /tmp/api.tar.gz')
with warn_only():
sudo('service api-uwsgi start')
sudo('service nginx start')
local('rm /tmp/api.tar.gz')
if env.environment != 'staging':
abort('Local deploy to staging only. Production deploy is automatic when merging to master.')
local('make publish-to-staging')