Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
df4b665
feat: add an action with pythonpackage.yml
vinitkumar Feb 3, 2021
0d48496
Merge pull request #1 from SocialSchools/feat/enable-github-actions
vinitkumar Feb 5, 2021
d2f2f64
feat: update readme to make the wording a bit generic
vinitkumar Feb 5, 2021
1c8397a
feat: fix typo on link
vinitkumar Feb 5, 2021
275e0b0
Merge pull request #2 from SocialSchools/feat/update-readme
NicolaiRidani Feb 5, 2021
81eafb3
feat: try building on more versions of pythona and OSes
vinitkumar Feb 5, 2021
3c17be9
fix: container operations only on linux containers
vinitkumar Feb 5, 2021
08a0ea2
Merge pull request #3 from SocialSchools/feat/add-more-python-support…
vinitkumar Feb 5, 2021
7c5f996
Add Github actions badge To Readme
vinitkumar Feb 5, 2021
11fa982
fix: postgres was not getting init because of wrong url
vinitkumar Mar 5, 2021
b6a73f0
fix: wrong db name
vinitkumar Mar 5, 2021
20cf675
Merge pull request #5 from SocialSchools/fix/issue-with-postgres-not-…
vinitkumar Mar 5, 2021
f8b577e
upgrade to django CMS 3.9
Aug 14, 2021
ebbcf93
fully support static files serving (also for local dev env)
Aug 14, 2021
5640fc0
simplify db setup
Aug 14, 2021
e3507cb
standardize app name
Aug 14, 2021
0f846ef
add static files for whitenoise demo
Aug 14, 2021
fce402a
move static folder to backend where it belongs
Aug 14, 2021
17f2aff
fix collectstatic best practises
Aug 14, 2021
043dcee
allow for simpler production deployment
Aug 14, 2021
2ce534f
better deployment docs
Aug 14, 2021
6b1f8c5
standardize DEBUG env var
Aug 14, 2021
dd9c5ac
fix DEBUG env var in local dev env
Aug 14, 2021
f257bfb
make allowed hosts work
Aug 14, 2021
aabd2ea
clean up static files
Aug 14, 2021
d682b11
deployment docs
Aug 18, 2021
50f5beb
test version with filer RC4 and bootstrap5
Sep 16, 2021
4e6a86a
TASK: Update docker-compose command.
Sep 20, 2021
a22bcc7
Merge pull request #10 from crydotsnake/main
Sep 20, 2021
92d32a6
Merge pull request #8 from django-cms/develop
Sep 24, 2021
689621b
FIX: docker-compose commands
Sep 24, 2021
2ce54ba
TASK: Update docker compose commands
Sep 29, 2021
38fedf7
Merge pull request #12 from crydotsnake/main
Sep 29, 2021
7daabb1
Merge pull request #13 from django-cms/main
Sep 29, 2021
ba91d6f
use frozen requirements
Oct 1, 2021
2da9805
Update docker-compose.yml
jpVm5jYYRE1VIKL Oct 11, 2021
965842a
Merge pull request #19 from jpVm5jYYRE1VIKL/patch-4
Oct 20, 2021
6979824
revert to bs4 (as bs5 is still a bit broken)
Oct 20, 2021
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
4 changes: 2 additions & 2 deletions .env-local
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DATABASE_URL=postgres://postgres@database_default:5432/db
DATABASE_URL=postgres://postgres:password@database_default:5432/db
DEFAULT_STORAGE_DSN=file:///data/media/?url=%2Fmedia%2F
DJANGO_DEBUG=True
DEBUG=True
DOMAIN_ALIASES=localhost, 127.0.0.1
SECURE_SSL_REDIRECT=False
62 changes: 62 additions & 0 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Python application

on: [push, pull_request]

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: [3.8, 3.9, pypy3]
os: [
ubuntu-20.04,
ubuntu-18.04,
]

services:
postgres:
image: postgres:12
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- 5432:5432
# needed because the postgres container does not provide a healthcheck
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

steps:
- uses: actions/checkout@v1
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Configure sysctl limits
run: |
sudo swapoff -a
sudo sysctl -w vm.swappiness=1
sudo sysctl -w fs.file-max=262144
sudo sysctl -w vm.max_map_count=262144

- uses: getong/elasticsearch-action@v1.2
with:
elasticsearch version: '2.3'
host port: 9200
container port: 9200
host node port: 9300
node port: 9300
discovery type: 'single-node'
- name: psycopg2 prerequisites
run: sudo apt-get install python-dev libpq-dev
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pytest-django
- name: Run migrations
run: python manage.py migrate
- name: Validate Project
run: python manage.py check
- name: Run Tests
run: python manage.py test
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
db.sqlite3

# Django
/staticfiles
/staticfiles_collected/

# Divio
.divio
Expand All @@ -18,3 +18,5 @@ db.sqlite3
._*
.Spotlight-V100
.Trashes

.idea/
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM python:3.8
FROM python:3.9
WORKDIR /app
COPY . /app
RUN pip install -r requirements.txt
RUN python manage.py collectstatic --noinput
CMD uwsgi --http=0.0.0.0:80 --module=quickstart.wsgi
CMD uwsgi --http=0.0.0.0:80 --module=backend.wsgi
70 changes: 54 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
# django CMS Divio quickstart
![Python application](https://github.com/django-cms/django-cms-quickstart/workflows/Python%20application/badge.svg?branch=main)

A Dockerised django CMS project, ready to deploy on Divio or another Docker-based cloud platform, and run
locally in Docker on your own machine. A Divio account is not required.
# django CMS quickstart

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.

This version uses Python 3.8 running and the most up-to-date versions of Django 3.1 and django CMS 3.8.

## Installation

You need to have docker installed on your system to run this project.

- [Install Docker](https://docs.docker.com/engine/install/) here.
- If you have not used docker in the past, please read this [introduction on docker](https://docs.docker.com/get-started/) here.

## Try it

```bash
git clone git@github.com:divio/django-cms-divio-quickstart.git
cd django-cms-divio-quickstart
docker-compose build
docker-compose run web python manage.py migrate
docker-compose run web python manage.py createsuperuser
docker-compose up
open http://127.0.0.1:8000
git clone git@github.com:django-cms/django-cms-quickstart.git
cd django-cms-quickstart
docker compose build web
docker compose up -d database_default
docker compose run web python manage.py migrate
docker compose run web python manage.py createsuperuser
docker compose up -d
```

For a more complete how-to guide to this project, see [Deploy a new django CMS project using the Divio quickstart
repository](https://docs.divio.com/en/latest/how-to/django-cms-deploy-quickstart/) in the [Divio Developer
Handbook](https://docs.divio.com).

Then open http://django-cms-quickstart.127.0.0.1.nip.io:8000 (or just http://127.0.0.1:8000) in your browser.

## Customising the project

Expand All @@ -33,5 +37,39 @@ see sections that can be removed - in each case, the section is noted with a com

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

Again, see [Deploy a new django CMS project using the Divio quickstart
repository](https://docs.divio.com/en/latest/how-to/django-cms-deploy-quickstart/) for more guidance on customisation.
#### Updating requirements

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/

## Features

### Static Files with Whitenoise

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

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.

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.

## Contribution

Here is the official django CMS repository: [https://github.com/django-cms/django-cms-quickstart/](https://github.com/django-cms/django-cms-quickstart/).


## Deployment

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.

#### Env variables
- to deploy this project in testing mode (recommended) set the environment variable `DEBUG` to `True` in your hosting environment.
- 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`.
- If you want the media hosted on S3 set the `DEFAULT_FILE_STORAGE` variable accordingly.

#### Deployment Commands
Configure your hosting environment to run the following commands on every deployment:
- `./manage.py migrate`


#### Divio Deployment

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.
File renamed without changes.
2 changes: 1 addition & 1 deletion quickstart/asgi.py → backend/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'quickstart.settings')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')

application = get_asgi_application()
60 changes: 29 additions & 31 deletions quickstart/settings.py → backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@
SECRET_KEY = os.environ.get('SECRET_KEY', '<a string of random characters>')

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

DIVIO_DOMAIN = os.environ.get('DOMAIN', '')
DIVIO_DOMAIN_ALIASES = [
d.strip()
for d in os.environ.get('DOMAIN_ALIASES', '').split(',')
if d.strip()
]
ALLOWED_HOSTS = [DIVIO_DOMAIN] + DIVIO_DOMAIN_ALIASES
ALLOWED_HOSTS = [os.environ.get('DOMAIN'),]
if DEBUG:
ALLOWED_HOSTS = ["*",]

# Redirect to HTTPS by default, unless explicitly disabled
SECURE_SSL_REDIRECT = os.environ.get('SECURE_SSL_REDIRECT') != "False"
Expand All @@ -30,7 +26,7 @@
# Application definition

INSTALLED_APPS = [
'quickstart',
'backend',

# optional, but used in most projects
'djangocms_admin_style',
Expand All @@ -40,6 +36,7 @@
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'whitenoise.runserver_nostatic', # http://whitenoise.evans.io/en/stable/django.html#using-whitenoise-in-development
'django.contrib.staticfiles',
'django.contrib.sites',

Expand Down Expand Up @@ -100,7 +97,7 @@
'cms.middleware.language.LanguageCookieMiddleware',
]

ROOT_URLCONF = 'quickstart.urls'
ROOT_URLCONF = 'backend.urls'

TEMPLATES = [
{
Expand Down Expand Up @@ -129,13 +126,14 @@
CMS_TEMPLATES = [
# a minimal template to get started with
('minimal.html', 'Minimal template'),
('whitenoise-static-files-demo.html', 'Static File Demo'),

# optional templates that extend base.html, to be used with Bootstrap 4
('page.html', 'Page'),
('feature.html', 'Page with Feature')
# optional templates that extend base.html, to be used with Bootstrap 5
('page.html', 'Bootstrap 4 Demo'),
('feature.html', 'Bootstrap 4 Demo with two placeholders')
]

WSGI_APPLICATION = 'quickstart.wsgi.application'
WSGI_APPLICATION = 'backend.wsgi.application'


# Database
Expand All @@ -144,27 +142,27 @@
# Configure database using DATABASE_URL; fall back to sqlite in memory when no
# environment variable is available, e.g. during Docker build
DATABASE_URL = os.environ.get('DATABASE_URL', 'sqlite://:memory:')

DATABASES = {'default': dj_database_url.parse(DATABASE_URL)}


# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
if not DEBUG:
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


# Internationalization
Expand All @@ -189,7 +187,7 @@
# https://docs.djangoproject.com/en/3.1/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles_collected')
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

# Media files
Expand All @@ -202,7 +200,7 @@
DefaultStorageClass = dsn_configured_storage_class('DEFAULT_STORAGE_DSN')

# Django's DEFAULT_FILE_STORAGE requires the class name
DEFAULT_FILE_STORAGE = 'quickstart.settings.DefaultStorageClass'
DEFAULT_FILE_STORAGE = 'backend.settings.DefaultStorageClass'

# only required for local file storage and serving, in development
MEDIA_URL = 'media/'
Expand Down
Binary file added backend/static/django-cms-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<title>{% block title %}This is my new project home page{% endblock title %}</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<!-- <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous"> -->
{% render_block "css" %}
</head>
<body>
Expand All @@ -28,7 +29,9 @@
</div>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<!-- <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script> -->
{% render_block "js" %}
</body>
</html>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions backend/templates/whitenoise-static-files-demo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% load cms_tags sekizai_tags static %}
<html>
<head>
<title>{% page_attribute "page_title" %}</title>
{% render_block "css" %}
</head>
<body>
{% cms_toolbar %}

<img src="{% static "django-cms-logo.png" %}" \/>

{% placeholder "content" %}
{% render_block "js" %}
</body>
</html>
5 changes: 4 additions & 1 deletion quickstart/urls.py → backend/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@
if settings.DEBUG:
urlpatterns.extend(static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT))

urlpatterns.append(path('', include('cms.urls')))
urlpatterns.append(path('', include('cms.urls')))

# the new django admin sidebar is bad UX in django CMS custom admin views.
admin.site.enable_nav_sidebar = False
4 changes: 2 additions & 2 deletions quickstart/wsgi.py → backend/wsgi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
WSGI config for quickstart project.
WSGI config for backend project.

It exposes the WSGI callable as a module-level variable named ``application``.

Expand All @@ -11,6 +11,6 @@

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'quickstart.settings')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')

application = get_wsgi_application()
Loading