Browse Source

fabfile changes/updates

py3-upgrade
noah 2 years ago
parent
commit
fd42f64846
1 changed files with 39 additions and 37 deletions
  1. +39
    -37
      fabfile.py

+ 39
- 37
fabfile.py View File

@ -1,79 +1,81 @@
# -*- coding: utf-8 -*-
import datetime
from fabric import Connection, task
from fabric import task
from invoke import Context
prod = Connection('watershed-prod')
local = Context()
import pytz
@task
def test(c):
c.run('ls /srv/watershed/watershed.git', echo=True)
c.run('ls -al /srv/watershed/deploys', echo=True)
@task
def deploy(remote=prod, migrate=False):
@task(hosts=['prod'])
def deploy(c, migrate=False):
"""
deploy to production.
"""
local = Context()
GIT_SHA = git_hash()
TIMESTAMP = datetime.datetime.now().replace(microsecond=0).isoformat()
TIMESTAMP = datetime.datetime.now(pytz.timezone('America/New_York'))\
.replace(microsecond=0).isoformat().replace(':', '.')
DEPLOY_DIR = "/srv/watershed/deploys/{}_{}".format(TIMESTAMP, GIT_SHA)
local.run("git push origin master", echo=True)
# ensure origin/master stays up to date
c.local("git push origin master", echo=True)
# sentry release
VERSION = local.run("sentry-cli releases propose-version", echo=True).stdout
local.run("sentry-cli releases new {}".format(VERSION), echo=True)
local.run("sentry-cli releases set-commits --auto {}".format(VERSION), echo=True)
VERSION = c.local("sentry-cli releases propose-version", echo=True).stdout
c.local("sentry-cli releases new {}".format(VERSION), echo=True)
c.local("sentry-cli releases set-commits --auto {}".format(VERSION), echo=True)
c.local("git push deploy master", echo=True)
local.run("git push deploy master -vvv", echo=True)
c.run("/usr/bin/git clone file:///srv/watershed/watershed.git {}".format(DEPLOY_DIR), echo=True)
remote.run("git clone /srv/watershed/watershed.git {}".format(DEPLOY_DIR), echo=True)
remote.cd(DEPLOY_DIR, echo=True)
remote.run("virtualenv .venv", echo=True)
remote.run("source .venv/bin/activate", echo=True)
c.run("virtualenv {}/.venv".format(DEPLOY_DIR), echo=True)
with c.cd(DEPLOY_DIR):
with c.prefix("source .venv/bin/activate"):
c.run("pip install -r requirements.txt", echo=True)
c.run("yarn install", echo=True)
remote.run("pip install -r requirements.txt", echo=True)
remote.run("yarn install", echo=True)
c.run("webpack --mode=production --config=webpack.config.js", echo=True)
c.run("./manage.py collectstatic --noinput", echo=True)
remote.run("webpack --mode=production --config=webpack.config.js", echo=True)
remote.run("./manage.py collectstatic --noinput", echo=True)
if migrate:
c.run("./manage.py migrate")
if migrate:
remote.run("./manage.py migrate", echo=True)
c.run("./manage.py compile_pyc")
c.run("chgrp -R www-data . && chmod -R 775 .")
remote.run("./manage.py compile_pyc", echo=True)
remote.run("ln -nsf {} /srv/watershed/live".format(DEPLOY_DIR), echo=True)
remote.run(
c.run("ln -nsf {} /srv/watershed/live".format(DEPLOY_DIR))
c.run(
"ln -nsf /srv/watershed/live/watershed.uwsgi.ini /etc/uwsgi/apps-enabled/",
echo=True
)
remote.run("sudo service uwsgi reload", echo=True)
remote.run(
c.run("sudo service uwsgi reload")
c.run(
"ln -nsf /srv/watershed/live/watershed.nginx.conf /etc/nginx/sites-enabled/",
echo=True
)
remote.run("sudo service nginx reload", echo=True)
c.run("sudo service nginx reload")
@task
def package_ext(c=local):
@task()
def package_ext(c):
"""
zip the extension. just making sure idk
"""
GIT_SHA = git_hash()
local.run("webpack --mode=production --browser", echo=True)
with local.cd("browser/dist"):
local.run("zip -r ../releases/extension_{} *".format(GIT_SHA), echo=True)
c.local("webpack --mode=production --browser")
with c.local.cd("browser/dist"):
c.local("zip -r ../releases/extension_{} *".format(GIT_SHA))
def git_hash():
"""
get an identifier for HEAD
"""
local = Context()
return local.run("git rev-parse --short HEAD", echo=True).stdout.rstrip("\n")
return local.run("git rev-parse --short HEAD").stdout.rstrip("\n")

Loading…
Cancel
Save