From: Aleksander Ɓukasz Date: Thu, 12 Dec 2013 11:35:01 +0000 (+0100) Subject: Build and deployment X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/3e82fe190f3d1fbfb7300a98ff1a3a0497d9e237 Build and deployment - build command - deployment via fnpdjango --- diff --git a/.gitignore b/.gitignore index 318e02d0..156648d6 100644 --- a/.gitignore +++ b/.gitignore @@ -33,4 +33,7 @@ nbproject/* node_modules /static_test -chromedriver.log \ No newline at end of file +chromedriver.log + +deployment/environments.py +apps/wiki/static/wiki/build diff --git a/apps/build/__init__.py b/apps/build/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/apps/build/management/__init__.py b/apps/build/management/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/apps/build/management/commands/__init__.py b/apps/build/management/commands/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/apps/build/management/commands/build.py b/apps/build/management/commands/build.py new file mode 100644 index 00000000..416893d4 --- /dev/null +++ b/apps/build/management/commands/build.py @@ -0,0 +1,43 @@ +import os +from subprocess import call +from optparse import make_option + +from django.core.management.base import BaseCommand, CommandError +from django.core.management import call_command + + +class Command(BaseCommand): + + option_list = BaseCommand.option_list + ( + make_option('--node-bin-path', + action='store', + dest='node_bin_path', + type='string', + default=None, + help='Path to node binary'), + make_option('--npm-bin', + action='store', + dest='npm_bin', + type='string', + default='npm', + help='Path to npm binary'), + ) + + def handle(self, **options): + wiki_base_dir = os.path.join(os.getcwd(), 'apps', 'wiki', 'static', 'wiki') + rng_base_dir = os.path.join(wiki_base_dir, 'rng') + build_dir = os.path.join(wiki_base_dir, 'build') + + self.stdout.write('Installing editor dependencies') + try: + call([options['npm_bin'], 'install'], cwd = rng_base_dir) + except OSError: + raise CommandError('Something went wrong, propably npm binary not found. Tried: %s' % options['npm_bin']) + + self.stdout.write('Building editor') + if options['node_bin_path']: + # grunt needs npm binary to be foundable in PATH + os.environ['PATH'] = '%s:%s' % (options['node_bin_path'], os.environ['PATH']) + call(['./node_modules/.bin/grunt', 'build', '--output-dir=%s' % build_dir], cwd = rng_base_dir) + + call_command('collectstatic', interactive = False, ignore_patterns = ['rng']) diff --git a/deployment/__init__.py b/deployment/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/deployment/base.py b/deployment/base.py new file mode 100644 index 00000000..54333259 --- /dev/null +++ b/deployment/base.py @@ -0,0 +1,26 @@ +from fabric.api import env +from fabric.tasks import Task +from fnpdjango.deploy import Command + + +class Environment(Task): + def __init__(self, *args, **kwargs): + super(Environment, self).__init__(*args, **kwargs) + self.npm_bin = kwargs.pop('npm_bin', 'npm') + self.host = kwargs.pop('host') + self.env_vars = kwargs + self.env_vars['skip_collect_static'] = True + + def run(self, *args, **kwargs): + env.project_name = 'redakcja' + env.hosts = [self.host] + for k,v in self.env_vars.items(): + env[k] = v + + build_cmd = '../../ve/bin/python manage.py build --npm-bin=%s' % self.npm_bin + if 'node_bin_path' in self.env_vars: + build_cmd += ' --node-bin-path=%s' % self.env_vars['node_bin_path'] + + env.pre_collectstatic = [ + Command([build_cmd], '') + ] diff --git a/deployment/environment_template.py b/deployment/environment_template.py new file mode 100644 index 00000000..581b45c6 --- /dev/null +++ b/deployment/environment_template.py @@ -0,0 +1,14 @@ +from fnpdjango.deploy import DebianGunicorn +from base import Environment + + +env1 = Environment( + host = '', + user = '', + app_path = '', + services = [ + DebianGunicorn('') + ], + node_bin_path = '/usr/bin', + npm_bin = 'npm', +) \ No newline at end of file diff --git a/fabfile.py b/fabfile.py new file mode 100644 index 00000000..6738894d --- /dev/null +++ b/fabfile.py @@ -0,0 +1,2 @@ +from fnpdjango.deploy import * +from deployment.environments import * diff --git a/redakcja/settings/common.py b/redakcja/settings/common.py index 4565fe4b..c9a4616f 100644 --- a/redakcja/settings/common.py +++ b/redakcja/settings/common.py @@ -124,6 +124,7 @@ INSTALLED_APPS = ( 'toolbar', 'apiclient', 'email_mangler', + 'build' ) LOGIN_REDIRECT_URL = '/documents/user' diff --git a/redakcja/urls.py b/redakcja/urls.py index 504c828e..d9297e29 100644 --- a/redakcja/urls.py +++ b/redakcja/urls.py @@ -35,3 +35,9 @@ urlpatterns = patterns('', if settings.DEBUG: urlpatterns += staticfiles_urlpatterns() urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + +if getattr(settings, 'SERVE_FILES_WITH_DEBUG_FALSE', False): + urlpatterns += patterns('', + (r'^%s(?P.*)$' % settings.STATIC_URL[1:], 'django.views.static.serve', {'document_root': settings.STATIC_ROOT}), + (r'^%s(?P.*)$' % settings.MEDIA_URL[1:], 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}), +) diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 00000000..5e655130 --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,4 @@ +-i http://pypi.nowoczesnapolska.org.pl/simple + +fabric +fnpdjango>=0.1.10,<0.2