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 |
--------------------------------------------------------------------------------