Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
venv/
.idea/
.github/
41 changes: 41 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

version: '3.7'

services:
web:
build:
context: .
dockerfile: ./packaging/cypetulip/Dockerfile
working_dir: /opt/cypetulip
command: daphne -b 0.0.0.0 -p 8000 home.asgi:application
volumes:
- .:/opt/cypetulip
- static_volume:/var/cypetulip/static:rw
- media_volume:/var/cypetulip/media:rw
expose:
- 8000
env_file:
- ./packaging/cypetulip/.env.cypetulip.prod
depends_on:
- redis
links:
- redis
nginx:
build:
context: ./packaging/nginx
dockerfile: Dockerfile
env_file:
- ./packaging/nginx/.env.nginx.prod
volumes:
- static_volume:/var/cypetulip/static:ro
ports:
- 80:80
depends_on:
- web
redis:
image: redis
ports:
- "6379:6379"
volumes:
static_volume:
media_volume:
3 changes: 2 additions & 1 deletion management/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class ManagementConfig(AppConfig):

def ready(self):
try:
from management.models import CacheSetting
from management.models import CacheSetting, LegalSetting
cache_settings,_ = CacheSetting.objects.get_or_create()
legal_settings,_ = LegalSetting.objects.get_or_create()
except :
pass
13 changes: 13 additions & 0 deletions packaging/cypetulip/.env.cypetulip.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
REDIS_HOST=redis
DEBUG=1
SECRET_KEY=foo
DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 [::1]
CACHE_MIDDLEWARE_SECONDS = 600
SESSION_COOKIE_AGE = 604800

#SQL_ENGINE=django.db.backends.postgresql
#SQL_DATABASE=hello_django_dev
#SQL_USER=hello_django
#SQL_PASSWORD=hello_django
#SQL_HOST=db
#SQL_PORT=5432
73 changes: 73 additions & 0 deletions packaging/cypetulip/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
FROM python:3.8.3


ENV HOME=/opt/cypetulip/

RUN adduser app && adduser app app
# Install packages needed to run your application (not build deps):
# mime-support -- for mime types when serving static files
# postgresql-client -- for running database commands
# We need to recreate the /usr/share/man/man{1..8} directories first because
# they were clobbered by a parent image.
RUN set -ex \
&& RUN_DEPS=" \
libpcre3 \
mime-support \
postgresql-client \
gettext \
" \
&& seq 1 8 | xargs -I{} mkdir -p /usr/share/man/man{} \
&& apt-get update && apt-get install -y --no-install-recommends $RUN_DEPS \
&& rm -rf /var/lib/apt/lists/*

# Copy in your requirements file
COPY requirements.txt requirements.txt

# OR, if you're using a directory for your requirements, copy everything (comment out the above and uncomment this if so):
# ADD requirements /requirements

# Install build deps, then run `pip install`, then remove unneeded build deps all in a single step.
# Correct the path to your production requirements file, if needed.
RUN set -ex \
&& BUILD_DEPS=" \
build-essential \
libpcre3-dev \
libpq-dev \
" \
&& apt-get update && apt-get install -y --no-install-recommends $BUILD_DEPS \
&& pip install --no-cache-dir -r /requirements.txt \
\
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false $BUILD_DEPS \
&& rm -rf /var/lib/apt/lists/*


COPY ./packaging/cypetulip/local_settings.py /etc/cypetulip/

# todo cron.d
# todo fix permissions on shared volumes so it can be run as app:app
# test deploy

# Copy your application code to the container (make sure you create a .dockerignore file if any large files or directories should be excluded)

WORKDIR /opt/cypetulip/
COPY . /opt/cypetulip/

ADD https://github.com/sass/dart-sass/releases/download/1.32.2/dart-sass-1.32.2-linux-x64.tar.gz /tmp/dart-sass/
RUN tar -xf /tmp/dart-sass/dart-sass-1.32.2-linux-x64.tar.gz -C /opt/
#RUN wget https://github.com/sass/dart-sass/releases/download/1.32.2/dart-sass-1.32.2-linux-x64.tar.gz && tar -xf dart-sass-1.32.2-linux-x64.tar.gz


COPY ./packaging/cypetulip/entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/entrypoint.sh

RUN pip install -r /opt/cypetulip/requirements.txt


RUN mkdir /var/cypetulip/
RUN mkdir /var/cypetulip/static
RUN mkdir /var/cypetulip/media
RUN chown -R app:app /var/cypetulip
RUN chown -R app:app /opt/cypetulip

USER app
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
9 changes: 9 additions & 0 deletions packaging/cypetulip/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

#chown -R app:app /opt/cypetulip
#chown -R app:app /var/cypetulip
python manage.py migrate
python manage.py createcachetable
python manage.py compilemessages --ignore=venv/*
python manage.py collectstatic --noinput
daphne -b 0.0.0.0 -p 8000 home.asgi:application
30 changes: 30 additions & 0 deletions packaging/cypetulip/local_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import os

from home.settings import BASE_DIR

COMPRESS_PRECOMPILERS = (
('text/x-scss', '/opt/dart-sass/sass {infile} {outfile}'),
)
COMPRESS_CACHE_BACKEND = "default"
COMPRESS_CACHEABLE_PRECOMPILERS = ['text/x-scss']
SESSION_COOKIE_AGE= int(os.environ.get("SESSION_COOKIE_AGE", default=604800))
CACHE_MIDDLEWARE_SECONDS = int(os.environ.get("CACHE_MIDDLEWARE_SECONDS", default=600)) # number of seconds to cache a page for (TTL)

DATABASES = {
'default': {
"ENGINE": os.environ.get("SQL_ENGINE", "django.db.backends.sqlite3"),
"NAME": os.environ.get("SQL_DATABASE", os.path.join(BASE_DIR, "db2.sqlite3")),
"USER": os.environ.get("SQL_USER", "user"),
"PASSWORD": os.environ.get("SQL_PASSWORD", "password"),
"HOST": os.environ.get("SQL_HOST", "localhost"),
"PORT": os.environ.get("SQL_PORT", "5432"),
}
}

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get("SECRET_KEY")

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = int(os.environ.get("DEBUG", default=0))

ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS").split(" ")
2 changes: 2 additions & 0 deletions packaging/nginx/.env.nginx.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NGINX_HOST=localhost
NGINX_PORT=80
4 changes: 4 additions & 0 deletions packaging/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM nginx
RUN rm /etc/nginx/conf.d/default.conf

COPY cypetulip.conf /etc/nginx/conf.d
58 changes: 58 additions & 0 deletions packaging/nginx/cypetulip.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
map $sent_http_content_type $expires {
default off;
# text/html 24h;
text/css 365d;
application/javascript 365d;
~image/ 365d;
application/octet-stream 365d;
}

upstream cypetulip {
server web:8000;
}

server {
listen 80;

client_max_body_size 100M;

expires $expires;

gzip on;
gzip_disable "msie6";

gzip_comp_level 6;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_proxied any;
gzip_types
text/plain
text/css
text/js
text/xml
text/javascript
application/javascript
application/json
application/xml
application/rss+xml
image/svg+xml
application/octet-stream;

location / {
proxy_pass http://cypetulip;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection “upgrade”;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}

location /static {
autoindex on;
alias /var/cypetulip/static;
}

}
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,6 @@ paypalhttp==1.0.0
paypal-checkout-serversdk==1.0.1
django-cookiebanner==0.2.2
csscompressor==0.9.5
django-compressor==2.4
django-compressor==2.4
django-recaptcha==2.0.6
daphne==3.0.1