From 742f249db88f4d3fd910c459acbac0216d5efd0f Mon Sep 17 00:00:00 2001 From: Mario Colombo Date: Tue, 20 Aug 2024 23:43:47 -0600 Subject: [PATCH] support for djangocms-text (#65) * support for djangocms-text * add --rm to docker compose run commands * Update requirements.txt upgrade djangocms-text * switch Manifest mode on again --------- Co-authored-by: Mario Colombo --- .dockerignore | 2 + Dockerfile | 8 ++-- README.rst | 12 ++++-- backend/settings.py | 34 +++++++++------- compose.yaml | 4 +- requirements.in | 8 ++-- requirements.txt | 96 +++++++++++++++++++++------------------------ 7 files changed, 85 insertions(+), 79 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..85dcc16 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +.git +node_modules diff --git a/Dockerfile b/Dockerfile index 0445706..aea13e7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,10 +2,12 @@ FROM python:3.11 WORKDIR /app -COPY . . - RUN python -m pip install --upgrade pip -RUN python -m pip install -r requirements.txt + +# optimizing the docker caching behaviour +COPY requirements.txt . +RUN python -m pip install --no-cache-dir -r requirements.txt +COPY . . RUN python manage.py collectstatic --noinput diff --git a/README.rst b/README.rst index c0e6654..c735272 100644 --- a/README.rst +++ b/README.rst @@ -35,8 +35,8 @@ Try it 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 run --rm web python manage.py migrate + docker compose run --rm web python manage.py createsuperuser docker compose up -d Then open http://django-cms-quickstart.127.0.0.1.nip.io:8000 (or just http://127.0.0.1:8000) in your browser. @@ -74,8 +74,12 @@ Options are also available for using Postgres/MySQL, uWSGI/Gunicorn/Guvicorn, et 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/ +The project uses a django best practise two step approach, freezing all dependencies with pip-tools. Here is how to update requirements: + +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) +2. Run `docker compose run --rm web pip-compile requirements.in >> requirements.txt` +3. `requirements.txt` should now have changed +4. Rebuild the container `docker compose build web` and restart `docker compose up -d` Features ######## diff --git a/backend/settings.py b/backend/settings.py index f0c503f..14314ea 100644 --- a/backend/settings.py +++ b/backend/settings.py @@ -57,8 +57,8 @@ 'djangocms_alias', 'parler', - # the default CKEditor - optional, but used in most projects - 'djangocms_text_ckeditor', + # the next-gen text editor - optional, but used in most projects + 'djangocms_text', # optional django CMS frontend modules 'djangocms_frontend', @@ -194,25 +194,31 @@ # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/3.1/howto/static-files/ -STATIC_URL = '/static/' -STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles_collected') -STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' - -# Media files -# DEFAULT_FILE_STORAGE is configured using DEFAULT_STORAGE_DSN +STATICFILES_DIRS = [ # this are were django staticfiles is looking for sources + BASE_DIR / "backend" / "static", +] -# read the setting value from the environment variable -DEFAULT_STORAGE_DSN = os.environ.get('DEFAULT_STORAGE_DSN') +STATIC_URL = '/static/' +STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles_collected') # this is were the collected files are placed -# dsn_configured_storage_class() requires the name of the setting +# read the setting value from the environment variable. This functionality is +# provided by https://github.com/divio/django-storage-url +DEFAULT_STORAGE_DSN = os.environ.get('DEFAULT_STORAGE_DSN', '/data/media/') DefaultStorageClass = dsn_configured_storage_class('DEFAULT_STORAGE_DSN') -# Django's DEFAULT_FILE_STORAGE requires the class name -DEFAULT_FILE_STORAGE = 'backend.settings.DefaultStorageClass' +STORAGES = { + 'default': { + 'BACKEND': 'backend.settings.DefaultStorageClass', + }, + 'staticfiles': { + 'BACKEND': 'whitenoise.storage.CompressedManifestStaticFilesStorage', + # 'BACKEND': 'whitenoise.storage.CompressedStaticFilesStorage', + }, +} # only required for local file storage and serving, in development MEDIA_URL = 'media/' -MEDIA_ROOT = os.path.join('/data/media/') +MEDIA_ROOT = '/data/media/' SITE_ID = 1 diff --git a/compose.yaml b/compose.yaml index 83e7d00..609ea67 100644 --- a/compose.yaml +++ b/compose.yaml @@ -1,5 +1,3 @@ -version: "3" - services: web: # the application's web service (container) will use an image based on our Dockerfile @@ -40,4 +38,4 @@ networks: djangocmsnet: volumes: - postgres-data: \ No newline at end of file + postgres-data: diff --git a/requirements.in b/requirements.in index 80573f3..d8b3bb6 100644 --- a/requirements.in +++ b/requirements.in @@ -5,7 +5,7 @@ boto3 psycopg2 uwsgi -django<5 +django<=6 dj-database-url django-storage-url whitenoise @@ -19,12 +19,12 @@ djangocms-alias>=2.0.0 # optional, but used in most projects djangocms-admin-style>=3.2.2 -# the default CKEditor - optional, but used in most projects -djangocms-text-ckeditor>=5.1.2 +# the next-gen text editor +djangocms-text # optional django CMS frontend -djangocms-frontend!=1.2.1 +djangocms-frontend django-filer diff --git a/requirements.txt b/requirements.txt index 8c9a4e8..a0aee1e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,18 +1,18 @@ # -# This file is autogenerated by pip-compile with Python 3.11 +# This file is autogenerated by pip-compile with Python 3.12 # by the following command: # # pip-compile --output-file=requirements.txt requirements.in # -asgiref==3.7.2 +asgiref==3.8.1 # via django -boto3==1.34.11 +boto3==1.35.2 # via -r requirements.in -botocore==1.34.11 +botocore==1.35.2 # via # boto3 # s3transfer -build==1.0.3 +build==1.2.1 # via pip-tools chardet==5.2.0 # via reportlab @@ -20,13 +20,12 @@ click==8.1.7 # via pip-tools cssselect2==0.7.0 # via svglib -dj-database-url==2.1.0 +dj-database-url==2.2.0 # via -r requirements.in -django==4.2.8 +django==4.2.15 # via # -r requirements.in # dj-database-url - # django-appconf # django-classy-tags # django-cms # django-entangled @@ -35,7 +34,6 @@ django==4.2.8 # django-parler # django-polymorphic # django-sekizai - # django-select2 # django-storage-url # django-storages # django-treebeard @@ -44,29 +42,27 @@ django==4.2.8 # djangocms-frontend # djangocms-versioning # easy-thumbnails -django-appconf==1.0.6 - # via django-select2 django-classy-tags==4.1.0 # via # django-cms # django-sekizai -django-cms==4.1.0 +django-cms==4.1.2 # via # -r requirements.in # djangocms-alias # djangocms-attributes-field # djangocms-frontend - # djangocms-text-ckeditor + # djangocms-text # djangocms-versioning django-entangled==0.5.4 # via djangocms-frontend -django-filer==3.1.1 +django-filer==3.1.4 # via # -r requirements.in # djangocms-frontend django-formtools==2.5.1 # via django-cms -django-fsm==2.8.1 +django-fsm==2.8.2 # via djangocms-versioning django-parler==2.3 # via djangocms-alias @@ -74,99 +70,97 @@ django-polymorphic==3.1.0 # via django-filer django-sekizai==4.1.0 # via django-cms -django-select2==8.1.2 - # via djangocms-frontend django-storage-url==0.12.0 # via -r requirements.in -django-storages==1.14.2 +django-storages==1.14.4 # via django-storage-url -django-treebeard==4.7 +django-treebeard==4.7.1 # via django-cms -djangocms-admin-style==3.2.6 +djangocms-admin-style==3.3.1 # via # -r requirements.in # django-cms -djangocms-alias==2.0.0 +djangocms-alias==2.0.1 # via -r requirements.in djangocms-attributes-field==3.0.0 # via djangocms-frontend -djangocms-frontend==1.2.2 +djangocms-frontend==1.3.3 # via -r requirements.in -djangocms-text-ckeditor==5.1.5 - # via - # -r requirements.in - # djangocms-frontend -djangocms-versioning==2.0.0 +djangocms-text==0.2.2 + # via -r requirements.in +djangocms-versioning==2.0.2 # via -r requirements.in -easy-thumbnails[svg]==2.8.5 +easy-thumbnails[svg]==2.9 # via # -r requirements.in # django-filer # djangocms-frontend furl==2.1.3 # via django-storage-url -html5lib==1.1 - # via djangocms-text-ckeditor jmespath==1.0.1 # via # boto3 # botocore -lxml==5.0.0 - # via svglib +lxml==5.3.0 + # via + # djangocms-text + # svglib +nh3==0.2.18 + # via djangocms-text orderedmultidict==1.0.1 # via furl -packaging==23.2 +packaging==24.1 # via # build # django-cms - # djangocms-text-ckeditor -pillow==10.1.0 + # djangocms-text +pillow==10.4.0 # via - # djangocms-text-ckeditor + # djangocms-text # easy-thumbnails # reportlab -pip-tools==7.3.0 +pip-tools==7.4.1 # via -r requirements.in psycopg2==2.9.9 # via -r requirements.in -pyproject-hooks==1.0.0 - # via build -python-dateutil==2.8.2 +pyproject-hooks==1.1.0 + # via + # build + # pip-tools +python-dateutil==2.9.0.post0 # via botocore -reportlab==4.0.8 +reportlab==4.2.2 # via # easy-thumbnails # svglib -s3transfer==0.10.0 +s3transfer==0.10.2 # via boto3 six==1.16.0 # via # furl - # html5lib # orderedmultidict # python-dateutil -sqlparse==0.4.4 +sqlparse==0.5.1 # via django svglib==1.5.1 # via easy-thumbnails -tinycss2==1.2.1 +tinycss2==1.3.0 # via # cssselect2 # svglib -typing-extensions==4.9.0 +typing-extensions==4.12.2 # via dj-database-url -urllib3==2.0.7 +urllib3==2.2.2 # via botocore -uwsgi==2.0.23 +uwsgi==2.0.26 # via -r requirements.in webencodings==0.5.1 # via # cssselect2 - # html5lib # tinycss2 -wheel==0.42.0 +wheel==0.44.0 # via pip-tools -whitenoise==6.6.0 +whitenoise==6.7.0 # via -r requirements.in # The following packages are considered to be unsafe in a requirements file: