From 4f6d7a3e9ad39a1b610995b565a08f811fab29ef Mon Sep 17 00:00:00 2001 From: Greg Thole Date: Sun, 21 Jan 2018 11:56:53 -0500 Subject: [PATCH] Various deployment fixes --- .dockerignore | 1 + .gitignore | 2 ++ Dockerfile | 3 +- gedgo/__init__.py | 7 +++-- gedgo/gedcom_update.py | 2 +- gedgo/migrations/0002_auto_20180120_1030.py | 2 +- gedgo/models/document.py | 2 +- gedgo/static/styles/style-default.css | 10 +++--- gedgo/storages.py | 4 ++- gedgo/templates/default/base.html | 2 +- gedgo/templates/default/blogpost.html | 31 ++++++++++--------- gedgo/templates/default/dashboard.html | 11 ++++--- .../templates/default/documentary_by_id.html | 8 +++-- gedgo/views/dashboard.py | 2 +- gedgo/views/media.py | 4 +-- reqs.frozen.pip | 31 +++++++++++++++++++ reqs.pip | 2 ++ settings.py | 7 +++-- wsgi.py | 7 +++++ 19 files changed, 98 insertions(+), 40 deletions(-) create mode 100644 reqs.frozen.pip create mode 100644 wsgi.py diff --git a/.dockerignore b/.dockerignore index 2a6b170..a46ba90 100644 --- a/.dockerignore +++ b/.dockerignore @@ -3,3 +3,4 @@ settings_local.py *.ged /tmp /files +/data diff --git a/.gitignore b/.gitignore index e584585..3457a16 100644 --- a/.gitignore +++ b/.gitignore @@ -32,6 +32,8 @@ pip-log.txt *d3.*.js /files/ +/data/ *.ged +docker-compose-prd.yml settings_local.py /tmp diff --git a/Dockerfile b/Dockerfile index 2438e1f..ebedaa5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,8 @@ FROM python:2.7 COPY ./ /app/ WORKDIR /app/ -RUN pip install -r reqs.pip +RUN pip install -r reqs.frozen.pip +RUN mkdir -p /static && python manage.py collectstatic -c --noinput RUN adduser --disabled-password --gecos '' gedgo RUN chown -R gedgo:gedgo /app diff --git a/gedgo/__init__.py b/gedgo/__init__.py index ae6f887..9e11c72 100644 --- a/gedgo/__init__.py +++ b/gedgo/__init__.py @@ -3,5 +3,8 @@ redis = None if hasattr(settings, 'GEDGO_REDIS_SERVER'): - redis = Redis.StrictRedis(host=settings.GEDGO_REDIS_SERVER) - redis.ping() + try: + redis = Redis.StrictRedis(host=settings.GEDGO_REDIS_SERVER) + redis.ping() + except Exception as e: + print e diff --git a/gedgo/gedcom_update.py b/gedgo/gedcom_update.py index a6ab291..035c46e 100644 --- a/gedgo/gedcom_update.py +++ b/gedgo/gedcom_update.py @@ -43,7 +43,7 @@ def update(g, file_name, verbose=True): __process_Note(entry, g) note_counter += 1 - if (index + 1) % 100 == 0: + if verbose and (index + 1) % 100 == 0: print ' ... %d / %d' % (index + 1, len(entries)) if verbose: diff --git a/gedgo/migrations/0002_auto_20180120_1030.py b/gedgo/migrations/0002_auto_20180120_1030.py index 53936d8..d36c655 100644 --- a/gedgo/migrations/0002_auto_20180120_1030.py +++ b/gedgo/migrations/0002_auto_20180120_1030.py @@ -29,6 +29,6 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='document', name='docfile', - field=models.FileField(upload_to=b'gedcom'), + field=models.FileField(upload_to=b'uploads'), ), ] diff --git a/gedgo/models/document.py b/gedgo/models/document.py index 302ffa6..6210889 100644 --- a/gedgo/models/document.py +++ b/gedgo/models/document.py @@ -8,7 +8,7 @@ class Meta: title = models.CharField(max_length=40, null=True, blank=True) description = models.TextField(null=True, blank=True) - docfile = models.FileField(upload_to='gedcom') + docfile = models.FileField(upload_to='uploads') last_updated = models.DateTimeField(auto_now_add=True) gedcom = models.ForeignKey('Gedcom', null=True, blank=True) diff --git a/gedgo/static/styles/style-default.css b/gedgo/static/styles/style-default.css index 1164e3f..273e3bf 100644 --- a/gedgo/static/styles/style-default.css +++ b/gedgo/static/styles/style-default.css @@ -120,15 +120,17 @@ path { } #worker-section { - min-height: 75px; - + min-height: 150px; } #worker-section p { margin-top: 5px; } -#worker-status { +#worker-status-icon { + display: block; + margin-left: auto; + margin-right: auto; width: 80px; font-size: 40px; color: #fff; @@ -138,6 +140,6 @@ path { border-radius: 10px; /* future proofing */ } -#worker-status span { +#worker-status-icon span { margin-top: 10px; } diff --git a/gedgo/storages.py b/gedgo/storages.py index 413337a..dc15f8c 100644 --- a/gedgo/storages.py +++ b/gedgo/storages.py @@ -108,9 +108,11 @@ def resize_thumb(file_, size='w128h128', crop=None): im.save(output, 'JPEG') return output - research_storage = import_string(settings.GEDGO_RESEARCH_FILE_STORAGE)( location=settings.GEDGO_RESEARCH_FILE_ROOT) gedcom_storage = import_string(settings.GEDGO_GEDCOM_FILE_STORAGE)( location=settings.GEDGO_GEDCOM_FILE_ROOT) + +documentary_storage = import_string(settings.GEDGO_DOCUMENTARY_STORAGE)( + location=settings.GEDGO_DOCUMENTARY_ROOT) diff --git a/gedgo/templates/default/base.html b/gedgo/templates/default/base.html index d3cfc30..f9874a5 100644 --- a/gedgo/templates/default/base.html +++ b/gedgo/templates/default/base.html @@ -5,7 +5,7 @@ - + {% block headappend %}{% endblock %} diff --git a/gedgo/templates/default/blogpost.html b/gedgo/templates/default/blogpost.html index b1295cf..cb4ca30 100644 --- a/gedgo/templates/default/blogpost.html +++ b/gedgo/templates/default/blogpost.html @@ -5,13 +5,17 @@ {% endblock %} {% block leftsidebar %} -{% if post.tagged_photos.all %} - {% for photo in post.tagged_photos.all %} - - - - {% endfor %} -{% endif %} +

Posted: {{ post.created }}

+

Back to the post list

+ + {% if post.tagged_photos.exists %} +
+ {% for photo in post.tagged_photos.all %} + + + + {% endfor %} + {% endif %} {% endblock %} {% block content %} @@ -21,18 +25,17 @@

{{ post.title }}

Edit this post {% endif %} -
- Posted: {{ post.created }}
- Back to the post list -
- - {% if post.tagged_people.all %} + {% if post.tagged_people.exists %}

People in this post:

+
{% for somebody in post.tagged_people.all %} +
{% include "person-card.html" %} - {% if forloop.last %}{% else %}
{% endif %} +
{% endfor %} +
+
{% endif %} diff --git a/gedgo/templates/default/dashboard.html b/gedgo/templates/default/dashboard.html index 573a40e..a9ff142 100644 --- a/gedgo/templates/default/dashboard.html +++ b/gedgo/templates/default/dashboard.html @@ -3,7 +3,8 @@ {% block leftsidebar %}

Worker Status

-
+
+
@@ -80,17 +81,17 @@

User Activity

$('.email_users_checkbox').prop('checked', this.checked); }); $.getJSON('worker/status', function(res) { - var el = $('#worker-status'); - var st = $('#worker-status span'); + var el = $('#worker-status-icon'); + var st = $('#worker-status-icon span'); if (res.length) { el.addClass('bg-success'); st.addClass('glyphicon glyphicon-ok'); $('#submit-gedcom').removeClass("disabled"); - $('#worker-section').append("

Worker is currently availabe to process gedcoms!

"); + $('#worker-status').html("

Worker is currently availabe to process gedcoms!

"); } else { el.addClass('bg-danger'); st.addClass('glyphicon glyphicon-remove'); - $('#worker-section').append("

Worker is currently offline, so gedcom uploads cannot be processed.

"); + $('#worker-status').html("

Worker is currently offline, so gedcom uploads cannot be processed.

"); } }); diff --git a/gedgo/templates/default/documentary_by_id.html b/gedgo/templates/default/documentary_by_id.html index 8723a7e..f103ced 100644 --- a/gedgo/templates/default/documentary_by_id.html +++ b/gedgo/templates/default/documentary_by_id.html @@ -8,17 +8,19 @@

{{ documentary.title }}

{{ documentary.description }}


-

<< back to documentaries

+

Download

+
+

Back to documentaries

{% endblock %} {% block content %} {% if can_video %} - + {% else %}
- +
diff --git a/gedgo/views/dashboard.py b/gedgo/views/dashboard.py index 5ffb494..597a768 100644 --- a/gedgo/views/dashboard.py +++ b/gedgo/views/dashboard.py @@ -96,7 +96,7 @@ def user_tracking(request, user_id): def _handle_upload(request, form): if form.is_valid(): - file_name = 'uploaded/gedcoms/%d_%s' % ( + file_name = 'uploads/gedcoms/%d_%s' % ( time.time(), form.cleaned_data['gedcom_file'].name) default_storage.save(file_name, form.cleaned_data['gedcom_file']) async_update.delay( diff --git a/gedgo/views/media.py b/gedgo/views/media.py index b4742e0..aea5eb9 100644 --- a/gedgo/views/media.py +++ b/gedgo/views/media.py @@ -6,7 +6,7 @@ from django.shortcuts import redirect from gedgo.views.research import can_preview -from gedgo.storages import gedcom_storage, research_storage +from gedgo.storages import gedcom_storage, research_storage, documentary_storage import mimetypes from os import path @@ -14,8 +14,8 @@ sys.stdout = sys.stderr - STORAGES = { + 'documentary': documentary_storage, 'default': default_storage, 'research': research_storage, 'gedcom': gedcom_storage diff --git a/reqs.frozen.pip b/reqs.frozen.pip new file mode 100644 index 0000000..b1bd0c1 --- /dev/null +++ b/reqs.frozen.pip @@ -0,0 +1,31 @@ +amqp==2.2.2 +anyjson==0.3.3 +billiard==3.5.0.3 +celery==4.1.0 +certifi==2018.1.18 +chardet==3.0.4 +configparser==3.5.0 +dj-static==0.0.6 +Django==1.9.2 +dropbox==8.6.0 +enum34==1.1.6 +flake8==3.5.0 +funcsigs==1.0.2 +gunicorn==19.7.1 +idna==2.6 +kombu==4.1.0 +mccabe==0.6.1 +mock==2.0.0 +MySQL-python==1.2.5 +pbr==3.1.1 +Pillow==3.1.1 +pycodestyle==2.3.1 +pyflakes==1.6.0 +pytz==2017.3 +redis==2.10.6 +requests==2.18.4 +six==1.11.0 +static3==0.7.0 +urllib3==1.22 +vine==1.1.4 +virtualenv==15.1.0 diff --git a/reqs.pip b/reqs.pip index 20a48ce..3b4c884 100644 --- a/reqs.pip +++ b/reqs.pip @@ -1,6 +1,8 @@ django==1.9.2 celery==4.1.0 pillow==3.1.1 +dj-static==0.0.6 +gunicorn anyjson dropbox mysql-python diff --git a/settings.py b/settings.py index af2fef6..939ff33 100644 --- a/settings.py +++ b/settings.py @@ -32,7 +32,7 @@ MEDIA_ROOT = '/app/files/default/' MEDIA_URL = '/gedgo/media/default/' -STATIC_ROOT = '' +STATIC_ROOT = '/static/' STATIC_URL = '/static/' STATICFILES_FINDERS = ( @@ -78,8 +78,7 @@ ) ROOT_URLCONF = 'urls' -# WSGI_APPLICATION = 'wsgi.application' - +WSGI_APPLICATION = 'wsgi.application' INSTALLED_APPS = ( 'django.contrib.auth', @@ -116,6 +115,8 @@ GEDGO_REDIS_SERVER = 'redis' GEDGO_RESEARCH_FILE_STORAGE = 'gedgo.storages.FileSystemSearchableStorage' GEDGO_RESEARCH_FILE_ROOT = '/app/files/gedcom/' +GEDGO_DOCUMENTARY_STORAGE = 'gedgo.storages.FileSystemSearchableStorage' +GEDGO_DOCUMENTARY_ROOT = '/app/files/documentaries/' GEDGO_GEDCOM_FILE_STORAGE = 'gedgo.storages.FileSystemSearchableStorage' GEDGO_GEDCOM_FILE_ROOT = '/app/files/research/' GEDGO_SHOW_RESEARCH_FILES = True diff --git a/wsgi.py b/wsgi.py new file mode 100644 index 0000000..6205d83 --- /dev/null +++ b/wsgi.py @@ -0,0 +1,7 @@ +import os +from django.core.wsgi import get_wsgi_application +from dj_static import Cling + +os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' + +application = Cling(get_wsgi_application())