From 43a98f71644b499de55619a19dfeb4c474b85580 Mon Sep 17 00:00:00 2001 From: Oliver Marks Date: Tue, 30 Jan 2018 14:19:39 +0000 Subject: [PATCH] Sass fix for permissions --- compose/django/Dockerfile-dev | 8 +++++ compose/django/bjoern.py | 42 +++++++++++++++++++++++ compose/django/dev-gunicorn-mhackspace.sh | 2 +- config/settings/common.py | 3 +- config/settings/local.py | 6 ++-- config/wsgi.py | 9 +++-- local.yml | 3 +- mhackspace/core/storage.py | 6 ++++ requirements/base.txt | 2 ++ 9 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 compose/django/bjoern.py create mode 100644 mhackspace/core/storage.py diff --git a/compose/django/Dockerfile-dev b/compose/django/Dockerfile-dev index 25d1394..147d8d2 100644 --- a/compose/django/Dockerfile-dev +++ b/compose/django/Dockerfile-dev @@ -1,10 +1,17 @@ +#FROM python:3.6-alpine FROM python:3.6 ENV PYTHONUNBUFFERED 1 +#RUN apk add --no-cache libev-dev git postgresql-dev gcc python3-dev musl-dev + +#RUN apt update +#RUN apt install -y libev-dev libevdev2 git python3-dev + # Requirements have to be pulled and installed here, otherwise caching won't work COPY ./requirements /requirements + RUN pip install --cache-dir ./cache/pip -r /requirements/local.txt \ && groupadd -r django \ && useradd -r -g django django @@ -20,6 +27,7 @@ RUN mkdir -p /var/log/gunicorn/ \ COPY ./compose/django/dev-gunicorn-mhackspace.sh /dev-gunicorn-mhackspace.sh COPY ./compose/django/live-gunicorn-mhackspace.sh /live-gunicorn-mhackspace.sh COPY ./compose/django/stage-gunicorn-mhackspace.sh /stage-gunicorn-mhackspace.sh +COPY ./compose/django/bjoern.py /bjoern.py COPY ./compose/django/entrypoint.sh /entrypoint.sh RUN sed -i 's/\r//' /entrypoint.sh \ && sed -i 's/\r//' /stage-gunicorn-mhackspace.sh \ diff --git a/compose/django/bjoern.py b/compose/django/bjoern.py new file mode 100644 index 0000000..1a8568e --- /dev/null +++ b/compose/django/bjoern.py @@ -0,0 +1,42 @@ +""" +WSGI config for Maidstone Hackspace project. + +This module contains the WSGI application used by Django's development server +and any production WSGI deployments. It should expose a module-level variable +named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover +this application via the ``WSGI_APPLICATION`` setting. + +Usually you will have the standard Django WSGI application here, but it also +might make sense to replace the whole Django WSGI application with a custom one +that later delegates to the Django one. For example, you could introduce WSGI +middleware here, or combine a Django application with an application of another +framework. + +""" +import os +import bjoern + +from django.core.wsgi import get_wsgi_application + +# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks +# if running multiple sites in the same mod_wsgi process. To fix this, use +# mod_wsgi daemon mode with each site in its own daemon process, or use +# os.environ["DJANGO_SETTINGS_MODULE"] = "config.settings.production" +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.production") + +# This application object is used by any WSGI server configured to use this +# file. This includes Django's development server, if the WSGI_APPLICATION +# setting points here. +application = get_wsgi_application() + +# Apply WSGI middleware here. +# from helloworld.wsgi import HelloWorldApplication +# application = HelloWorldApplication(application) +# apply Werkzeug WSGI middleware +# if os.environ.setdefault('DJANGO_DEBUG', 'False') is True: +from werkzeug.debug import DebuggedApplication +# application.wsgi_app = DebuggedApplication(application.wsgi_app, evalex=True) +application = DebuggedApplication(application, evalex=True, pin_security=True) +application.debug = True + +bjoern.run(application, 'unix:/data/sockets/bjoern-mhackspace.sock') diff --git a/compose/django/dev-gunicorn-mhackspace.sh b/compose/django/dev-gunicorn-mhackspace.sh index a1782e5..2092fa3 100755 --- a/compose/django/dev-gunicorn-mhackspace.sh +++ b/compose/django/dev-gunicorn-mhackspace.sh @@ -2,4 +2,4 @@ #python /app/manage.py collectstatic --noinput #python /app/manage.py compilescss -/usr/local/bin/gunicorn config.wsgi -w 2 -b unix:/data/sockets/dev-gunicorn-mhackspace.sock --reload --chdir=/app +/usr/local/bin/gunicorn config.wsgi -w 1 -b unix:/data/sockets/dev-gunicorn-mhackspace.sock --reload --chdir=/app diff --git a/config/settings/common.py b/config/settings/common.py index 2d8a916..d9e9d63 100644 --- a/config/settings/common.py +++ b/config/settings/common.py @@ -446,7 +446,8 @@ PAYMENT_PROVIDERS = { } SASS_PRECISION = 8 - +# Important this fixes permission issues by compiling in a temporary folder, instead of inside your project +SASS_PROCESSOR_ROOT = os.path.join('/tmp', 'sass') SASS_PROCESSOR_INCLUDE_DIRS = [ str(APPS_DIR) + '/static/sass', str(ROOT_DIR) + '/node_modules', diff --git a/config/settings/local.py b/config/settings/local.py index 6295afc..538bebc 100644 --- a/config/settings/local.py +++ b/config/settings/local.py @@ -17,7 +17,7 @@ from .common import * # noqa # DEBUG # ------------------------------------------------------------------------------ DEBUG = env.bool('DJANGO_DEBUG', default=True) - +DEBUG = True TEMPLATES[0]['OPTIONS']['debug'] = DEBUG # SECRET CONFIGURATION @@ -169,7 +169,9 @@ AWS_S3_OBJECT_PARAMETERS = { AWS_LOCATION = 'dev' AWS_S3_SECURE_URLS = True STATIC_URL = '%s/%s/' % (AWS_S3_ENDPOINT_URL, AWS_STORAGE_BUCKET_NAME) -STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage' + + +STATICFILES_STORAGE = 'mhackspace.core.storage.SassStorageFix' # COMPRESSOR # ------------------------------------------------------------------------------ diff --git a/config/wsgi.py b/config/wsgi.py index 9d177e9..212b444 100644 --- a/config/wsgi.py +++ b/config/wsgi.py @@ -32,6 +32,9 @@ application = get_wsgi_application() # from helloworld.wsgi import HelloWorldApplication # application = HelloWorldApplication(application) # apply Werkzeug WSGI middleware -if os.environ.setdefault('DEBUG', 'False') is True: - from werkzeug.debug import DebuggedApplication - application = DebuggedApplication(application, evalex=True) +# if os.environ.setdefault('DJANGO_DEBUG', 'False') is True: +from werkzeug.debug import DebuggedApplication +# application.wsgi_app = DebuggedApplication(application.wsgi_app, evalex=True) +application = DebuggedApplication(application, evalex=True, pin_security=True) +application.debug = True + diff --git a/local.yml b/local.yml index a16fde7..16c7d68 100644 --- a/local.yml +++ b/local.yml @@ -31,6 +31,7 @@ services: depends_on: - postgres # - redis + # command: python /bjorne.py command: /dev-gunicorn-mhackspace.sh env_file: .env volumes: @@ -76,4 +77,4 @@ services: env_file: .env volumes: - ./mhackspace:/data - command: server /data + command: server --config-dir /tmp/minio /data diff --git a/mhackspace/core/storage.py b/mhackspace/core/storage.py new file mode 100644 index 0000000..4563e25 --- /dev/null +++ b/mhackspace/core/storage.py @@ -0,0 +1,6 @@ +from storages.backends.s3boto3 import S3Boto3Storage +from django.conf import settings + + +class SassStorageFix(S3Boto3Storage): + base_url = settings.AWS_S3_ENDPOINT_URL diff --git a/requirements/base.txt b/requirements/base.txt index 7115af0..bfd017a 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -60,6 +60,8 @@ lxml==3.7.3 # ------------------------------------------------ gevent==1.2.2 gunicorn==19.7.1 +#https://github.com/jonashaag/bjoern +#bjoern # Your custom requirements go here mock==2.0.0