Deploying Ftrack to AWSΒΆ

Deploying ftrack is fairly straight-forward, however the kinds of environments in which it is deployed are usually not under your control as a developer. To make things a little more convenient, here’s a fabric script that deploys ftrack to AWS in one line.

from fabric.api import *
from fabric.contrib.files import exists
from fabric.operations import prompt
from fabric.contrib.files import sed

import os
import shelve

prefs = shelve.open("prefs")

def pref_prompt(key, prompt_text, default=""):
  if key in prefs:
    return prefs[key]
  else:
    prefs[key] = prompt(prompt_text, default=default)
    return prefs[key]

env.hosts = [pref_prompt(key='host', prompt_text='AWS Public DNS (IPv4):')]
ftrack_dl_link = pref_prompt(key='download_link', prompt_text='FTrack Download Link:', default='https://ftrack-deployment.s3.amazonaws.com/localinstall/ftrack-3.5.13-centos6.tar.gz?Signature=kbeLPvONCEts21%2F03fGvJJ6ANf4%3D&Expires=1544116563&AWSAccessKeyId=AKIAIEIZYIZAFJT3IYPA')
ftrack_repo = pref_prompt(key='ftrack_repo', prompt_text='ftrack repo (optional):', default=os.path.join(os.path.expanduser("~"), "dev/ftrack"))
env.key_filename = pref_prompt(key='pem', prompt_text='pem file:',default='~/.ssh/centos.pem')
env.user = pref_prompt(key='user', prompt_text='username (leave as is):', default='centos')
ftrack_deployment_script = pref_prompt(key='ftrack_deployment_script', prompt_text='ftrack deployment script (leave as is):', default="https://s3-eu-west-1.amazonaws.com/ftrack-deployment/localinstall/install_ftrack33_centos6.sh")

@task(default=True)
def setup():
  if not exists("ftrack.tar.gz"):
    run("curl '{0}' > ftrack.tar.gz".format(ftrack_dl_link))
  if not exists("install_ftrack33_centos6.sh"):
    run("curl -O {0}".format(ftrack_deployment_script))
  sudo("yum remove -y mariadb-libs.x86_64")
  sudo("ln -sf /usr/lib64/libpcre.so.1 /usr/lib64/libpcre.so.0")
  with settings(prompts={'Enter the path to the downloaded ftrack package: ': 'ftrack.tar.gz'}):
    sudo("bash install_ftrack33_centos6.sh")
  if os.path.exists(ftrack_repo):
    gen_license()
#  sudo("sed -i '8iftrack.server_url=http://%s' /opt/ftrack_config/ftrack.ini"%env.host)
  print("Your host is now setup on: http://%s\nPlease remember to allow http connections in your security group.\nYou may login with u:root pw:12345"%env.host)

@task
def gen_license():
  with settings(hide('warnings', 'running', 'stdout', 'stderr'),warn_only=True):
    out = run("ifconfig -a | grep -m 1 ether | awk '{print $2}'")
  gen_license_script = os.path.join(ftrack_repo, "trunk/FTServer/genlicense.py")
  key = local("python {0} -m {1}".format(gen_license_script, out), capture=True).split("\n")[0]
  sed("/opt/ftrack_config/ftrack.ini", "<set-licensekey-in-gui>", key)

@task
def stop():
  sudo("/etc/init.d/supervisord_local stop")

@task
def start():
  sudo("/etc/init.d/supervisord_local start")

@task
def restart():
  stop()
  import time
  time.sleep(10)
  start()

@task
def logs():
  run("tail -f /tmp/ftrack.log")

@task
def ssh():
  local("ssh -i %s %s@%s"%(env.key_filename, env.user, env.host))

@task
def clear_prefs():
  os.unlink("prefs.db")

prefs.close()