Skip to content

Commit a63c5a5

Browse files
authored
Initial commit
0 parents  commit a63c5a5

24 files changed

+909
-0
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.git
2+
node_modules

.env-local

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
DATABASE_URL=postgres://postgres:password@database_default:5432/db
2+
DEFAULT_STORAGE_DSN=file:///data/media/?url=%2Fmedia%2F
3+
DEBUG=True
4+
DOMAIN_ALIASES="localhost, 127.0.0.1"
5+
SECURE_SSL_REDIRECT=False

.github/FUNDING.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# These are supported funding model platforms
2+
3+
github: [django-cms]
4+
patreon: # Replace with a single Patreon username
5+
open_collective: # Replace with a single Open Collective username
6+
ko_fi: # Replace with a single Ko-fi username
7+
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8+
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9+
liberapay: # Replace with a single Liberapay username
10+
issuehunt: # Replace with a single IssueHunt username
11+
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
12+
polar: # Replace with a single Polar username
13+
buy_me_a_coffee: # Replace with a single Buy Me a Coffee username
14+
thanks_dev: # Replace with a single thanks.dev username
15+
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

.github/workflows/docker.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Docker test suite
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
workflow_dispatch:
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.event.pull_request.number || github.sha }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
pytest:
16+
name: Docker test build
17+
# List of supported runners:
18+
# https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- uses: actions/checkout@v4
23+
24+
- name: Pre-build container images
25+
run: |
26+
docker network create djangocmsnet
27+
docker compose build --force-rm
28+
29+
- name: Run the containers
30+
run: |
31+
docker compose build web
32+
docker compose up database_default -d
33+
sleep 2s
34+
docker compose run web python manage.py migrate
35+
docker compose up -d
36+
37+
- name: 'debug: Display state and logs'
38+
if: always()
39+
run: |
40+
docker compose ps
41+
docker compose logs web
42+
docker compose logs database_default
43+
44+
- name: Execute django check
45+
run: docker compose exec -w /app web python manage.py check --deploy
46+
47+
- name: Execute test suite
48+
run: docker compose exec -w /app web python manage.py test
49+
50+
- name: Terminate all components
51+
if: always()
52+
run: docker compose down -v

.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Python
2+
*.pyc
3+
*.pyo
4+
db.sqlite3
5+
6+
# Django
7+
/staticfiles_collected/
8+
9+
# Divio
10+
.divio
11+
/data.tar.gz
12+
/data
13+
14+
15+
# OS-specific patterns - add your own here
16+
.DS_Store
17+
.DS_Store?
18+
._*
19+
.Spotlight-V100
20+
.Trashes
21+
22+
.idea/
23+
.env

Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM python:3.11
2+
3+
WORKDIR /app
4+
5+
RUN python -m pip install --upgrade pip
6+
7+
# optimizing the docker caching behaviour
8+
COPY requirements.txt .
9+
RUN python -m pip install --no-cache-dir -r requirements.txt
10+
COPY . .
11+
12+
RUN python manage.py collectstatic --noinput
13+
14+
CMD uwsgi --http=0.0.0.0:80 --module=backend.wsgi

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Divio
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.rst

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
|pythonapp|
2+
3+
#####################
4+
django CMS quickstart
5+
#####################
6+
7+
- A dockerised django CMS project intended to be run locally in Docker on your own machine or on a Docker-based cloud, such as `Divio <https://www.divio.com/>`_
8+
- This version uses Python 3.11 and the most up-to-date versions of Django 4.2, and django CMS 4.1.0
9+
- 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.
10+
- The documentation for django CMS can be found here: https://docs.django-cms.org/
11+
12+
Installation
13+
############
14+
15+
Requirements
16+
============
17+
18+
You need to have Docker installed on your system to run this project.
19+
20+
- `Install Docker <https://docs.docker.com/engine/install/>`_ here.
21+
- If you have not used docker in the past, please read this
22+
`introduction on docker <https://docs.docker.com/get-started/>`_ here.
23+
24+
Local Setup
25+
===========
26+
27+
.. inclusion-marker-do-not-remove
28+
29+
.. code-block:: bash
30+
31+
git clone [email protected]:django-cms/django-cms-quickstart.git
32+
cd django-cms-quickstart
33+
docker compose build web
34+
docker compose up -d database_default
35+
docker compose run --rm web python manage.py migrate
36+
docker compose run --rm web python manage.py createsuperuser
37+
docker compose up -d
38+
39+
Then open http://django-cms-quickstart.127.0.0.1.nip.io:8000 (or just http://127.0.0.1:8000) in your browser.
40+
41+
You can stop the server with ``docker compose stop`` without destroying the containers and restart it with
42+
``docker compose start``.
43+
44+
With ``docker compose down`` the containers are deleted, but the database content is still preserved in the named
45+
volume ``django-cms-quickstart_postgres-data`` and the media files are stored in the file system in ``data/media``.
46+
Then you can update the project e. g. by changing the requirements and settings. Finally you can rebuild the web image
47+
and start the server again:
48+
49+
.. code-block:: bash
50+
51+
docker compose build web
52+
docker compose up -d
53+
54+
55+
Note: Since Compose V2, ``docker-compose`` is now included inside docker. For more information, checkout the
56+
`Compose V2 <https://docs.docker.com/compose/cli-command/>`_ Documentation.
57+
58+
.. inclusion-end-marker-do-not-remove
59+
60+
Customising the project
61+
#######################
62+
63+
This project is ready-to-go without making any changes at all, but also gives you some options.
64+
65+
As-is, it will include a number of useful django CMS plugins and Bootstrap 4 for the frontend. You don't have to use
66+
these; they're optional. If you don't want to use them, read through the ``settings.py`` and ``requirements.txt`` files
67+
to see sections that can be removed - in each case, the section is noted with a comment containing the word 'optional'.
68+
69+
Options are also available for using Postgres/MySQL, uWSGI/Gunicorn/Guvicorn, etc.
70+
71+
Updating requirements
72+
=====================
73+
74+
The project uses a django best practise two step approach, freezing all dependencies with pip-tools. Here is how to update requirements:
75+
76+
1. Change ``requirements.in`` according to your needs. There is no need to pin the package versions here unless you have a good reason (i.e. known incompatibilities)
77+
2. Run ``docker compose run --rm web pip-compile requirements.in >> requirements.txt``
78+
3. ``requirements.txt`` should now have changed
79+
4. Rebuild the container ``docker compose build web`` and restart ``docker compose up -d``
80+
81+
Features
82+
########
83+
84+
Static Files with Whitenoise
85+
============================
86+
87+
- This quickstart demo has a cloud-ready static files setup via django-whitenoise.
88+
- 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.
89+
- 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.
90+
91+
Env variables
92+
=============
93+
94+
- By default, Docker injects the env vars defined in ``.env-local`` into the quickstart project.
95+
- If you want to access the PostgreSQL database from the host system, set ``DB_PORT`` to the desired port number.
96+
5432 is the standard port number. If you run PosgreSQL on your host system, you may want to set another port number.
97+
If this variable is empty (the default), the PosgreSQL instance in the container is only reachable within docker, but
98+
not from outside.
99+
100+
Contribution
101+
############
102+
103+
Here is the official django CMS repository:
104+
`https://github.com/django-cms/django-cms-quickstart/ <https://github.com/django-cms/django-cms-quickstart/>`_.
105+
106+
107+
Deployment
108+
##########
109+
110+
Note that this is just a demo project to get you started. It is designed to be run locally through docker. If you want a full production ready site with all the bells
111+
and whistles we recommend you have a look at https://github.com/django-cms/djangocms-template instead.
112+
113+
Some deployment hints:
114+
115+
- To deploy this project in testing mode (recommended) set the environment variable ``DEBUG`` to ``True`` in your hosting environment.
116+
- Be aware that 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``.
117+
- You can set the env var ``DEFAULT_STORAGE_DSN`` to something meaningful (i.e. for s3 file storage)
118+
119+
Deployment Commands
120+
===================
121+
122+
Configure your hosting environment to run the following commands on every deployment:
123+
124+
- ``./manage.py migrate``
125+
126+
127+
Divio Deployment
128+
================
129+
130+
divio.com is a cloud hosting platform optimized for django web applications. It's the quickest way to deploy this
131+
project. Here is a `video tutorial <https://www.youtube.com/watch?v=O2g5Wfoyp7Q>`_ and a
132+
`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.
133+
134+
135+
.. |pythonapp| image:: https://github.com/django-cms/django-cms-quickstart/workflows/Python%20application/badge.svg?branch=support/cms-4.1.x

backend/__init__.py

Whitespace-only changes.

backend/asgi.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
ASGI config for quickstart project.
3+
4+
It exposes the ASGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.asgi import get_asgi_application
13+
14+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')
15+
16+
application = get_asgi_application()

0 commit comments

Comments
 (0)