From 9faf03f1e7e5720ec8ec892d0c39d62d6593f07b Mon Sep 17 00:00:00 2001 From: Oliver Marks Date: Wed, 1 Feb 2017 22:26:13 +0000 Subject: [PATCH] initial docker setup for staging now works --- compose/django/Dockerfile | 4 +- compose/django/gunicorn.sh | 3 ++ compose/nginx/nginx.conf | 15 ++++---- config/settings/common.py | 3 +- config/settings/production.py | 3 ++ docker-compose.yml | 23 ++++++++++-- live.yml | 55 ++++++++++++++++++++++++++++ mhackspace/subscriptions/payments.py | 2 - mhackspace/templates/base.html | 15 +++++++- requirements/base.txt | 5 +-- staticfiles/staticfiles | 0 11 files changed, 109 insertions(+), 19 deletions(-) create mode 100644 live.yml create mode 100644 staticfiles/staticfiles diff --git a/compose/django/Dockerfile b/compose/django/Dockerfile index a198604..b26d2fd 100644 --- a/compose/django/Dockerfile +++ b/compose/django/Dockerfile @@ -11,6 +11,7 @@ RUN pip install -r /requirements/production.txt \ COPY . /app RUN chown -R django /app +RUN mkdir -p /data/sockets COPY ./compose/django/gunicorn.sh /gunicorn.sh COPY ./compose/django/entrypoint.sh /entrypoint.sh @@ -19,7 +20,8 @@ RUN sed -i 's/\r//' /entrypoint.sh \ && chmod +x /entrypoint.sh \ && chown django /entrypoint.sh \ && chmod +x /gunicorn.sh \ - && chown django /gunicorn.sh + && chown django /gunicorn.sh \ + && chown django /data/sockets WORKDIR /app diff --git a/compose/django/gunicorn.sh b/compose/django/gunicorn.sh index 21f8633..52c50ca 100644 --- a/compose/django/gunicorn.sh +++ b/compose/django/gunicorn.sh @@ -1,3 +1,6 @@ #!/bin/sh python /app/manage.py collectstatic --noinput +chmod 777 -R /data/sockets/ +touch /data/sockets/gunicron.sock +ls -la /data/sockets/ /usr/local/bin/gunicorn config.wsgi -w 4 -b unix:/data/sockets/gunicorn.sock --chdir=/app diff --git a/compose/nginx/nginx.conf b/compose/nginx/nginx.conf index 3b9d2a3..a200939 100644 --- a/compose/nginx/nginx.conf +++ b/compose/nginx/nginx.conf @@ -26,7 +26,8 @@ http { #gzip on; upstream app { - server django:5000; + #server django:5000; + server unix:/data/sockets/gunicorn.sock; } server { @@ -36,12 +37,12 @@ http { server_name ___my.example.com___ ; - location /.well-known/acme-challenge { - proxy_pass http://certbot:80; - proxy_set_header Host $host; - proxy_set_header X-Forwarded-For $remote_addr; - proxy_set_header X-Forwarded-Proto https; - } +# location /.well-known/acme-challenge { +# proxy_pass http://certbot:80; +# proxy_set_header Host $host; +# proxy_set_header X-Forwarded-For $remote_addr; +# proxy_set_header X-Forwarded-Proto https; +# } location / { diff --git a/config/settings/common.py b/config/settings/common.py index 2e505d0..d60d0f3 100644 --- a/config/settings/common.py +++ b/config/settings/common.py @@ -189,6 +189,7 @@ STATICFILES_DIRS = ( STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder', + 'sass_processor.finders.CssFinder', ) # MEDIA CONFIGURATION @@ -252,7 +253,7 @@ LOGIN_URL = 'account_login' AUTOSLUG_SLUGIFY_FUNCTION = 'slugify.slugify' # django-compressor # ------------------------------------------------------------------------------ -INSTALLED_APPS += ("compressor", ) +INSTALLED_APPS += ("compressor", 'sass_processor',) STATICFILES_FINDERS += ("compressor.finders.CompressorFinder", ) # Location of root django.contrib.admin URL, use {% url 'admin:index' %} diff --git a/config/settings/production.py b/config/settings/production.py index e8d8d20..5ab3a21 100644 --- a/config/settings/production.py +++ b/config/settings/production.py @@ -56,6 +56,9 @@ X_FRAME_OPTIONS = 'DENY' # Hosts/domain names that are valid for this site # See https://docs.djangoproject.com/en/1.6/ref/settings/#allowed-hosts ALLOWED_HOSTS = env.list('DJANGO_ALLOWED_HOSTS', default=['maidstone-hackspace.org.uk']) +ALLOWED_HOSTS.append('172.*') +ALLOWED_HOSTS.append('172.18.0.5') + # END SITE CONFIGURATION INSTALLED_APPS += ('gunicorn', ) diff --git a/docker-compose.yml b/docker-compose.yml index 3e77fa4..99d65fc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,9 +1,20 @@ version: '2' volumes: - gunicorn_socket: {} - postgres_data: {} - postgres_backup: {} + gunicorn_socket: + driver: local + postgres_data: + driver: local + postgres_backup: + driver: local + + +# volumes: +# sockets: +# driver: local +# data: +# driver: local + services: postgres: @@ -25,10 +36,11 @@ services: env_file: .env volumes: - .:/app - - gunicorn_socket:/data/sockets/ + - gunicorn_socket:/data/sockets nginx: build: ./compose/nginx + env_file: .env depends_on: - django # - certbot @@ -37,6 +49,9 @@ services: - MY_DOMAIN_NAME=maidstone-hackspace.org.uk ports: - "0.0.0.0:80:80" + volumes: + - .:/app + - gunicorn_socket:/data/sockets # - "0.0.0.0:443:443" # volumes: # - /etc/letsencrypt:/etc/letsencrypt diff --git a/live.yml b/live.yml new file mode 100644 index 0000000..09566d7 --- /dev/null +++ b/live.yml @@ -0,0 +1,55 @@ +version: '2' + +volumes: + gunicorn_socket: {} + postgres_data_dev: {} + postgres_backup_dev: {} + +services: + postgres: + build: ./compose/postgres + volumes: + - postgres_data_dev:/var/lib/postgresql/data + - postgres_backup_dev:/backups + # environment: + # - POSTGRES_USER=${POSTGRES_USER} + env_file: .env + + django: + build: + context: . + dockerfile: ./compose/django/Dockerfile + command: /start-dev.sh + depends_on: + - postgres + environment: + - POSTGRES_USER=${POSTGRES_USER} + - USE_DOCKER=yes + volumes: + - .:/app + - gunicorn_socket:/var/run/gunicorn/ + ports: + - "8180:8000" + links: + - postgres + - mailhog + + nginx: + build: ./compose/nginx + depends_on: + - django + environment: + - MY_DOMAIN_NAME=maidstone-hackspace.org.uk + ports: + - "0.0.0.0:80:80" + # - "0.0.0.0:443:443" + volumes: + - gunicorn_socket:/var/run/gunicorn/ + + mailhog: + image: mailhog/mailhog + ports: + - "8125:8025" + + redis: + image: redis:latest diff --git a/mhackspace/subscriptions/payments.py b/mhackspace/subscriptions/payments.py index 26ff92e..a92bc78 100644 --- a/mhackspace/subscriptions/payments.py +++ b/mhackspace/subscriptions/payments.py @@ -369,9 +369,7 @@ class payment: confirm_details['successfull'] = False print('---------------------') print(args) - - from pprint import pprint if self.provider == 'paypal': print(args.get('paymentId')) diff --git a/mhackspace/templates/base.html b/mhackspace/templates/base.html index 2751ea0..1aa9239 100644 --- a/mhackspace/templates/base.html +++ b/mhackspace/templates/base.html @@ -91,8 +91,21 @@ +
- {% if messages %} {% for message in messages %}
{{ message }}
diff --git a/requirements/base.txt b/requirements/base.txt index 25779a5..078f3aa 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -42,10 +42,9 @@ django-redis==4.7.0 redis>=2.10.5 - - -rcssmin==1.0.6 +rcssmin==1.0.6 django-compressor==2.1 +django-sass-processor lxml==3.7.2 mock diff --git a/staticfiles/staticfiles b/staticfiles/staticfiles new file mode 100644 index 0000000..e69de29