From 152b5658a92db467f1b1781e7d7a342654f9750f Mon Sep 17 00:00:00 2001 From: Ronny Abraham Date: Thu, 20 Jul 2017 23:43:33 +0300 Subject: [PATCH] fix bug in deployment where pip gets updated during initial bootstrap,but then screws up the rest of the deployment including pip install. Break up the deployment into two parts. NOTE: must find a way to have deployment as one part alone Changes to be committed: modified: modules/deploy.py modified: modules/pip.py --- modules/deploy.py | 145 ++++++++++++++++++++++++++++++++++++++++++++++ modules/pip.py | 2 +- 2 files changed, 146 insertions(+), 1 deletion(-) diff --git a/modules/deploy.py b/modules/deploy.py index 5acd042..6b9971b 100644 --- a/modules/deploy.py +++ b/modules/deploy.py @@ -193,6 +193,151 @@ def bootstrap(): db.init() +@task +def bootstrap_part1(): + # import database as db + + # configuration = env.config + + # if env.debug: + # logger = loggify('deploy', 'bootstrap_part1') + + # + # not doing a full sync, because we have to set up the rootpath, + # virtualenv, files, dir structure, etc. This means we aren't + # going to upload gunicorn and supervisor until after we've done + # everything else at the end of the bootstrapping process + + sync(full=False) + + # continue setting up the rootpath and virtualenv + setup_rootpath() + + setup_virtualenv() + + +@task +def bootstrap_part2(): + import database as db + + configuration = env.config + + if env.debug: + logger = loggify('deploy', 'bootstrap') + + # create the django project + from django import create_project + create_project() + + # + # link virtualenv to rootpath/private/virtualenv + + src_virtual = configuration.virtualenv.paths.root + dst_virtual = configuration.paths.server.virtual + + # + # link templates to rootpath/private/templates + + src_templates = configuration.paths.django.templates + dst_templates = configuration.paths.server.django.templates + + # + # link the django code in the project directory to the appropriate location + # in the rootpath directory + + src_code = configuration.paths.django.root + dst_code = configuration.paths.server.django.code + + # + # I corrected the linking code so that it deletes already existing + # links before creating them, otherwise you get really weird errors + # where the a link is recreated within the destination link + + from utils import link_create + + if env.debug: + logger.debug("virtualenv.root : %s" + % configuration.virtualenv.paths.root) + logger.debug("virtualenv.bin : %s\n" % + configuration.virtualenv.paths.bin) + + logger.debug("paths.server\n") + + logger.debug(" - root\t: %s" % configuration.paths.server.root) + + logger.debug(" - media\t: %s" % + configuration.paths.server.media.static) + + logger.debug(" - virtual\t: %s" % configuration.paths.server.virtual) + + logger.debug(" - django.code\t: %s\n" % + configuration.paths.server.django.code) + + logger.debug("django templates : %s" % + configuration.paths.django.templates) + + logger.debug("django root : %s" % + configuration.paths.django.root) + + logger.debug("django settings : %s" % + configuration.paths.django.settings.root) + + logger.debug("django local : %s" % + configuration.paths.django.settings.local) + + logger.debug(link_create(src_virtual, dst_virtual, debug=True)) + logger.debug(link_create(src_templates, dst_templates, debug=True)) + logger.debug(link_create(src_code, dst_code, debug=True)) + + else: + link_create(src_virtual, dst_virtual) + link_create(src_templates, dst_templates) + link_create(src_code, dst_code) + + # + # create and link the scripts that manage the server + # e.g. nginx, supervisor, gunicorn + + from nginx import upload as upload_nginx + from supervisor import upload as upload_supervisor + from django import generate as django_generate + + print_console("creating gunicorn script") + django_generate('gunicorn', True) + django_generate('local', True) + + print_console("creating supervisor script") + upload_supervisor() + + print_console("creating nginx script") + upload_nginx() + + # + # instantiate docker containers if any + + import docker + + print_console("check to see if docker containers are used") + + if hasattr(configuration, "docker"): + print_console("generating docker configuration file") + docker.generate() + + print_console("creating and starting docker container") + docker.create() + else: + print_console("no docker containers are being used. pass") + + # + # create and initialize the database + + print_console("in db.generate") + db.generate() + + print_console("in db.init") + db.init() + + @task def sync(full=True, extras=False): diff --git a/modules/pip.py b/modules/pip.py index 60e4b38..88b5ba1 100644 --- a/modules/pip.py +++ b/modules/pip.py @@ -58,7 +58,7 @@ def bootstrap_pip(): """ bootstraps pip """ - upgrade() + # upgrade() setup()