fabfile.py 21 KB

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