Build and deployment
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 12 Dec 2013 11:35:01 +0000 (12:35 +0100)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Sun, 15 Dec 2013 23:14:16 +0000 (00:14 +0100)
- build command
- deployment via fnpdjango

12 files changed:
.gitignore
apps/build/__init__.py [new file with mode: 0644]
apps/build/management/__init__.py [new file with mode: 0644]
apps/build/management/commands/__init__.py [new file with mode: 0644]
apps/build/management/commands/build.py [new file with mode: 0644]
deployment/__init__.py [new file with mode: 0644]
deployment/base.py [new file with mode: 0644]
deployment/environment_template.py [new file with mode: 0644]
fabfile.py [new file with mode: 0644]
redakcja/settings/common.py
redakcja/urls.py
requirements-dev.txt [new file with mode: 0644]

index 318e02d..156648d 100644 (file)
@@ -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 (file)
index 0000000..e69de29
diff --git a/apps/build/management/__init__.py b/apps/build/management/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/apps/build/management/commands/__init__.py b/apps/build/management/commands/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/apps/build/management/commands/build.py b/apps/build/management/commands/build.py
new file mode 100644 (file)
index 0000000..416893d
--- /dev/null
@@ -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 (file)
index 0000000..e69de29
diff --git a/deployment/base.py b/deployment/base.py
new file mode 100644 (file)
index 0000000..5433325
--- /dev/null
@@ -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 (file)
index 0000000..581b45c
--- /dev/null
@@ -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 (file)
index 0000000..6738894
--- /dev/null
@@ -0,0 +1,2 @@
+from fnpdjango.deploy import *
+from deployment.environments import *
index 4565fe4..c9a4616 100644 (file)
@@ -124,6 +124,7 @@ INSTALLED_APPS = (
     'toolbar',
     'apiclient',
     'email_mangler',
+    'build'
 )
 
 LOGIN_REDIRECT_URL = '/documents/user'
index 504c828..d9297e2 100644 (file)
@@ -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<path>.*)$' % settings.STATIC_URL[1:], 'django.views.static.serve', {'document_root': settings.STATIC_ROOT}),
+    (r'^%s(?P<path>.*)$' % 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 (file)
index 0000000..5e65513
--- /dev/null
@@ -0,0 +1,4 @@
+-i http://pypi.nowoczesnapolska.org.pl/simple
+
+fabric
+fnpdjango>=0.1.10,<0.2