├── .gitignore ├── {{cookiecutter.project_slug}} ├── web │ ├── {{cookiecutter.project_slug}} │ │ ├── __init__.py │ │ ├── migrations │ │ │ └── __init__.py │ │ ├── static │ │ │ └── {{cookiecutter.project_slug}} │ │ │ │ ├── .gitkeep │ │ │ │ └── css │ │ │ │ └── style.css │ │ ├── .models.py.swp │ │ ├── wsgi.py │ │ ├── templates │ │ │ ├── page.html │ │ │ ├── feature.html │ │ │ ├── menu.html │ │ │ └── base.html │ │ ├── cms_plugins.py │ │ ├── models.py │ │ ├── urls.py │ │ └── settings.py │ ├── project.db │ ├── config.ini │ ├── entrypoint.sh │ ├── Dockerfile │ ├── requirements.txt │ ├── manage.py │ └── run_server.sh ├── nginx │ ├── Dockerfile │ └── nginx.conf ├── .env.dev ├── db │ ├── entrypoint.sh │ ├── list-backups.sh │ ├── Dockerfile │ ├── backup.sh │ └── restore.sh ├── .env.example ├── .editorconfig ├── docker-compose-dev.yml ├── docker-compose-prod.yml ├── README.md └── LICENSE ├── cookiecutter.json ├── README.md └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | .bash_history 2 | -------------------------------------------------------------------------------- /{{cookiecutter.project_slug}}/web/{{cookiecutter.project_slug}}/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /{{cookiecutter.project_slug}}/web/{{cookiecutter.project_slug}}/migrations/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /{{cookiecutter.project_slug}}/web/{{cookiecutter.project_slug}}/static/{{cookiecutter.project_slug}}/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /{{cookiecutter.project_slug}}/web/{{cookiecutter.project_slug}}/static/{{cookiecutter.project_slug}}/css/style.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /{{cookiecutter.project_slug}}/web/project.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/altryne/cookiecutter-django-cms-docker/master/{{cookiecutter.project_slug}}/web/project.db -------------------------------------------------------------------------------- /{{cookiecutter.project_slug}}/nginx/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM nginx:1.13 2 | ENV BUILD_TIMESTAMP 2017-09-12T:12:00 3 | RUN rm /etc/nginx/conf.d/default.conf 4 | ADD ./nginx.conf /etc/nginx/conf.d/nginx.conf 5 | -------------------------------------------------------------------------------- /{{cookiecutter.project_slug}}/web/{{cookiecutter.project_slug}}/.models.py.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/altryne/cookiecutter-django-cms-docker/master/{{cookiecutter.project_slug}}/web/{{cookiecutter.project_slug}}/.models.py.swp -------------------------------------------------------------------------------- /{{cookiecutter.project_slug}}/.env.dev: -------------------------------------------------------------------------------- 1 | DEBUG=True 2 | SECRET_KEY=asecretkey 3 | DB_NAME={{cookiecutter.project_slug}}_db 4 | DB_USER={{cookiecutter.project_slug}} 5 | DB_PASS=1234 6 | DB_HOST=db 7 | DB_PORT=5432 8 | ALLOWED_HOSTS=localhost 9 | -------------------------------------------------------------------------------- /{{cookiecutter.project_slug}}/db/entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/env bash 2 | psql -U postgres -c "CREATE USER $DB_USER WITH PASSWORD '$DB_PASS'" 3 | psql -U postgres -c "ALTER USER $DB_USER SUPERUSER;" 4 | psql -U postgres -c "CREATE DATABASE $DB_NAME OWNER $DB_USER" 5 | -------------------------------------------------------------------------------- /{{cookiecutter.project_slug}}/db/list-backups.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -o errexit 4 | set -o pipefail 5 | set -o nounset 6 | 7 | 8 | echo "listing available backups" 9 | echo "-------------------------" 10 | ls -lt /backups | awk '{print $6, $7, $8, $9}' 11 | -------------------------------------------------------------------------------- /{{cookiecutter.project_slug}}/web/{{cookiecutter.project_slug}}/wsgi.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from django.core.wsgi import get_wsgi_application 4 | 5 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{cookiecutter.project_slug}}.settings") 6 | 7 | application = get_wsgi_application() 8 | -------------------------------------------------------------------------------- /{{cookiecutter.project_slug}}/web/{{cookiecutter.project_slug}}/templates/page.html: -------------------------------------------------------------------------------- 1 | {% raw %}{% extends "base.html" %} 2 | {% load cms_tags %} 3 | 4 | {% block title %}{% page_attribute "page_title" %}{% endblock title %} 5 | 6 | {% block content %} 7 | {% placeholder "content" %} 8 | {% endblock content %}{% endraw %} 9 | -------------------------------------------------------------------------------- /{{cookiecutter.project_slug}}/db/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM postgres:9.6 2 | ADD ./entrypoint.sh /docker-entrypoint-initdb.d/ 3 | 4 | COPY ./backup.sh /usr/local/bin/backup 5 | RUN chmod +x /usr/local/bin/backup 6 | 7 | COPY ./restore.sh /usr/local/bin/restore 8 | RUN chmod +x /usr/local/bin/restore 9 | 10 | COPY ./list-backups.sh /usr/local/bin/list-backups 11 | RUN chmod +x /usr/local/bin/list-backups 12 | -------------------------------------------------------------------------------- /{{cookiecutter.project_slug}}/web/{{cookiecutter.project_slug}}/templates/feature.html: -------------------------------------------------------------------------------- 1 | {% raw %}{% extends "base.html" %} 2 | {% load cms_tags %} 3 | 4 | {% block title %}{% page_attribute "page_title" %}{% endblock title %} 5 | 6 | {% block content %} 7 |
8 | {% placeholder "feature" %} 9 |
10 |
11 | {% placeholder "content" %} 12 |
13 | {% endblock content %}{% endraw %} -------------------------------------------------------------------------------- /{{cookiecutter.project_slug}}/.env.example: -------------------------------------------------------------------------------- 1 | DEBUG=False # This should stay untouched 2 | SECRET_KEY= # choose a secret 3 | DB_NAME={{cookiecutter.project_slug}}_db # This should stay untouched 4 | DB_USER={{cookiecutter.project_slug}} # This should stay untouched 5 | DB_PASS= # choose a db password 6 | DB_HOST=db # This should stay untouched 7 | DB_PORT=5432 # This should stay untouched 8 | ALLOWED_HOSTS= # choose allowed hosts - could be many in coma separated list 9 | -------------------------------------------------------------------------------- /{{cookiecutter.project_slug}}/.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | charset = utf-8 7 | end_of_line = lf 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.{py,rst,ini}] 12 | indent_style = space 13 | indent_size = 4 14 | 15 | [*.{html,css,scss,json,yml}] 16 | indent_style = space 17 | indent_size = 2 18 | 19 | [*.md] 20 | trim_trailing_whitespace = false 21 | 22 | [Makefile] 23 | indent_style = tab 24 | 25 | [nginx.conf] 26 | indent_style = space 27 | indent_size = 2 28 | -------------------------------------------------------------------------------- /cookiecutter.json: -------------------------------------------------------------------------------- 1 | { 2 | "project_name": "Project Name", 3 | "project_slug": "{{ cookiecutter.project_name.lower()|replace(' ', '_')|replace('-', '_') }}", 4 | "author_name": "Rafal Gumienny", 5 | "github_user": "{{ cookiecutter.author_name.lower()|replace(' ', '_')|replace('-', '_') }}", 6 | "email": "you@example.com", 7 | "description": "A short description of the project.", 8 | "domain_name": "example.com", 9 | "timezone": "'Europe/Warsaw'", 10 | "open_source_license": ["MIT", "BSD", "GPLv3", "Apache Software License 2.0", "Not open source"] 11 | } 12 | -------------------------------------------------------------------------------- /{{cookiecutter.project_slug}}/web/config.ini: -------------------------------------------------------------------------------- 1 | [djangocms_installer] 2 | db = sqlite://localhost/project.db 3 | use-tz = yes 4 | timezone = 5 | utc = true 6 | reversion = no 7 | permissions = yes 8 | i18n = no 9 | django-version = stable 10 | cms-version = stable 11 | parent-dir = . 12 | pip-options = 13 | bootstrap = yes 14 | templates = no 15 | starting-page = no 16 | list-plugins = false 17 | dump-requirements = false 18 | no-input = false 19 | filer = true 20 | requirements = 21 | no-deps = false 22 | no-db-driver = false 23 | no-sync = false 24 | no-user = false 25 | template = 26 | extra-settings = 27 | skip-empty-check = true 28 | -------------------------------------------------------------------------------- /{{cookiecutter.project_slug}}/web/{{cookiecutter.project_slug}}/cms_plugins.py: -------------------------------------------------------------------------------- 1 | from cms.plugin_base import CMSPluginBase 2 | from cms.plugin_pool import plugin_pool 3 | from django.utils.translation import ugettext_lazy as _ 4 | 5 | # from .models import ExampleModel 6 | 7 | # class ExamplePlugin(CMSPluginBase): 8 | # model = ExampleModel 9 | # name = _("Example Plugin") 10 | # render_template = "example_plugin.html" 11 | # cache = False 12 | 13 | # def render(self, context, instance, placeholder): 14 | # context = super(TeamCardPlugin, self).render(context, instance, placeholder) 15 | # return context 16 | 17 | # plugin_pool.register_plugin(ExamplePlugin) 18 | -------------------------------------------------------------------------------- /{{cookiecutter.project_slug}}/web/{{cookiecutter.project_slug}}/models.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """Models""" 3 | from django.db import models 4 | from django.utils.translation import ugettext, ugettext_lazy as _ 5 | 6 | from cms.models import CMSPlugin 7 | 8 | from filer.fields.image import FilerImageField 9 | from django.utils.encoding import python_2_unicode_compatible 10 | 11 | # @python_2_unicode_compatible 12 | # class ExampleModel(CMSPlugin): 13 | # """Renders a card with a team member.""" 14 | # name = models.CharField( 15 | # max_length=100, 16 | # verbose_name=_('Name'), 17 | # blank=True, 18 | # help_text=_('Provide a name of the team member.') 19 | # ) 20 | -------------------------------------------------------------------------------- /{{cookiecutter.project_slug}}/nginx/nginx.conf: -------------------------------------------------------------------------------- 1 | server { 2 | 3 | listen 80; 4 | server_name {{cookiecutter.domain_name}}; 5 | charset utf-8; 6 | client_max_body_size 10M; 7 | access_log /var/log/nginx/access_{{cookiecutter.project_slug}}.log; 8 | error_log /var/log/nginx/error_{{cookiecutter.project_slug}}.log info; 9 | 10 | location /media { 11 | alias /public/media; 12 | } 13 | 14 | location /static { 15 | alias /public/static; 16 | } 17 | 18 | location / { 19 | proxy_pass http://web:8000; 20 | proxy_set_header Host $host; 21 | proxy_set_header X-Real-IP $remote_addr; 22 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Cookiecutter Django CMS with Docker support 2 | =========================================== 3 | 4 | This cookiecutter provides a production ready Django CMS template 5 | using Docker. 6 | 7 | Features 8 | --------- 9 | 10 | * For Django 1.9 11 | * Twitter Bootstrap_ v3 12 | * Docker support by docker-compose_ for development and production 13 | * Easy backup of DB and Media files 14 | 15 | Usage 16 | ----- 17 | 18 | Install cookiecutter:: 19 | 20 | $ pip install cookiecutter>=1.6.0 21 | 22 | Run cookiecutter against repo:: 23 | 24 | $ cookiecutter https://github.com/guma44/cookiecutter-django-cms-docker 25 | 26 | Provide the values that will be promped and the project will be created for you. 27 | 28 | See the generated README.md file in the project directory for the details how to run 29 | and set up the CMS. 30 | -------------------------------------------------------------------------------- /{{cookiecutter.project_slug}}/web/entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -o errexit 4 | set -o pipefail 5 | 6 | # the official postgres image uses 'postgres' as default user if not set explictly. 7 | if [ -z "$DB_USER" ]; then 8 | export DB_USER=postgres 9 | fi 10 | 11 | export DATABASE_URL=$DB_HOST://$DB_USER:$DB_PASS@$DB_HOST:$DB_PORT/$DB_USER 12 | 13 | 14 | function postgres_ready(){ 15 | python << END 16 | import sys 17 | import psycopg2 18 | try: 19 | conn = psycopg2.connect(dbname="$DB_NAME", user="$DB_USER", password="$DB_PASS", host="$DB_HOST") 20 | except psycopg2.OperationalError: 21 | sys.exit(-1) 22 | sys.exit(0) 23 | END 24 | } 25 | 26 | until postgres_ready; do 27 | >&2 echo "Postgres is unavailable - sleeping" 28 | sleep 1 29 | done 30 | 31 | >&2 echo "Postgres is up - continuing..." 32 | 33 | exec "$@" -------------------------------------------------------------------------------- /{{cookiecutter.project_slug}}/web/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.6 2 | 3 | ENV BUILD_TIMESTAMP 2017-10-14:17:11:14 4 | 5 | ENV PYTHONUNBUFFERED 1 6 | 7 | RUN groupadd -r django && useradd -r -g django django 8 | 9 | RUN mkdir -p /usr/src/app 10 | RUN mkdir -p /public/media 11 | RUN mkdir -p /public/static 12 | RUN mkdir -p /var/log/{{cookiecutter.project_slug}} 13 | WORKDIR /usr/src/app 14 | 15 | # Run python requirements installation 16 | COPY requirements.txt /usr/src/app/ 17 | RUN pip install --no-cache-dir -r requirements.txt 18 | 19 | # Copy run_server.sh 20 | COPY ./run_server.sh /run_server.sh 21 | RUN sed -i 's/\r//' /run_server.sh 22 | RUN chmod a+x /run_server.sh 23 | 24 | # Copy entrypoint.sh 25 | COPY ./entrypoint.sh /entrypoint.sh 26 | RUN sed -i 's/\r//' /entrypoint.sh 27 | RUN chmod a+x /entrypoint.sh 28 | 29 | COPY . /usr/src/app 30 | 31 | ENTRYPOINT ["/entrypoint.sh"] 32 | -------------------------------------------------------------------------------- /{{cookiecutter.project_slug}}/web/requirements.txt: -------------------------------------------------------------------------------- 1 | cmsplugin-filer==1.1.3 2 | dj-database-url==0.4.2 3 | Django==1.9.13 4 | django-appconf==1.0.2 5 | django-classy-tags==0.8.0 6 | django-cms==3.4.5 7 | django-filer==1.2.8 8 | django-formtools==2.0 9 | django-mptt==0.8.7 10 | django-polymorphic==1.0.2 11 | django-sekizai==0.10.0 12 | django-treebeard==4.1.2 13 | djangocms-admin-style==1.2.7 14 | djangocms-attributes-field==0.3.0 15 | djangocms-column==1.7.0 16 | djangocms-googlemap==1.1.1 17 | djangocms-installer==0.9.7 18 | djangocms-link==2.1.2 19 | djangocms-snippet==1.9.2 20 | djangocms-style==2.0.2 21 | djangocms-text-ckeditor==3.5.0 22 | djangocms-video==2.0.4 23 | easy-thumbnails==2.4.1 24 | gunicorn==19.7.1 25 | html5lib==0.9999999 26 | olefile==0.44 27 | Pillow==4.2.1 28 | psycopg2==2.7.3.1 29 | pytz==2017.2 30 | six==1.10.0 31 | tzlocal==1.4 32 | Unidecode==0.4.21 33 | aldryn-newsblog==1.3.3 34 | -------------------------------------------------------------------------------- /{{cookiecutter.project_slug}}/web/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == "__main__": 6 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{cookiecutter.project_slug}}.settings") 7 | try: 8 | from django.core.management import execute_from_command_line 9 | except ImportError: 10 | # The above import may fail for some other reason. Ensure that the 11 | # issue is really that Django is missing to avoid masking other 12 | # exceptions on Python 2. 13 | try: 14 | import django 15 | except ImportError: 16 | raise ImportError( 17 | "Couldn't import Django. Are you sure it's installed and " 18 | "available on your PYTHONPATH environment variable? Did you " 19 | "forget to activate a virtual environment?" 20 | ) 21 | raise 22 | execute_from_command_line(sys.argv) 23 | -------------------------------------------------------------------------------- /{{cookiecutter.project_slug}}/docker-compose-dev.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | 3 | services: 4 | web: 5 | image: {{cookiecutter.project_slug}}_web 6 | build: ./web/ 7 | # Expose ports without publishing them 8 | ports: 9 | - "8000:8000" 10 | links: 11 | - db:db 12 | env_file: .env.dev 13 | volumes: 14 | - ./web:/usr/src/app 15 | - web_public_dev:/public:rw 16 | depends_on: 17 | - db 18 | command: /run_server.sh local 19 | 20 | db: 21 | image: {{cookiecutter.project_slug}}_db 22 | build: ./db/ 23 | env_file: .env.dev 24 | volumes: 25 | - db_data_dev:/var/lib/postgresql/data:rw 26 | - db_backup_dev:/backups 27 | - web_public_dev:/public:rw 28 | # Expose ports without publishing them 29 | expose: 30 | - "5432" 31 | 32 | volumes: 33 | db_data_dev: 34 | driver: local 35 | db_backup_dev: 36 | driver: local 37 | web_public_dev: 38 | driver: local -------------------------------------------------------------------------------- /{{cookiecutter.project_slug}}/web/{{cookiecutter.project_slug}}/templates/menu.html: -------------------------------------------------------------------------------- 1 | {% raw %}{% load i18n menu_tags cache %} 2 | 3 | {% for child in children %} 4 | 18 | {% if class and forloop.last and not forloop.parentloop %}{% endif %} 19 | {% endfor %}{% endraw %} 20 | -------------------------------------------------------------------------------- /{{cookiecutter.project_slug}}/web/{{cookiecutter.project_slug}}/urls.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from __future__ import absolute_import, print_function, unicode_literals 3 | 4 | from cms.sitemaps import CMSSitemap 5 | from django.conf import settings 6 | from django.conf.urls import include, url 7 | from django.contrib import admin 8 | from django.contrib.sitemaps.views import sitemap 9 | from django.contrib.staticfiles.urls import staticfiles_urlpatterns 10 | from django.views.static import serve 11 | 12 | admin.autodiscover() 13 | 14 | urlpatterns = [ 15 | url(r'^sitemap\.xml$', sitemap, 16 | {'sitemaps': {'cmspages': CMSSitemap}}), 17 | ] 18 | 19 | urlpatterns += ( 20 | url(r'^admin/', include(admin.site.urls)), # NOQA 21 | url(r'^', include('cms.urls')), 22 | ) 23 | 24 | # This is only needed when using a runserver command. 25 | if settings.DEBUG: 26 | urlpatterns = [ 27 | url(r'^media/(?P.*)$', serve, 28 | {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}), 29 | ] + staticfiles_urlpatterns() + urlpatterns 30 | -------------------------------------------------------------------------------- /{{cookiecutter.project_slug}}/web/run_server.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # test.sh 4 | # Copyright (C) 2017 Rafal Gumienny 5 | # 6 | # Distributed under terms of the GPL license. 7 | # 8 | 9 | 10 | # end when error 11 | set -e 12 | # raise error when variable is unset 13 | set -u 14 | # raise error when in pipe 15 | set -o pipefail 16 | 17 | 18 | if (( $# != 1 )); then 19 | echo "Ussage: run_server.sh [local|gunicorn]" 20 | exit 21 | fi 22 | 23 | if [ "$1" == "local" ]; then 24 | echo "Running local development server" 25 | python manage.py migrate 26 | python /usr/src/app/manage.py runserver 0.0.0.0:8000 27 | elif [ "$1" == "gunicorn" ]; then 28 | echo "Running Gunicorn" 29 | python manage.py migrate 30 | python /usr/src/app/manage.py collectstatic --noinput 31 | /usr/local/bin/gunicorn {{cookiecutter.project_slug}}.wsgi:application -w 5 -b :8000 \ 32 | --access-logfile /var/log/{{cookiecutter.project_slug}}/access.log \ 33 | --error-logfile /var/log/{{cookiecutter.project_slug}}/error.log \ 34 | --log-level debug 35 | else 36 | echo "Usage: run_server.sh [local|gunicorn]" 37 | fi 38 | -------------------------------------------------------------------------------- /{{cookiecutter.project_slug}}/db/backup.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -o errexit 4 | set -o pipefail 5 | set -o nounset 6 | 7 | 8 | # we might run into trouble when using the default `postgres` user, e.g. when dropping the postgres 9 | # database in restore.sh. Check that something else is used here 10 | if [ "$DB_USER" == "postgres" ] 11 | then 12 | echo "creating a backup as the postgres user is not supported, make sure to set the DB_USER environment variable" 13 | exit 1 14 | fi 15 | 16 | # export the postgres password so that subsequent commands don't ask for it 17 | export PGPASSWORD=$DB_PASS 18 | 19 | echo "creating DB backup" 20 | echo "------------------" 21 | 22 | TIMESTAMP="$(date +'%Y_%m_%dT%H_%M_%S')" 23 | 24 | DB_FILENAME=backup_${TIMESTAMP}_db.sql.gz 25 | pg_dump -h $DB_HOST -U $DB_USER -d $DB_NAME | gzip > /backups/$DB_FILENAME 26 | 27 | echo "creating Media backup" 28 | echo "---------------------" 29 | 30 | MEDIA_FILENAME=backup_${TIMESTAMP}_media.tar.gz 31 | 32 | tar -zcvf /backups/$MEDIA_FILENAME -C /public media 33 | 34 | echo "successfully created backups: $DB_FILENAME and $MEDIA_FILENAME" 35 | -------------------------------------------------------------------------------- /{{cookiecutter.project_slug}}/docker-compose-prod.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | 3 | services: 4 | web: 5 | restart: always 6 | image: {{cookiecutter.project_slug}}_web 7 | build: ./web/ 8 | # Expose ports without publishing them 9 | expose: 10 | - "8000" 11 | links: 12 | - db:db 13 | env_file: .env 14 | volumes: 15 | - web_public_prod:/public:rw 16 | depends_on: 17 | - db 18 | command: /run_server.sh gunicorn 19 | 20 | nginx: 21 | restart: always 22 | image: {{cookiecutter.project_slug}}_nginx 23 | build: ./nginx/ 24 | # Expose ports and publish them to the host machine 25 | ports: 26 | - "80:80" 27 | volumes: 28 | - web_public_prod:/public:rw 29 | links: 30 | - web:web 31 | depends_on: 32 | - web 33 | 34 | db: 35 | restart: always 36 | image: {{cookiecutter.project_slug}}_db 37 | build: ./db/ 38 | env_file: .env 39 | volumes: 40 | - db_data_prod:/var/lib/postgresql/data:rw 41 | - db_backup_prod:/backups 42 | - web_public_prod:/public:rw 43 | # Expose ports without publishing them 44 | expose: 45 | - "5432" 46 | 47 | volumes: 48 | db_data_prod: 49 | driver: local 50 | db_backup_prod: 51 | driver: local 52 | web_public_prod: 53 | driver: local 54 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017, Rafal Gumienny 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, this 11 | list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | * Neither the name of Cookiecutter Django-CMS-Docker nor the names of its contributors may 15 | be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 22 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 23 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 26 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 27 | OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /{{cookiecutter.project_slug}}/web/{{cookiecutter.project_slug}}/templates/base.html: -------------------------------------------------------------------------------- 1 | {% raw %}{% load cms_tags staticfiles sekizai_tags menu_tags %} 2 | 3 | 4 | 5 | 6 | {% block title %}{% endraw %}{{cookiecutter.project_name}}{% raw %}{% endblock title %} 7 | 8 | 9 | 10 | {% render_block "css" %} 11 | 12 | 13 | 14 | {% cms_toolbar %} 15 |
16 | 32 | {% block content %}{% endblock content %} 33 |
34 | 35 | 36 | {% render_block "js" %} 37 | 38 | 39 | {% endraw %} 40 | -------------------------------------------------------------------------------- /{{cookiecutter.project_slug}}/db/restore.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -o errexit 4 | set -o pipefail 5 | set -o nounset 6 | 7 | 8 | # we might run into trouble when using the default `postgres` user, e.g. when dropping the postgres 9 | # database in restore.sh. Check that something else is used here 10 | if [ "$DB_USER" == "postgres" ] 11 | then 12 | echo "restoring as the postgres user is not supported, make sure to set the DB_USER environment variable" 13 | exit 1 14 | fi 15 | 16 | # export the postgres password so that subsequent commands don't ask for it 17 | export PGPASSWORD=$DB_PASS 18 | 19 | # check that we have an argument for a filename candidate 20 | if [[ $# -eq 0 ]] ; then 21 | echo 'usage:' 22 | echo ' docker-compose -f docker-compose-prod.yml run postgres restore ' 23 | echo '' 24 | echo 'to get a list of available backups, run:' 25 | echo ' docker-compose -f docker-compose-prod.yml run postgres list-backups' 26 | exit 1 27 | fi 28 | 29 | # set the backupfile variable 30 | DB_BACKUPFILE=/backups/backup_$1_db.sql.gz 31 | MEDIA_BACKUPFILE=/backups/backup_$1_media.tar.gz 32 | 33 | # check that the file exists 34 | if ! [ -f $DB_BACKUPFILE ]; then 35 | echo "$DB_BACKUPFILE backup file not found" 36 | echo 'to get a list of available backups, run:' 37 | echo ' docker-compose -f production.yml run postgres list-backups' 38 | exit 1 39 | fi 40 | 41 | echo "beginning restore from $DB_BACKUPFILE" 42 | echo "-----------------------------------------" 43 | 44 | # delete the db 45 | # deleting the db can fail. Spit out a comment if this happens but continue since the db 46 | # is created in the next step 47 | echo "deleting old database $DB_USER" 48 | if dropdb -h $DB_HOST -U $DB_USER $DB_USER 49 | then echo "deleted $DB_USER database" 50 | else echo "database $DB_USER does not exist, continue" 51 | fi 52 | 53 | # create a new database 54 | echo "creating new database $DB_USER" 55 | createdb -h $DB_HOST -U $DB_USER $DB_NAME -O $DB_USER 56 | 57 | # restore the database 58 | echo "restoring database $DB_USER" 59 | gunzip -c $DB_BACKUPFILE | psql -h $DB_HOST -U $DB_USER 60 | 61 | echo "beginning restore from $MEDIA_BACKUPFILE" 62 | echo "-----------------------------------------" 63 | 64 | MEDIA_DIR="/public/media" 65 | 66 | if [ -d "$MEDIA_DIR" ]; then 67 | # Remove media directory. 68 | rm -rf $MEDIA_DIR 69 | fi 70 | 71 | tar -zxvf $MEDIA_BACKUPFILE -C /public/ 72 | -------------------------------------------------------------------------------- /{{cookiecutter.project_slug}}/README.md: -------------------------------------------------------------------------------- 1 | # Repo for {{cookiecutter.project_name}} website 2 | 3 | ## Local development 4 | 5 | ``` 6 | git clone https://github.com/{{cookiecutter.github_user}}/{{cookiecutter.project_slug}} 7 | cd {{cookiecutter.project_slug}} 8 | docker-compose -f docker-compose-dev.yml build 9 | docker-compose -f docker-compose-dev.yml up (-d) 10 | ``` 11 | 12 | If starting from the scratch run following commands: 13 | ``` 14 | docker-compose -f docker-compose-dev.yml exec web python manage.py createsuperuser 15 | ``` 16 | 17 | Alternatively, one can restore from previous run or from different machine: 18 | ``` 19 | docker-compose -f docker-compose-dev.yml exec db list-backups 20 | docker-compose -f docker-compose-dev.yml exec db restore 21 | ``` 22 | 23 | For the local development a internal django server is used (ie. runserver command) 24 | and the port 8000 is exposed to the host. Local web directory is mapped to the 25 | container and the local changes will be reflected in the running container thus 26 | greatly facilitating the development process. 27 | 28 | ## Production run 29 | 30 | The production environment is similar to the local but requires creating .env file 31 | based based on the .env.example and usage of the `docker-compose-prod.yml` file 32 | wherever the `docker-compose-dev.yml` is used. 33 | 34 | 35 | For the production run a gunicorn server is used to serve Django 36 | and the port 8000 is exposed to other services. The Nginx server 37 | is used as a proxy for Django and to serve static and media files. 38 | 39 | ### IMPORTANT 40 | 41 | Do not forget to set properly environment. Especially ALLOWED_HOSTS. 42 | 43 | There is a know bug in Django CMS causing a failure to load / address. 44 | If you experience 404 accessing the website (eg. http://localhost) 45 | turn on DEBUG=True for an initialization or go directly to /admin 46 | and create first Page manually in the DJANGO CMS -> Pages section. 47 | 48 | 49 | ## Backups 50 | 51 | In order to prepare backup run following command: 52 | ``` 53 | docker-compose -f docker-compose-dev.yml exec db backup 54 | ``` 55 | 56 | In order to list all backups run following command: 57 | ``` 58 | docker-compose -f docker-compose-dev.yml exec db list-backups 59 | ``` 60 | 61 | In order to restore choosen backup run following command: 62 | ``` 63 | docker-compose -f docker-compose-dev.yml exec db restore 64 | ``` 65 | 66 | Backup files are located in `/backups` directory. If order to transfer 67 | DB to a different machine copy choosen backup (sql and media file) to 68 | local host and transfer them to /backup directory of choosen machine 69 | running {{cookiecutter.project_name}} website DB container. To copy the files from container 70 | to local machine run: 71 | 72 | ``` 73 | sudo docker cp container_id:/backups/ ./ 74 | sudo docker cp container_id:/backups/ ./ 75 | ``` 76 | 77 | In order to copy files from the host to choosen machine's container do: 78 | ``` 79 | sudo docker cp container_id:/backups/ 80 | sudo docker cp container_id:/backups/ 81 | ``` 82 | 83 | ## Logs 84 | 85 | The logs for nginx service can be found in `/var/log/nginx/error_{{cookiecutter.project_slug}}.log` 86 | and `/var/log/nginx/access_{{cookiecutter.project_slug}}.log`. 87 | 88 | The logs for web servece are in `/var/log/{{cookiecutter.project_slug}}/access.log`, 89 | `/var/log/{{cookiecutter.project_slug}}/error.log` and `/var/log/{{cookiecutter.project_slug}}/django.log`. 90 | 91 | One can see them by executing: 92 | ``` 93 | docker-compose -f docker-compose-dev.yml exec tail [-F] 94 | ``` -------------------------------------------------------------------------------- /{{cookiecutter.project_slug}}/LICENSE: -------------------------------------------------------------------------------- 1 | {% if cookiecutter.open_source_license == 'MIT' %} 2 | The MIT License (MIT) 3 | Copyright (c) {% now 'utc', '%Y' %}, {{ cookiecutter.author_name }} 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | {% elif cookiecutter.open_source_license == 'BSD' %} 11 | Copyright (c) {% now 'utc', '%Y' %}, {{ cookiecutter.author_name }} 12 | All rights reserved. 13 | 14 | Redistribution and use in source and binary forms, with or without modification, 15 | are permitted provided that the following conditions are met: 16 | 17 | * Redistributions of source code must retain the above copyright notice, this 18 | list of conditions and the following disclaimer. 19 | 20 | * Redistributions in binary form must reproduce the above copyright notice, this 21 | list of conditions and the following disclaimer in the documentation and/or 22 | other materials provided with the distribution. 23 | 24 | * Neither the name of {{ cookiecutter.project_name }} nor the names of its 25 | contributors may be used to endorse or promote products derived from this 26 | software without specific prior written permission. 27 | 28 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 29 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 30 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 31 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 32 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 33 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 34 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 35 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 36 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 37 | OF THE POSSIBILITY OF SUCH DAMAGE. 38 | {% elif cookiecutter.open_source_license == 'GPLv3' %} 39 | Copyright (c) {% now 'utc', '%Y' %}, {{ cookiecutter.author_name }} 40 | 41 | This program is free software: you can redistribute it and/or modify 42 | it under the terms of the GNU General Public License as published by 43 | the Free Software Foundation, either version 3 of the License, or 44 | (at your option) any later version. 45 | 46 | This program is distributed in the hope that it will be useful, 47 | but WITHOUT ANY WARRANTY; without even the implied warranty of 48 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 49 | GNU General Public License for more details. 50 | 51 | You should have received a copy of the GNU General Public License 52 | along with this program. If not, see . 53 | {% endif %} 54 | -------------------------------------------------------------------------------- /{{cookiecutter.project_slug}}/web/{{cookiecutter.project_slug}}/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for {{cookiecutter.project_slug}} project. 3 | 4 | Generated by 'django-admin startproject' using Django 1.10.8. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/1.10/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/1.10/ref/settings/ 11 | """ 12 | 13 | import os 14 | gettext = lambda s: s 15 | DATA_DIR = os.path.dirname(os.path.dirname(__file__)) 16 | 17 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 18 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 19 | 20 | 21 | # Quick-start development settings - unsuitable for production 22 | # See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/ 23 | 24 | # SECURITY WARNING: don't run with debug turned on in production! 25 | is_debug = os.environ.get('DEBUG', "False") 26 | if is_debug == "True": 27 | DEBUG = True 28 | else: 29 | DEBUG = False 30 | 31 | # SECURITY WARNING: keep the secret key used in production secret! 32 | SECRET_KEY = os.environ['SECRET_KEY'] 33 | 34 | ALLOWED_HOSTS = os.environ.get('ALLOWED_HOSTS', "0.0.0.0").split(",") 35 | 36 | ADMINS = [("""{{cookiecutter.author_name}}""", '{{cookiecutter.email}}'),] 37 | # Application definition 38 | 39 | ROOT_URLCONF = '{{cookiecutter.project_slug}}.urls' 40 | 41 | 42 | 43 | 44 | # Internationalization 45 | # https://docs.djangoproject.com/en/1.10/topics/i18n/ 46 | 47 | LANGUAGE_CODE = 'en' 48 | 49 | TIME_ZONE = {{ cookiecutter.timezone }} 50 | 51 | USE_I18N = False 52 | 53 | USE_L10N = False 54 | 55 | USE_TZ = True 56 | 57 | 58 | # Static files (CSS, JavaScript, Images) 59 | # https://docs.djangoproject.com/en/1.10/howto/static-files/ 60 | 61 | STATIC_URL = '/static/' 62 | MEDIA_URL = '/media/' 63 | MEDIA_ROOT = os.path.join('/public', 'media') 64 | STATIC_ROOT = os.path.join('/public', 'static') 65 | 66 | STATICFILES_DIRS = ( 67 | os.path.join(BASE_DIR, '{{cookiecutter.project_slug}}', 'static'), 68 | ) 69 | SITE_ID = 1 70 | 71 | 72 | TEMPLATES = [ 73 | { 74 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 75 | 'DIRS': [os.path.join(BASE_DIR, '{{cookiecutter.project_slug}}', 'templates'),], 76 | 'OPTIONS': { 77 | 'context_processors': [ 78 | 'django.contrib.auth.context_processors.auth', 79 | 'django.contrib.messages.context_processors.messages', 80 | 'django.template.context_processors.debug', 81 | 'django.template.context_processors.request', 82 | 'django.template.context_processors.media', 83 | 'django.template.context_processors.csrf', 84 | 'django.template.context_processors.tz', 85 | 'sekizai.context_processors.sekizai', 86 | 'django.template.context_processors.static', 87 | 'cms.context_processors.cms_settings' 88 | ], 89 | 'loaders': [ 90 | 'django.template.loaders.filesystem.Loader', 91 | 'django.template.loaders.app_directories.Loader', 92 | 'django.template.loaders.eggs.Loader' 93 | ], 94 | }, 95 | }, 96 | ] 97 | 98 | 99 | MIDDLEWARE_CLASSES = ( 100 | 'cms.middleware.utils.ApphookReloadMiddleware', 101 | 'django.middleware.csrf.CsrfViewMiddleware', 102 | 'django.contrib.sessions.middleware.SessionMiddleware', 103 | 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 104 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 105 | 'django.contrib.messages.middleware.MessageMiddleware', 106 | 'django.middleware.common.CommonMiddleware', 107 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 108 | 'cms.middleware.user.CurrentUserMiddleware', 109 | 'cms.middleware.page.CurrentPageMiddleware', 110 | 'cms.middleware.toolbar.ToolbarMiddleware', 111 | ) 112 | 113 | INSTALLED_APPS = ( 114 | 'djangocms_admin_style', 115 | 'django.contrib.auth', 116 | 'django.contrib.contenttypes', 117 | 'django.contrib.sessions', 118 | 'django.contrib.admin', 119 | 'django.contrib.sites', 120 | 'django.contrib.sitemaps', 121 | 'django.contrib.staticfiles', 122 | 'django.contrib.messages', 123 | 'cms', 124 | 'menus', 125 | 'sekizai', 126 | 'treebeard', 127 | 'djangocms_text_ckeditor', 128 | 'filer', 129 | 'easy_thumbnails', 130 | 'djangocms_column', 131 | 'djangocms_link', 132 | 'cmsplugin_filer_file', 133 | 'cmsplugin_filer_folder', 134 | 'cmsplugin_filer_image', 135 | 'cmsplugin_filer_utils', 136 | 'djangocms_style', 137 | 'djangocms_snippet', 138 | 'djangocms_googlemap', 139 | 'djangocms_video', 140 | # aldryn news blog 141 | 'aldryn_apphooks_config', 142 | 'aldryn_categories', 143 | 'aldryn_common', 144 | 'aldryn_newsblog', 145 | 'aldryn_people', 146 | 'aldryn_reversion', 147 | 'aldryn_translation_tools', 148 | 'parler', 149 | 'sortedm2m', 150 | 'taggit', 151 | 'reversion', 152 | # Custom apps 153 | '{{cookiecutter.project_slug}}' 154 | ) 155 | 156 | LANGUAGES = ( 157 | ## Customize this 158 | ('en', gettext('en')), 159 | ) 160 | 161 | CMS_LANGUAGES = { 162 | ## Customize this 163 | 1: [ 164 | { 165 | 'code': 'en', 166 | 'name': gettext('en'), 167 | 'redirect_on_fallback': True, 168 | 'public': True, 169 | 'hide_untranslated': False, 170 | }, 171 | ], 172 | 'default': { 173 | 'redirect_on_fallback': True, 174 | 'public': True, 175 | 'hide_untranslated': False, 176 | }, 177 | } 178 | 179 | CMS_TEMPLATES = ( 180 | ## Customize this 181 | ('page.html', 'Page'), 182 | ('feature.html', 'Page with Feature') 183 | ) 184 | 185 | CMS_PERMISSION = True 186 | 187 | CMS_PLACEHOLDER_CONF = {} 188 | 189 | if 'DB_NAME' in os.environ: 190 | DATABASES = { 191 | 'default': { 192 | 'ENGINE': 'django.db.backends.postgresql_psycopg2', 193 | 'NAME': os.environ['DB_NAME'], 194 | 'USER': os.environ['DB_USER'], 195 | 'PASSWORD': os.environ['DB_PASS'], 196 | 'HOST': os.environ['DB_HOST'], 197 | 'PORT': os.environ['DB_PORT'] 198 | } 199 | } 200 | else: 201 | # Building the Docker image 202 | DATABASES = { 203 | 'default': { 204 | 'ENGINE': 'django.db.backends.sqlite3', 205 | 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 206 | } 207 | } 208 | 209 | MIGRATION_MODULES = { 210 | 211 | } 212 | 213 | THUMBNAIL_PROCESSORS = ( 214 | 'easy_thumbnails.processors.colorspace', 215 | 'easy_thumbnails.processors.autocrop', 216 | 'filer.thumbnail_processors.scale_and_crop_with_subject_location', 217 | 'easy_thumbnails.processors.filters' 218 | ) 219 | 220 | 221 | LOGGING = { 222 | 'version': 1, 223 | 'disable_existing_loggers': False, 224 | 'handlers': { 225 | 'console': { 226 | 'level': 'DEBUG', 227 | 'class': 'logging.StreamHandler', 228 | }, 229 | 'logfile': { 230 | 'level': 'DEBUG', 231 | 'filename': "/var/log/{{cookiecutter.project_slug}}/django.log", 232 | 'class': 'logging.handlers.RotatingFileHandler', 233 | 'maxBytes': 1024 * 1024 * 5, # 5 MB 234 | 'backupCount': 5, 235 | }, 236 | }, 237 | 'root': { 238 | 'level': 'INFO', 239 | 'handlers': ['console', 'logfile'] 240 | }, 241 | } 242 | --------------------------------------------------------------------------------