Skip to content

Commit 21fa750

Browse files
MacLakeJens-Erik Webermarksweb
authored
Make database persistent, set ext. postgres port with env. variable, … (#53)
* Make database persistent, set ext. postgres port with env. variable, docs Create a named volume in order to keep the database content after containers have been deleted with docker compose down. To access the postgres instance in the docker container from the host, an external port number can be set. Update documentation * Update .gitignore Co-authored-by: Mark Walker <theshow@gmail.com> * Update compose.yaml more generic, shorter db port name Co-authored-by: Mark Walker <theshow@gmail.com> * Reflect renaming of the db port env. variable to DB_PORT in the docs * Fix typos, version numbers in the documentation, formatting Update version numbers in the documentation Keep line length to max. 120 where possible --------- Co-authored-by: Jens-Erik Weber <Jens-Erik Weber Jens-Erik.Weber@passiv.de> Co-authored-by: Mark Walker <theshow@gmail.com>
1 parent aa17d82 commit 21fa750

File tree

4 files changed

+59
-21
lines changed

4 files changed

+59
-21
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ db.sqlite3
2020
.Trashes
2121

2222
.idea/
23+
.env

README.rst

+51-17
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,26 @@
44
django CMS quickstart
55
#####################
66

7-
A Dockerised django CMS project, ready to deploy on `Divio <https://www.divio.com/>`_ or another Docker-based cloud platform, and run locally in Docker on your own machine.
7+
A dockerised django CMS project, ready to deploy on `Divio <https://www.divio.com/>`_ or another Docker-based cloud
8+
platform, and run locally in Docker on your own machine.
89

9-
This version uses Python 3.10 running and the most up-to-date versions of Django 3.2, and django CMS 4.1.0rc1
10+
This version uses Python 3.11 and the most up-to-date versions of Django 3.2, and django CMS 4.1.0rc3
1011

11-
This project is endorsed by the `django CMS Association <https://www.django-cms.org/en/about-us/>`_. That means that it is officially accepted by the dCA as being in line with our roadmap vision and development/plugin policy. Join us on `Slack <https://www.django-cms.org/slack/>`_ for more information or questions.
12+
This project is endorsed by the `django CMS Association <https://www.django-cms.org/en/about-us/>`_. That means that it
13+
is officially accepted by the dCA as being in line with our roadmap vision and development/plugin policy. Join us on
14+
`Slack <https://www.django-cms.org/slack/>`_ for more information or questions.
1215

13-
The documentation for version 4.1 is still work in progress and - for the time being - can be found here: https://django-cms-docs.readthedocs.io/en/latest/
16+
The documentation for version 4.1 is still work in progress and - for the time being - can be found here:
17+
https://django-cms-docs.readthedocs.io/en/latest/
1418

1519
Installation
1620
############
1721

18-
You need to have docker installed on your system to run this project.
22+
You need to have Docker installed on your system to run this project.
1923

2024
- `Install Docker <https://docs.docker.com/engine/install/>`_ here.
21-
- If you have not used docker in the past, please read this `introduction on docker <https://docs.docker.com/get-started/>`_ here.
25+
- If you have not used docker in the past, please read this
26+
`introduction on docker <https://docs.docker.com/get-started/>`_ here.
2227

2328
Try it
2429
######
@@ -38,7 +43,22 @@ Try it
3843
3944
Then open http://django-cms-quickstart.127.0.0.1.nip.io:8000 (or just http://127.0.0.1:8000) in your browser.
4045

41-
Note: Since Compose V2, ``docker-compose`` is now included inside docker. For more information, checkout the `Compose V2 <https://docs.docker.com/compose/cli-command/>`_ Documentation.
46+
You can stop the server with ``docker compose stop`` without destroying the containers and restart it with
47+
``docker compose start``.
48+
49+
With ``docker compose down`` the containers are deleted, but the database content is still preserved in the named
50+
volume ``django-cms-quickstart_postgres-data`` and the media files are stored in the file system in ``data/media``.
51+
Then you can update the project e. g. by changing the requirements and settings. Finally you can rebuild the web image
52+
and start the server again:
53+
54+
.. code-block:: bash
55+
56+
docker compose build web
57+
docker compose up -d
58+
59+
60+
Note: Since Compose V2, ``docker-compose`` is now included inside docker. For more information, checkout the
61+
`Compose V2 <https://docs.docker.com/compose/cli-command/>`_ Documentation.
4262

4363
.. inclusion-end-marker-do-not-remove
4464
@@ -48,15 +68,16 @@ Customising the project
4868
This project is ready-to-go without making any changes at all, but also gives you some options.
4969

5070
As-is, it will include a number of useful django CMS plugins and Bootstrap 4 for the frontend. You don't have to use
51-
these; they're optional. If you don't want to use them, read through the ``settings.py`` and ``requirements.txt`` files to
52-
see sections that can be removed - in each case, the section is noted with a comment containing the word 'optional'.
71+
these; they're optional. If you don't want to use them, read through the ``settings.py`` and ``requirements.txt`` files
72+
to see sections that can be removed - in each case, the section is noted with a comment containing the word 'optional'.
5373

5474
Options are also available for using Postgres/MySQL, uWSGI/Gunicorn/Guvicorn, etc.
5575

5676
Updating requirements
5777
=====================
5878

59-
The project uses a 2 step approach, freezing all dependencies with pip-tools. Read more about how to handle it here: https://blog.typodrive.com/2020/02/04/always-freeze-requirements-with-pip-compile-to-avoid-unpleasant-surprises/
79+
The project uses a 2 step approach, freezing all dependencies with pip-tools. Read more about how to handle it here:
80+
https://blog.typodrive.com/2020/02/04/always-freeze-requirements-with-pip-compile-to-avoid-unpleasant-surprises/
6081

6182
Features
6283
########
@@ -66,27 +87,38 @@ Static Files with Whitenoise
6687

6788
This quickstart demo has a cloud-ready static files setup via django-whitenoise.
6889

69-
In the containerized cloud the application is not served by a web server like nginx but directly through uwsgi. django-whitenoise is the glue that's needed to serve static files in your application directly through uwsgi.
90+
In the containerized cloud the application is not served by a web server like nginx but directly through uwsgi.
91+
django-whitenoise is the glue that's needed to serve static files in your application directly through uwsgi.
7092

71-
See the django-whitenoise settings in settings.py and the ``quickstart/templates/whitenoise-static-files-demo.html`` demo page template that serves a static file.
93+
See the django-whitenoise settings in settings.py and the ``quickstart/templates/whitenoise-static-files-demo.html``
94+
demo page template that serves a static file.
7295

7396
Contribution
7497
############
7598

76-
Here is the official django CMS repository: `https://github.com/django-cms/django-cms-quickstart/ <https://github.com/django-cms/django-cms-quickstart/>`_.
99+
Here is the official django CMS repository:
100+
`https://github.com/django-cms/django-cms-quickstart/ <https://github.com/django-cms/django-cms-quickstart/>`_.
77101

78102

79103
Deployment
80104
##########
81105

82-
Note that this is just a demo project to get you started. If you want a full production ready site with all the bells and whistles we recommend you have a look at https://github.com/django-cms/djangocms-template instead.
106+
Note that this is just a demo project to get you started. If you want a full production ready site with all the bells
107+
and whistles we recommend you have a look at https://github.com/django-cms/djangocms-template instead.
83108

84109
Env variables
85110
=============
86111

87-
- to deploy this project in testing mode (recommended) set the environment variable ``DEBUG`` to ``True`` in your hosting environment.
88-
- For production environment (if ``DEBUG`` is false) django requires you to whitelist the domain. Set the env var ``DOMAIN`` to the host, i.e. ``www.domain.com`` or ``*.domain.com``.
112+
- to deploy this project in testing mode (recommended) set the environment variable ``DEBUG`` to ``True`` in your
113+
hosting environment.
114+
- For production environment (if ``DEBUG`` is false) django requires you to whitelist the domain. Set the env var
115+
``DOMAIN`` to the host, i.e. ``www.domain.com`` or ``*.domain.com``.
89116
- If you want the media hosted on S3 set the ``DEFAULT_FILE_STORAGE`` variable accordingly.
117+
- If you want to access the PostgreSQL database from the host system, set ``DB_PORT`` to the desired port number.
118+
5432 is the standard port number. If you run PosgreSQL on your host system, you may want to set another port number.
119+
If this variable is empty (the default), the PosgreSQL instance in the container is only reachable within docker, but
120+
not from outside.
121+
90122

91123
Deployment Commands
92124
===================
@@ -99,7 +131,9 @@ Configure your hosting environment to run the following commands on every deploy
99131
Divio Deployment
100132
================
101133

102-
divio.com is a cloud hosting platform optimized for django web applications. It's the quickest way to deploy this project. Here is a `video tutorial <https://www.youtube.com/watch?v=O2g5Wfoyp7Q>`_ and a `description of the deployment steps <https://github.com/django-cms/djangocms-template/blob/mco-standalone/docs/deployment-divio.md#divio-project-setup>`_ that are mostly applicable for this quickstart project.
134+
divio.com is a cloud hosting platform optimized for django web applications. It's the quickest way to deploy this
135+
project. Here is a `video tutorial <https://www.youtube.com/watch?v=O2g5Wfoyp7Q>`_ and a
136+
`description of the deployment steps <https://github.com/django-cms/djangocms-template/blob/mco-standalone/docs/deployment-divio.md#divio-project-setup>`_ that are mostly applicable for this quickstart project.
103137

104138

105139
.. |pythonapp| image:: https://github.com/django-cms/django-cms-quickstart/workflows/Python%20application/badge.svg?branch=support/cms-4.1.x

docker-compose.yml renamed to compose.yaml

+6-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ services:
2121

2222
database_default:
2323
# Select one of the following db configurations for the database
24-
image: postgres:13.5-alpine
24+
image: postgres:15-alpine
2525
ports:
26-
- "5432:5432/tcp" # allow your local dev env to connect to the db
26+
- "${DB_PORT-}:5432/tcp" # allow your local dev env to connect to the db if variable set
2727
environment:
2828
POSTGRES_DB: "db"
2929
POSTGRES_PASSWORD: "password"
@@ -34,7 +34,10 @@ services:
3434
- djangocmsnet
3535

3636
volumes:
37-
- ".:/app:rw"
37+
- postgres-data:/var/lib/postgresql/data/
3838

3939
networks:
4040
djangocmsnet:
41+
42+
volumes:
43+
postgres-data:

requirements.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Compile this file for changes to take effect:
2-
# pip-compile requirements.in >> requirements.txt
2+
# pip-compile -U --resolver=backtracking
33

44
boto3
55
psycopg2

0 commit comments

Comments
 (0)