diff --git a/bin/deploy_meta.py b/bin/deploy_meta.py index 4f8451e..01a42b1 100644 --- a/bin/deploy_meta.py +++ b/bin/deploy_meta.py @@ -295,18 +295,27 @@ class DeployMeta(QtGui.QMainWindow): projectname=dquery.get('project.name'), branchext=dquery.get('project.extension')) + virtualenv_name = "{projectname}_{branchext}".format( + projectname=dquery.get('project.name'), + branchext=dquery.get('project.extension')) + nested_path( self.config_data, 'database.name', database_name) nested_path( - self.config_data, 'virtualenv.name', dquery.get('project.name')) + self.config_data, 'virtualenv.name', virtualenv_name) if self.currentbranch == 'development': projectpath = "{projectname}.prj".format( projectname=dquery.get('project.name')) + nested_path( self.config_data, 'project.paths.home', projectpath) + nested_path( + self.config_data, 'virtualenv.name', + dquery.get('project.name')) + def add_widgetrow(self, key, grid): row = grid.rowCount() diff --git a/modules/deploy.py b/modules/deploy.py index ec1515c..6b9971b 100644 --- a/modules/deploy.py +++ b/modules/deploy.py @@ -8,7 +8,7 @@ from utils import virtualenv_source, booleanize, loggify from utils import print_console from pip import setup_virtualenv -from pip import setup as pip_requirements +from pip import bootstrap_pip import os @@ -78,8 +78,156 @@ def bootstrap(): setup_rootpath() setup_virtualenv() + bootstrap_pip() - pip_requirements() + # 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 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 diff --git a/modules/django.py b/modules/django.py index b9cc655..55d3737 100644 --- a/modules/django.py +++ b/modules/django.py @@ -381,6 +381,11 @@ def generate_scripts(template_name, make_copy=False): @task def generate(param=None, make_copy=False): + """ + param can be one of settings, local, wsgi + make_copy must be set to True if you want it to actually do anthing + """ + SCRIPT_LIST = ['settings', 'local', 'wsgi'] PARAM_LIST = list(SCRIPT_LIST) PARAM_LIST.append('gunicorn') @@ -396,6 +401,7 @@ def generate(param=None, make_copy=False): print "django:generate make_copy : %s\n" % make_copy print "django:generate script : %s" % param + if env.debug: print "django:generate script : %s" % param print "django:generate make_copy : %s\n" % make_copy @@ -408,7 +414,6 @@ def generate(param=None, make_copy=False): if not param: # this is where script=None, generate all scripts - for scriptkey in SCRIPT_LIST: generate_scripts(scriptkey, make_copy) diff --git a/modules/initialize.py b/modules/initialize.py index 2740a87..edfe21f 100644 --- a/modules/initialize.py +++ b/modules/initialize.py @@ -349,6 +349,9 @@ def get_config(branchname): dataobject.server.nginx.port = config['nginx']['port'] + dataobject.server.nginx.socket = config['nginx']['socket'] + print "DEBUG -- socket: %s" % dataobject.server.nginx.socket + if config['project']['host'] == "localhost": dataobject.server.nginx.host = "{projectname}.{ext}".format( ext=dataobject.project.extension, diff --git a/modules/nginx.py b/modules/nginx.py index c62f341..f90fc8f 100644 --- a/modules/nginx.py +++ b/modules/nginx.py @@ -98,6 +98,7 @@ def upload(): context['error_log'] = configuration.logging.nginx.error context['port'] = configuration.server.nginx.port + context['socket'] = configuration.server.nginx.socket context['django_host'] = configuration.server.django.host context['django_port'] = configuration.server.django.port diff --git a/modules/pip.py b/modules/pip.py index 34789d1..88b5ba1 100644 --- a/modules/pip.py +++ b/modules/pip.py @@ -53,6 +53,38 @@ def setup_virtualenv(): run(mkvirtualenv_cmd) +@task +def bootstrap_pip(): + """ + bootstraps pip + """ + # upgrade() + setup() + + +@task +def upgrade(): + """ + upgrade pip to latest version + """ + + # configuration = env.config + + if env.debug: + logging.basicConfig( + format='\n%(levelname)s: deploy.pip %(message)s', + level=logging.DEBUG) + + pipinstall_cmd = "pip install --upgrade pip" + + if env.debug: + logging.debug("with virtualenv(): run(\"\n\t%s\n\t\")" % + pipinstall_cmd) + else: + with virtualenv(): + run(pipinstall_cmd) + + @task def setup(): """ diff --git a/share/templates/conf/django/files/local.jinja2 b/share/templates/conf/django/files/local.jinja2 index 980b10f..bc06c78 100644 --- a/share/templates/conf/django/files/local.jinja2 +++ b/share/templates/conf/django/files/local.jinja2 @@ -70,7 +70,7 @@ USE_DEBUG_TOOLBAR = DEBUG # allow template debug outputs on {{ project_branch }} environment INTERNAL_IPS = ['127.0.0.1', '127.0.0.2', '127.0.0.3', ] -ALLOWED_HOSTS = [configuration.project.extendedname, ] +ALLOWED_HOSTS = [configuration.project.extendedname, configuration.project.host] # ----------------------------------------- # Debug logging to the console diff --git a/share/templates/meta/development.yml b/share/templates/meta/development.yml index 2eb3962..077788f 100644 --- a/share/templates/meta/development.yml +++ b/share/templates/meta/development.yml @@ -22,7 +22,7 @@ maintenance: nginx: commands: {start: nginx, status: ps waux | grep nginx, stop: nginx -s stop} editor: mvim - execute: local + execute: sudo supervisor: commands: {reload: supervisorctl reload, start: supervisorctl start, status: supervisorctl status, stop: supervisorctl stop, update: supervisorctl update} diff --git a/share/templates/meta/layout.yml b/share/templates/meta/layout.yml index a623210..6655f8f 100644 --- a/share/templates/meta/layout.yml +++ b/share/templates/meta/layout.yml @@ -26,7 +26,8 @@ paths: extras: code: "extras/scripts/code" - fixtures: "extras/data/fixtures" + fixtures: "var/fixtures" + ssh: "share/ssh" templates: conf: "usr/etc" diff --git a/share/templates/readmes/aws.md b/share/templates/readmes/aws.md index 6f7b15b..64582ea 100644 --- a/share/templates/readmes/aws.md +++ b/share/templates/readmes/aws.md @@ -264,8 +264,8 @@ add the following: sudo pip install virtualenv sudo pip install virtualenvwrapper - cat "WORKON_HOME=~/.virtualenvs" >> .bashrc - cat ". /usr/local/bin/virtualenvwrapper.sh" >> .bashrc + echo "WORKON_HOME=~/.virtualenvs" >> .bashrc + echo ". /usr/local/bin/virtualenvwrapper.sh" >> .bashrc ### install nginx diff --git a/share/templates/readmes/paramiko.md b/share/templates/readmes/paramiko.md new file mode 100644 index 0000000..919e08f --- /dev/null +++ b/share/templates/readmes/paramiko.md @@ -0,0 +1 @@ +env LDFLAGS="-L$(brew --prefix openssl)/lib" CFLAGS="-I$(brew --prefix openssl)/include" pip install cryptography diff --git a/share/templates/readmes/psycopg2_problem.md b/share/templates/readmes/psycopg2_problem.md new file mode 100644 index 0000000..8003250 --- /dev/null +++ b/share/templates/readmes/psycopg2_problem.md @@ -0,0 +1 @@ + xcode-select --install diff --git a/share/templates/readmes/regex.md b/share/templates/readmes/regex.md new file mode 100644 index 0000000..379a19d --- /dev/null +++ b/share/templates/readmes/regex.md @@ -0,0 +1,9 @@ +# useful regex commands + +## convert href to static + +`.s/href="\([^"]\+\)"/href="{% static '\1' %}"` + +use when **href="/some/link/file.css"** if the + +quotes are single quotes, then convert them to double \ No newline at end of file diff --git a/share/templates/readmes/sass.md b/share/templates/readmes/sass.md new file mode 100644 index 0000000..8841319 --- /dev/null +++ b/share/templates/readmes/sass.md @@ -0,0 +1,20 @@ +##Sass + +### How to set up sass watch with multiple directories + +```` +sass -I share/media/projectwide_sass_files + --watch code/apps/sassdir:code/apps/cssdir +```` + + +### How to get vim to work with a sass file include + +```` +let g:syntastic_sass_sass_args=" + -I /Full/share/media/projectwide_sass_files" +```` + +[fixing syntastic check args](http://stackoverflow.com/questions/29041876/fixing-syntasticcheck-bootstrap-error-vim-syntastic-plugin) + +[syntastic manual](https://github.com/vim-syntastic/syntastic/blob/master/doc/syntastic.txt) \ No newline at end of file