Website for the bigbrother awards
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fabfile.py 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. from __future__ import print_function, unicode_literals
  2. from future.builtins import open
  3. import os
  4. import re
  5. import sys
  6. from contextlib import contextmanager
  7. from functools import wraps
  8. from getpass import getpass, getuser
  9. from glob import glob
  10. from importlib import import_module
  11. from posixpath import join
  12. from mezzanine.utils.conf import real_project_name
  13. from fabric.api import abort, env, cd, prefix, sudo as _sudo, run as _run, \
  14. hide, task, local
  15. from fabric.context_managers import settings as fab_settings
  16. from fabric.contrib.console import confirm
  17. from fabric.contrib.files import exists, upload_template
  18. from fabric.contrib.project import rsync_project
  19. from fabric.colors import yellow, green, blue, red
  20. from fabric.decorators import hosts
  21. ################
  22. # Config setup #
  23. ################
  24. if not hasattr(env, "proj_app"):
  25. env.proj_app = real_project_name("bigbrother")
  26. conf = {}
  27. if sys.argv[0].split(os.sep)[-1] in ("fab", "fab-script.py"):
  28. # Ensure we import settings from the current dir
  29. try:
  30. conf = import_module("%s.settings" % env.proj_app).FABRIC
  31. try:
  32. conf["HOSTS"][0]
  33. except (KeyError, ValueError):
  34. raise ImportError
  35. except (ImportError, AttributeError):
  36. print("Aborting, no hosts defined.")
  37. exit()
  38. env.db_pass = conf.get("DB_PASS", None)
  39. env.admin_pass = conf.get("ADMIN_PASS", None)
  40. env.user = conf.get("SSH_USER", getuser())
  41. env.password = conf.get("SSH_PASS", None)
  42. env.key_filename = conf.get("SSH_KEY_PATH", None)
  43. env.hosts = conf.get("HOSTS", [""])
  44. env.proj_name = conf.get("PROJECT_NAME", env.proj_app)
  45. env.venv_home = conf.get("VIRTUALENV_HOME", "/home/%s/.virtualenvs" % env.user)
  46. env.venv_path = join(env.venv_home, env.proj_name)
  47. env.proj_path = "/home/%s/mezzanine/%s" % (env.user, env.proj_name)
  48. env.manage = "%s/bin/python %s/manage.py" % (env.venv_path, env.proj_path)
  49. env.domains = conf.get("DOMAINS", [conf.get("LIVE_HOSTNAME", env.hosts[0])])
  50. env.domains_nginx = " ".join(env.domains)
  51. env.domains_regex = "|".join(env.domains)
  52. env.domains_python = ", ".join(["'%s'" % s for s in env.domains])
  53. env.ssl_disabled = "#" if len(env.domains) > 1 else ""
  54. env.vcs_tools = ["git", "hg"]
  55. env.deploy_tool = conf.get("DEPLOY_TOOL", "rsync")
  56. env.reqs_path = conf.get("REQUIREMENTS_PATH", None)
  57. env.locale = conf.get("LOCALE", "en_US.UTF-8")
  58. env.num_workers = conf.get("NUM_WORKERS",
  59. "multiprocessing.cpu_count() * 2 + 1")
  60. env.secret_key = conf.get("SECRET_KEY", "")
  61. env.nevercache_key = conf.get("NEVERCACHE_KEY", "")
  62. if not env.secret_key and \
  63. os.environ.get("DJANGO_SETTINGS_MODULE", "") != "docs_settings":
  64. print("Aborting, no SECRET_KEY setting defined.")
  65. exit()
  66. # Remote git repos need to be "bare" and reside separated from the project
  67. if env.deploy_tool == "git":
  68. env.repo_path = "/home/%s/git/%s.git" % (env.user, env.proj_name)
  69. else:
  70. env.repo_path = env.proj_path
  71. ##################
  72. # Template setup #
  73. ##################
  74. # Each template gets uploaded at deploy time, only if their
  75. # contents has changed, in which case, the reload command is
  76. # also run.
  77. templates = {
  78. "nginx": {
  79. "local_path": "deploy/nginx.conf.template",
  80. "remote_path": "/etc/nginx/sites-enabled/%(proj_name)s.conf",
  81. "reload_command": "nginx -t && service nginx restart",
  82. },
  83. "supervisor": {
  84. "local_path": "deploy/supervisor.conf.template",
  85. "remote_path": "/etc/supervisor/conf.d/%(proj_name)s.conf",
  86. "reload_command": "supervisorctl update gunicorn_%(proj_name)s",
  87. },
  88. "cron": {
  89. "local_path": "deploy/crontab.template",
  90. "remote_path": "/etc/cron.d/%(proj_name)s",
  91. "owner": "root",
  92. "mode": "600",
  93. },
  94. "gunicorn": {
  95. "local_path": "deploy/gunicorn.conf.py.template",
  96. "remote_path": "%(proj_path)s/gunicorn.conf.py",
  97. },
  98. "settings": {
  99. "local_path": "deploy/local_settings.py.template",
  100. "remote_path": "%(proj_path)s/%(proj_app)s/local_settings.py",
  101. },
  102. }
  103. ######################################
  104. # Context for virtualenv and project #
  105. ######################################
  106. @contextmanager
  107. def virtualenv():
  108. """
  109. Runs commands within the project's virtualenv.
  110. """
  111. with cd(env.venv_path):
  112. with prefix("source %s/bin/activate" % env.venv_path):
  113. yield
  114. @contextmanager
  115. def project():
  116. """
  117. Runs commands within the project's directory.
  118. """
  119. with virtualenv():
  120. with cd(env.proj_path):
  121. yield
  122. @contextmanager
  123. def update_changed_requirements():
  124. """
  125. Checks for changes in the requirements file across an update,
  126. and gets new requirements if changes have occurred.
  127. """
  128. reqs_path = join(env.proj_path, env.reqs_path)
  129. get_reqs = lambda: run("cat %s" % reqs_path, show=False)
  130. old_reqs = get_reqs() if env.reqs_path else ""
  131. yield
  132. if old_reqs:
  133. new_reqs = get_reqs()
  134. if old_reqs == new_reqs:
  135. # Unpinned requirements should always be checked.
  136. for req in new_reqs.split("\n"):
  137. if req.startswith("-e"):
  138. if "@" not in req:
  139. # Editable requirement without pinned commit.
  140. break
  141. elif req.strip() and not req.startswith("#"):
  142. if not set(">=<") & set(req):
  143. # PyPI requirement without version.
  144. break
  145. else:
  146. # All requirements are pinned.
  147. return
  148. pip("-r %s/%s" % (env.proj_path, env.reqs_path))
  149. ###########################################
  150. # Utils and wrappers for various commands #
  151. ###########################################
  152. def _print(output):
  153. print()
  154. print(output)
  155. print()
  156. def print_command(command):
  157. _print(blue("$ ", bold=True) +
  158. yellow(command, bold=True) +
  159. red(" ->", bold=True))
  160. @task
  161. def run(command, show=True, *args, **kwargs):
  162. """
  163. Runs a shell comand on the remote server.
  164. """
  165. if show:
  166. print_command(command)
  167. with hide("running"):
  168. return _run(command, *args, **kwargs)
  169. @task
  170. def sudo(command, show=True, *args, **kwargs):
  171. """
  172. Runs a command as sudo on the remote server.
  173. """
  174. if show:
  175. print_command(command)
  176. with hide("running"):
  177. return _sudo(command, *args, **kwargs)
  178. def log_call(func):
  179. @wraps(func)
  180. def logged(*args, **kawrgs):
  181. header = "-" * len(func.__name__)
  182. _print(green("\n".join([header, func.__name__, header]), bold=True))
  183. return func(*args, **kawrgs)
  184. return logged
  185. def get_templates():
  186. """
  187. Returns each of the templates with env vars injected.
  188. """
  189. injected = {}
  190. for name, data in templates.items():
  191. injected[name] = dict([(k, v % env) for k, v in data.items()])
  192. return injected
  193. def upload_template_and_reload(name):
  194. """
  195. Uploads a template only if it has changed, and if so, reload the
  196. related service.
  197. """
  198. template = get_templates()[name]
  199. local_path = template["local_path"]
  200. if not os.path.exists(local_path):
  201. project_root = os.path.dirname(os.path.abspath(__file__))
  202. local_path = os.path.join(project_root, local_path)
  203. remote_path = template["remote_path"]
  204. reload_command = template.get("reload_command")
  205. owner = template.get("owner")
  206. mode = template.get("mode")
  207. remote_data = ""
  208. if exists(remote_path):
  209. with hide("stdout"):
  210. remote_data = sudo("cat %s" % remote_path, show=False)
  211. with open(local_path, "r") as f:
  212. local_data = f.read()
  213. # Escape all non-string-formatting-placeholder occurrences of '%':
  214. local_data = re.sub(r"%(?!\(\w+\)s)", "%%", local_data)
  215. if "%(db_pass)s" in local_data:
  216. env.db_pass = db_pass()
  217. local_data %= env
  218. clean = lambda s: s.replace("\n", "").replace("\r", "").strip()
  219. if clean(remote_data) == clean(local_data):
  220. return
  221. upload_template(local_path, remote_path, env, use_sudo=True, backup=False)
  222. if owner:
  223. sudo("chown %s %s" % (owner, remote_path))
  224. if mode:
  225. sudo("chmod %s %s" % (mode, remote_path))
  226. if reload_command:
  227. sudo(reload_command)
  228. def rsync_upload():
  229. """
  230. Uploads the project with rsync excluding some files and folders.
  231. """
  232. excludes = ["*.pyc", "*.pyo", "*.db", ".DS_Store", ".coverage",
  233. "local_settings.py", "/static", "/.git", "/.hg"]
  234. local_dir = os.getcwd() + os.sep
  235. return rsync_project(remote_dir=env.proj_path, local_dir=local_dir,
  236. exclude=excludes)
  237. def vcs_upload():
  238. """
  239. Uploads the project with the selected VCS tool.
  240. """
  241. if env.deploy_tool == "git":
  242. remote_path = "ssh://%s@%s%s" % (env.user, env.host_string,
  243. env.repo_path)
  244. if not exists(env.repo_path):
  245. run("mkdir -p %s" % env.repo_path)
  246. with cd(env.repo_path):
  247. run("git init --bare")
  248. local("git push -f %s master" % remote_path)
  249. with cd(env.repo_path):
  250. run("GIT_WORK_TREE=%s git checkout -f master" % env.proj_path)
  251. run("GIT_WORK_TREE=%s git reset --hard" % env.proj_path)
  252. elif env.deploy_tool == "hg":
  253. remote_path = "ssh://%s@%s/%s" % (env.user, env.host_string,
  254. env.repo_path)
  255. with cd(env.repo_path):
  256. if not exists("%s/.hg" % env.repo_path):
  257. run("hg init")
  258. print(env.repo_path)
  259. with fab_settings(warn_only=True):
  260. push = local("hg push -f %s" % remote_path)
  261. if push.return_code == 255:
  262. abort()
  263. run("hg update")
  264. def db_pass():
  265. """
  266. Prompts for the database password if unknown.
  267. """
  268. if not env.db_pass:
  269. env.db_pass = getpass("Enter the database password: ")
  270. return env.db_pass
  271. @task
  272. def apt(packages):
  273. """
  274. Installs one or more system packages via apt.
  275. """
  276. return sudo("apt-get install -y -q " + packages)
  277. @task
  278. def pip(packages):
  279. """
  280. Installs one or more Python packages within the virtual environment.
  281. """
  282. with virtualenv():
  283. return run("pip install %s" % packages)
  284. def postgres(command):
  285. """
  286. Runs the given command as the postgres user.
  287. """
  288. show = not command.startswith("psql")
  289. return sudo(command, show=show, user="postgres")
  290. @task
  291. def psql(sql, show=True):
  292. """
  293. Runs SQL against the project's database.
  294. """
  295. out = postgres('psql -c "%s"' % sql)
  296. if show:
  297. print_command(sql)
  298. return out
  299. @task
  300. def backup(filename):
  301. """
  302. Backs up the project database.
  303. """
  304. tmp_file = "/tmp/%s" % filename
  305. # We dump to /tmp because user "postgres" can't write to other user folders
  306. # We cd to / because user "postgres" might not have read permissions
  307. # elsewhere.
  308. with cd("/"):
  309. postgres("pg_dump -Fc %s > %s" % (env.proj_name, tmp_file))
  310. run("cp %s ." % tmp_file)
  311. sudo("rm -f %s" % tmp_file)
  312. @task
  313. def restore(filename):
  314. """
  315. Restores the project database from a previous backup.
  316. """
  317. return postgres("pg_restore -c -d %s %s" % (env.proj_name, filename))
  318. @task
  319. def python(code, show=True):
  320. """
  321. Runs Python code in the project's virtual environment, with Django loaded.
  322. """
  323. setup = "import os;" \
  324. "os.environ[\'DJANGO_SETTINGS_MODULE\']=\'%s.settings\';" \
  325. "import django;" \
  326. "django.setup();" % env.proj_app
  327. full_code = 'python -c "%s%s"' % (setup, code.replace("`", "\\\`"))
  328. with project():
  329. if show:
  330. print_command(code)
  331. result = run(full_code, show=False)
  332. return result
  333. def static():
  334. """
  335. Returns the live STATIC_ROOT directory.
  336. """
  337. return python("from django.conf import settings;"
  338. "print(settings.STATIC_ROOT)", show=False).split("\n")[-1]
  339. @task
  340. def manage(command):
  341. """
  342. Runs a Django management command.
  343. """
  344. return run("%s %s" % (env.manage, command))
  345. ###########################
  346. # Security best practices #
  347. ###########################
  348. @task
  349. @log_call
  350. @hosts(["root@%s" % host for host in env.hosts])
  351. def secure(new_user=env.user):
  352. """
  353. Minimal security steps for brand new servers.
  354. Installs system updates, creates new user (with sudo privileges) for future
  355. usage, and disables root login via SSH.
  356. """
  357. run("apt-get update -q")
  358. run("apt-get upgrade -y -q")
  359. run("adduser --gecos '' %s" % new_user)
  360. run("usermod -G sudo %s" % new_user)
  361. run("sed -i 's:RootLogin yes:RootLogin no:' /etc/ssh/sshd_config")
  362. run("service ssh restart")
  363. print(green("Security steps completed. Log in to the server as '%s' from "
  364. "now on." % new_user, bold=True))
  365. #########################
  366. # Install and configure #
  367. #########################
  368. @task
  369. @log_call
  370. def install():
  371. """
  372. Installs the base system and Python requirements for the entire server.
  373. """
  374. # Install system requirements
  375. sudo("apt-get update -y -q")
  376. apt("nginx libjpeg-dev python-dev python-setuptools git-core "
  377. "postgresql libpq-dev memcached supervisor python-pip")
  378. apt('gcc rsync')
  379. run("mkdir -p /home/%s/logs" % env.user)
  380. # Install Python requirements
  381. sudo("pip install -U pip virtualenv virtualenvwrapper mercurial")
  382. # Set up virtualenv
  383. run("mkdir -p %s" % env.venv_home)
  384. run("echo 'export WORKON_HOME=%s' >> /home/%s/.bashrc" % (env.venv_home,
  385. env.user))
  386. run("echo 'source /usr/local/bin/virtualenvwrapper.sh' >> "
  387. "/home/%s/.bashrc" % env.user)
  388. print(green("Successfully set up git, mercurial, pip, virtualenv, "
  389. "supervisor, memcached.", bold=True))
  390. @task
  391. @log_call
  392. def create():
  393. """
  394. Creates the environment needed to host the project.
  395. The environment consists of: system locales, virtualenv, database, project
  396. files, SSL certificate, and project-specific Python requirements.
  397. """
  398. # Generate project locale
  399. locale = env.locale.replace("UTF-8", "utf8")
  400. with hide("stdout"):
  401. if locale not in run("locale -a"):
  402. sudo("locale-gen %s" % env.locale)
  403. sudo("update-locale %s" % env.locale)
  404. sudo("service postgresql restart")
  405. run("exit")
  406. # Create project path
  407. run("mkdir -p %s" % env.proj_path)
  408. # Set up virtual env
  409. run("mkdir -p %s" % env.venv_home)
  410. with cd(env.venv_home):
  411. if exists(env.proj_name):
  412. if confirm("Virtualenv already exists in host server: %s"
  413. "\nWould you like to replace it?" % env.proj_name):
  414. run("rm -rf %s" % env.proj_name)
  415. else:
  416. abort()
  417. run("virtualenv %s" % env.proj_name)
  418. # Upload project files
  419. if env.deploy_tool in env.vcs_tools:
  420. vcs_upload()
  421. else:
  422. rsync_upload()
  423. # Create DB and DB user
  424. pw = db_pass()
  425. user_sql_args = (env.proj_name, pw.replace("'", "\'"))
  426. user_sql = "CREATE USER %s WITH ENCRYPTED PASSWORD '%s';" % user_sql_args
  427. psql(user_sql, show=False)
  428. shadowed = "*" * len(pw)
  429. print_command(user_sql.replace("'%s'" % pw, "'%s'" % shadowed))
  430. psql("CREATE DATABASE %s WITH OWNER %s ENCODING = 'UTF8' "
  431. "LC_CTYPE = '%s' LC_COLLATE = '%s' TEMPLATE template0;" %
  432. (env.proj_name, env.proj_name, env.locale, env.locale))
  433. # Set up SSL certificate
  434. if not env.ssl_disabled:
  435. conf_path = "/etc/nginx/conf"
  436. if not exists(conf_path):
  437. sudo("mkdir %s" % conf_path)
  438. with cd(conf_path):
  439. crt_file = env.proj_name + ".crt"
  440. key_file = env.proj_name + ".key"
  441. if not exists(crt_file) and not exists(key_file):
  442. try:
  443. crt_local, = glob(join("deploy", "*.crt"))
  444. key_local, = glob(join("deploy", "*.key"))
  445. except ValueError:
  446. parts = (crt_file, key_file, env.domains[0])
  447. sudo("openssl req -new -x509 -nodes -out %s -keyout %s "
  448. "-subj '/CN=%s' -days 3650" % parts)
  449. else:
  450. upload_template(crt_local, crt_file, use_sudo=True)
  451. upload_template(key_local, key_file, use_sudo=True)
  452. # Install project-specific requirements
  453. upload_template_and_reload("settings")
  454. with project():
  455. if env.reqs_path:
  456. pip("-r %s/%s" % (env.proj_path, env.reqs_path))
  457. pip("gunicorn setproctitle psycopg2 "
  458. "django-compressor python-memcached")
  459. # Bootstrap the DB
  460. manage("createdb --noinput --nodata")
  461. python("from django.conf import settings;"
  462. "from django.contrib.sites.models import Site;"
  463. "Site.objects.filter(id=settings.SITE_ID).update(domain='%s');"
  464. % env.domains[0])
  465. for domain in env.domains:
  466. python("from django.contrib.sites.models import Site;"
  467. "Site.objects.get_or_create(domain='%s');" % domain)
  468. if env.admin_pass:
  469. pw = env.admin_pass
  470. user_py = ("from django.contrib.auth import get_user_model;"
  471. "User = get_user_model();"
  472. "u, _ = User.objects.get_or_create(username='admin');"
  473. "u.is_staff = u.is_superuser = True;"
  474. "u.set_password('%s');"
  475. "u.save();" % pw)
  476. python(user_py, show=False)
  477. shadowed = "*" * len(pw)
  478. print_command(user_py.replace("'%s'" % pw, "'%s'" % shadowed))
  479. return True
  480. @task
  481. @log_call
  482. def remove():
  483. """
  484. Blow away the current project.
  485. """
  486. if exists(env.venv_path):
  487. run("rm -rf %s" % env.venv_path)
  488. if exists(env.proj_path):
  489. run("rm -rf %s" % env.proj_path)
  490. for template in get_templates().values():
  491. remote_path = template["remote_path"]
  492. if exists(remote_path):
  493. sudo("rm %s" % remote_path)
  494. if exists(env.repo_path):
  495. run("rm -rf %s" % env.repo_path)
  496. sudo("supervisorctl update")
  497. psql("DROP DATABASE IF EXISTS %s;" % env.proj_name)
  498. psql("DROP USER IF EXISTS %s;" % env.proj_name)
  499. ##############
  500. # Deployment #
  501. ##############
  502. @task
  503. @log_call
  504. def restart():
  505. """
  506. Restart gunicorn worker processes for the project.
  507. If the processes are not running, they will be started.
  508. """
  509. pid_path = "%s/gunicorn.pid" % env.proj_path
  510. if exists(pid_path):
  511. run("kill -HUP `cat %s`" % pid_path)
  512. else:
  513. sudo("supervisorctl update")
  514. @task
  515. @log_call
  516. def deploy():
  517. """
  518. Deploy latest version of the project.
  519. Backup current version of the project, push latest version of the project
  520. via version control or rsync, install new requirements, sync and migrate
  521. the database, collect any new static assets, and restart gunicorn's worker
  522. processes for the project.
  523. """
  524. if not exists(env.proj_path):
  525. if confirm("Project does not exist in host server: %s"
  526. "\nWould you like to create it?" % env.proj_name):
  527. create()
  528. else:
  529. abort()
  530. # Backup current version of the project
  531. with cd(env.proj_path):
  532. backup("last.db")
  533. if env.deploy_tool in env.vcs_tools:
  534. with cd(env.repo_path):
  535. if env.deploy_tool == "git":
  536. run("git rev-parse HEAD > %s/last.commit" % env.proj_path)
  537. elif env.deploy_tool == "hg":
  538. run("hg id -i > last.commit")
  539. with project():
  540. static_dir = static()
  541. if exists(static_dir):
  542. run("tar -cf static.tar --exclude='*.thumbnails' %s" %
  543. static_dir)
  544. else:
  545. with cd(join(env.proj_path, "..")):
  546. excludes = ["*.pyc", "*.pio", "*.thumbnails"]
  547. exclude_arg = " ".join("--exclude='%s'" % e for e in excludes)
  548. run("tar -cf {0}.tar {1} {0}".format(env.proj_name, exclude_arg))
  549. # Deploy latest version of the project
  550. with update_changed_requirements():
  551. if env.deploy_tool in env.vcs_tools:
  552. vcs_upload()
  553. else:
  554. rsync_upload()
  555. with project():
  556. manage("collectstatic -v 0 --noinput")
  557. manage("migrate --noinput")
  558. for name in get_templates():
  559. upload_template_and_reload(name)
  560. restart()
  561. return True
  562. @task
  563. @log_call
  564. def rollback():
  565. """
  566. Reverts project state to the last deploy.
  567. When a deploy is performed, the current state of the project is
  568. backed up. This includes the project files, the database, and all static
  569. files. Calling rollback will revert all of these to their state prior to
  570. the last deploy.
  571. """
  572. with update_changed_requirements():
  573. if env.deploy_tool in env.vcs_tools:
  574. with cd(env.repo_path):
  575. if env.deploy_tool == "git":
  576. run("GIT_WORK_TREE={0} git checkout -f "
  577. "`cat {0}/last.commit`".format(env.proj_path))
  578. elif env.deploy_tool == "hg":
  579. run("hg update -C `cat last.commit`")
  580. with project():
  581. with cd(join(static(), "..")):
  582. run("tar -xf %s/static.tar" % env.proj_path)
  583. else:
  584. with cd(env.proj_path.rsplit("/", 1)[0]):
  585. run("rm -rf %s" % env.proj_name)
  586. run("tar -xf %s.tar" % env.proj_name)
  587. with cd(env.proj_path):
  588. restore("last.db")
  589. restart()
  590. @task
  591. @log_call
  592. def all():
  593. """
  594. Installs everything required on a new system and deploy.
  595. From the base software, up to the deployed project.
  596. """
  597. install()
  598. if create():
  599. deploy()