Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade stacks #1462

Open
wants to merge 34 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
0b06254
Upgrade to python 3.12, postgresql 16
Xpirix May 23, 2024
5a5075c
Update to Django 4, update other packages in REQUIREMENTS.txt
Xpirix May 23, 2024
021023b
Fix various errors related to Django 4 update in the code
Xpirix May 23, 2024
2e1bf7f
Update migrations for Django 4 update
Xpirix May 23, 2024
e2fa7b1
Django 4 update: Some fixes in Dockerfile, requirements and settings
Xpirix May 23, 2024
5c341dc
Django 4 update: Fix deprecated ifequal condition
Xpirix May 24, 2024
04ba67e
Django 4 update: Fix the django-hashedfilenamestorage package
Xpirix May 24, 2024
56a4d6a
Django 4 update: Fix deprecated assertEquals in tests
Xpirix May 24, 2024
b13ec1b
Django 4 update: Fix bootstrap template issue
Xpirix May 24, 2024
01e6014
Django 4 update: Update for djstripe in certificate.py
Xpirix May 27, 2024
6d2bc03
Django 4 update: Revert to dj-stripe 2.1.1 with custom fixes
Xpirix May 27, 2024
f347021
Django 4 update: Fix deprecated ifnotequal
Xpirix May 27, 2024
7b9c707
Django 4 update: Fix failing delete views
Xpirix May 30, 2024
3dd167d
Django 4 update: Fix deprecated pypandoc and markdown
Xpirix May 31, 2024
16a5e5d
Django 4 update: Update docker-compose and makefile
Xpirix May 31, 2024
09088f2
Django 4 update: Add VALID_DOMAIN to environment variable
Xpirix Jun 3, 2024
9c54473
Add media, static, backups to the environment variable
Xpirix Jun 3, 2024
fd009b9
Apply modifications from the production server
Xpirix Jun 3, 2024
c37f66e
Add all email variables to the env variable
Xpirix Jun 3, 2024
6c0c8da
Set default values in .env.example
Xpirix Jun 3, 2024
b4f5fef
Merge branch 'develop' of github.com:kartoza/prj.app into upgrade_stacks
Xpirix Jul 4, 2024
987719f
Bump to version 3.0.0
Xpirix Jul 4, 2024
39c5b44
Merge 'develop' to 'upgrade_stacks'
Xpirix Aug 1, 2024
2b08ff7
Fix changelog file download
Xpirix Aug 1, 2024
e856d7a
Ignore long lines in flake, fix test_python_style
Xpirix Aug 1, 2024
c44236c
Revert docker-compose override volumes setup
Xpirix Sep 24, 2024
da876fb
Update makefile to use docker compose
Xpirix Sep 24, 2024
7eb1899
Init static and media volumes in docker-compose file
Xpirix Sep 24, 2024
b464440
Disabel smtp service for now
Xpirix Sep 24, 2024
98ffc2f
Comment smtp dependency
Xpirix Sep 24, 2024
6ee5c50
Update github workflow to use docker compose
Xpirix Sep 24, 2024
c177a91
Fix djstripe dependency
Xpirix Sep 24, 2024
31dab10
Add pyjwt to requirements
Xpirix Sep 24, 2024
954fd27
Fix container name for GH actions
Xpirix Sep 24, 2024
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
27 changes: 27 additions & 0 deletions deployment/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,30 @@ HTTPS_PORT=443
# Django debug server config
TEST_HTTP_PORT=61202
SSH_PORT=61203

# Volumes
MEDIA_VOLUME=./media
STATIC_VOLUME=./static
BACKUPS_VOLUME=./backups

# VALID_DOMAIN
VALID_DOMAIN=["localhost", "changelog.kartoza.com", "staging.changelog.kartoza.com","changelog.qgis.org", "staging.changelog.qgis.org"]

# Email
EMAIL_BACKEND='django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST=''
EMAIL_PORT=25
EMAIL_USE_TLS=True
EMAIL_HOST_USER=''
EMAIL_HOST_PASSWORD=''
EMAIL_SUBJECT_PREFIX=''
MAILDOMAIN=''
SERVER_EMAIL=''
ADMIN_EMAIL=''
DEFAULT_FROM_EMAIL=''

# Stripe
STRIPE_LIVE_SECRET_KEY='sk_live_key'
STRIPE_LIVE_PUBLIC_KEY='pk_live_key'
STRIPE_LIVE_MODE=True
DJSTRIPE_WEBHOOK_SECRET='whsec_'
12 changes: 3 additions & 9 deletions deployment/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ web:
@# This one runs the postgis-backup cron container
@# We add --no-recreate so that it does not destroy & recreate the db container
@docker-compose up --no-recreate --no-deps -d dbbackups
@docker-compose up -d btsync-db
@docker-compose up -d btsync-media

permissions:
# Probably we want something more granular here....
Expand Down Expand Up @@ -121,8 +119,6 @@ kill:
@echo "Killing in production mode"
@echo "------------------------------------------------------------------"
@docker-compose kill
@docker-compose kill btsync-db
@docker-compose kill btsync-media

rm: dbbackup rm-only

Expand Down Expand Up @@ -214,14 +210,14 @@ dbrestore:
@echo "stopping uwsgi container"
@docker-compose stop uwsgi
@source .env; echo "dropping $$DATABASE_NAME"
@docker-compose exec -e DATABASE_NAME db bash -c 'su - postgres -c "dropdb $${DATABASE_NAME}"'
-@docker-compose exec -e DATABASE_NAME db bash -c 'su - postgres -c "dropdb --force $${DATABASE_NAME}"'
@source .env; echo "creating $$DATABASE_NAME"
@docker-compose exec -e DATABASE_NAME db bash -c 'su - postgres -c "createdb -O docker -T template_postgis $${DATABASE_NAME}"'
-@docker-compose exec -e DATABASE_NAME db bash -c 'su - postgres -c "createdb -O docker -T template1 $${DATABASE_NAME}"'
@source .env; echo "restoring $$DATABASE_NAME"
@# Because we pipe from one docker command to another and we are going
@# to execute this Make command from a remote server at times, we need to using use interactive mode (-i)
@# in the first command and not use terminal (-t) in the second. Please do not change these!
@docker-compose exec -e DATABASE_NAME db /bin/bash -c 'pg_restore /backups/latest.dmp | su - postgres -c "psql $${DATABASE_NAME}"'
-@docker-compose exec -e DATABASE_NAME db bash -c 'su - postgres -c "pg_restore -c /backups/latest.dmp -d gis"'
@docker-compose start uwsgi
@echo "starting uwsgi container"

Expand Down Expand Up @@ -267,8 +263,6 @@ mediasync:
@echo "------------------------------------------------------------------"
@rsync -av --progress changelog.kartoza.com:/home/projecta/deployment/media/ media
@rsync -av --progress changelog.kartoza.com:/home/projecta/django_project/core/settings/secret.py ../django_project/core/settings/
@rsync -av --progress changelog.kartoza.com:/home/projecta/deployment/btsync-db.env btsync-db.env.PRODUCTION
@rsync -av --progress changelog.kartoza.com:/home/projecta/deployment/btsync-media.env btsync-media.env.PRODUCTION

dbsync:
@echo
Expand Down
7 changes: 6 additions & 1 deletion deployment/docker-compose.override.example.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
## docker-compose override recipe sample
## Intended to be used to override default recipe for development environment
## Copy paste it as docker-compose.override.yml to use
version: '3'
volumes:
postgres-data:
driver_opts:
Expand Down Expand Up @@ -41,11 +40,15 @@ services:
target: prod
volumes:
- ../django_project:/home/web/django_project
- ${MEDIA_VOLUME}:/home/web/media:rw
- ${STATIC_VOLUME}:/home/web/static:rw
- ./logs:/var/log

web:
volumes:
- ./logs:/var/log/nginx
- ${MEDIA_VOLUME}:/home/web/media:ro
- ${STATIC_VOLUME}:/home/web/static:ro
ports:
- "${HTTP_PORT}:8080"
- "${HTTPS_PORT}:443"
Expand All @@ -58,6 +61,8 @@ services:
target: dev
volumes:
- ../django_project:/home/web/django_project
- ${MEDIA_VOLUME}:/home/web/media:rw
- ${STATIC_VOLUME}:/home/web/static:rw
- ./logs:/var/log
ports:
- "${TEST_HTTP_PORT}:8080"
Expand Down
60 changes: 33 additions & 27 deletions deployment/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@
# docker-compose up -d web
#
# See accompanying Make commands for easy collectstatic etc.
version: '3'
volumes:
postgres-data:
db-backups:
static-data:
media-data:
reports-data:
nginx-conf:
services:
smtp:
image: catatnight/postfix
Expand All @@ -25,20 +20,23 @@ services:
restart: unless-stopped

db:
image: kartoza/postgis:9.6-2.4
image: kartoza/postgis:16-3.4
volumes:
- postgres-data:/var/lib/postgresql
- db-backups:/backups
environment:
- USERNAME=${DATABASE_USERNAME}
- PASS=${DATABASE_PASSWORD}
- POSTGRES_USER=${DATABASE_USERNAME}
- POSTGRES_PASS=${DATABASE_PASSWORD}
- ALLOW_IP_RANGE=0.0.0.0/0
restart: unless-stopped
ports:
- "7543:5432"

uwsgi: &uwsgi-common
image: kartoza/projecta-uwsgi
build:
context: ${PWD}/../
dockerfile: deployment/docker/Dockerfile
target: prod
environment:
- DATABASE_NAME=${DATABASE_NAME}
- DATABASE_USERNAME=${DATABASE_USERNAME}
Expand All @@ -47,12 +45,29 @@ services:
- DJANGO_SETTINGS_MODULE=${DJANGO_SETTINGS_MODULE}
- VIRTUAL_HOST=${VIRTUAL_HOST}
- VIRTUAL_PORT=${VIRTUAL_PORT}
- VALID_DOMAIN=${VALID_DOMAIN}
- EMAIL_BACKEND=${EMAIL_BACKEND}
- EMAIL_HOST=${EMAIL_HOST}
- EMAIL_PORT=${EMAIL_PORT}
- EMAIL_USE_TLS=${EMAIL_USE_TLS}
- EMAIL_HOST_USER=${EMAIL_HOST_USER:-automation}
- EMAIL_HOST_PASSWORD=${EMAIL_HOST_PASSWORD}
- EMAIL_SUBJECT_PREFIX=${EMAIL_SUBJECT_PREFIX}
- MAILDOMAIN=${MAILDOMAIN}
- DEFAULT_FROM_EMAIL=${DEFAULT_FROM_EMAIL}
- STRIPE_LIVE_SECRET_KEY=${STRIPE_LIVE_SECRET_KEY}
- STRIPE_LIVE_PUBLIC_KEY=${STRIPE_LIVE_PUBLIC_KEY}
- STRIPE_LIVE_MODE=${STRIPE_LIVE_MODE}
- DJSTRIPE_WEBHOOK_SECRET=${DJSTRIPE_WEBHOOK_SECRET}
- SERVER_EMAIL=${SERVER_EMAIL}
- ADMIN_EMAIL=${ADMIN_EMAIL}
volumes:
- static-data:/home/web/static:rw
- media-data:/home/web/media:rw
- reports-data:/home/web/reports
links:
- db:db
- smtp:smtp
restart: unless-stopped
user: root
logging:
Expand All @@ -62,7 +77,7 @@ services:
max-file: "10"

dbbackups:
image: kartoza/pg-backup:9.6
image: kartoza/pg-backup:16-3.4
hostname: pg-backups
volumes:
- db-backups:/backups
Expand All @@ -74,10 +89,10 @@ services:
- DUMPPREFIX=${DUMPPREFIX}
# These are all defaults anyway, but setting explicitly in
# case we ever want to ever use different credentials
- PGUSER=${DATABASE_USERNAME}
- PGPASSWORD=${DATABASE_PASSWORD}
- PGPORT=5432
- PGHOST=${DATABASE_HOST}
- POSTGRES_USER=${DATABASE_USERNAME}
- POSTGRES_PASS=${DATABASE_PASSWORD}
- POSTGRES_PORT=5432
- POSTGRES_HOST=${DATABASE_HOST}
- PGDATABASE=${DATABASE_NAME}
restart: unless-stopped

Expand All @@ -102,19 +117,10 @@ services:
# from prod environment if wanted
devweb:
<<: *uwsgi-common
build:
context: ${PWD}/../
dockerfile: dockerize/docker/Dockerfile
target: dev

btsync-db:
# BTSync backups for database dumps
image: kartoza/btsync
volumes:
# We mount RW so that we can use remove peer to clean up old backups off the server
- db-backups:/web:rw

btsync-media:
# BTSync backups for django media
image: kartoza/btsync
volumes:
# We mount RO as we do not really want peers to change this data
- media-data:/web:ro


9 changes: 5 additions & 4 deletions deployment/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#--------- Generic stuff all our Dockerfiles should start with so we get caching ------------
# Note this base image is based on debian
FROM python:3.10 as prod
FROM python:3.12-slim as prod
MAINTAINER Tim Sutton<[email protected]>

RUN export DEBIAN_FRONTEND=noninteractive
Expand All @@ -9,7 +9,7 @@ RUN dpkg-divert --local --rename --add /sbin/initctl

# Pandoc needed to generate rst dumps, uic compressor needed for django-pipeline
RUN apt-get update -y && \
apt-get -y install python3-gdal python3-geoip sudo curl rpl && \
apt-get -y install python3-gdal python3-geoip sudo curl rpl wget && \
apt-get -y --force-yes install yui-compressor gettext && \
apt-get -y --purge autoremove make libc-dev musl-dev g++ && \
apt-get install -y nodejs npm && \
Expand All @@ -18,14 +18,15 @@ RUN apt-get update -y && \
apt-get autoremove -y && \
rm -rf /var/lib/apt/lists/* /root/.npm /root/.cache && \
rm -rf ~/.cache/pip
RUN wget https://github.com/jgm/pandoc/releases/download/1.17.1/pandoc-1.17.1-2-amd64.deb
RUN dpkg -i pandoc-1.17.1-2-amd64.deb && rm pandoc-1.17.1-2-amd64.deb
RUN wget https://github.com/jgm/pandoc/releases/download/3.2/pandoc-3.2-1-amd64.deb
RUN dpkg -i pandoc-3.2-1-amd64.deb && rm pandoc-3.2-1-amd64.deb

# Added because of issue with building cryptography.io using pip
# This flag disabled rust build, but only for this particular version
# In the future, we may have to include rust toolchain in the Dockerfile
ENV CRYPTOGRAPHY_DONT_BUILD_RUST=1

RUN apt-get update -y && apt-get -y install git build-essential libpangocairo-1.0-0
ADD deployment/docker/REQUIREMENTS.txt /REQUIREMENTS.txt
ADD deployment/docker/uwsgi.conf /uwsgi.conf
ADD django_project /home/web/django_project
Expand Down
4 changes: 2 additions & 2 deletions deployment/docker/REQUIREMENTS-dev.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
django-nose
coverage
pep8>=1.5.7,<1.6
pep8
pylint
flake8==3.7.9
flake8
factory_boy

# documentation
Expand Down
91 changes: 46 additions & 45 deletions deployment/docker/REQUIREMENTS.txt
Original file line number Diff line number Diff line change
@@ -1,48 +1,49 @@
Django==3.2.13

psycopg2-binary==2.8.6
django-countries==7.3.2
django-crispy-forms==1.8.1
django-braces==1.15.0
django-model-utils==4.2.0
django-pipeline==2.0.8
git+https://github.com/dimasciput/django-pure-pagination.git
django-reversion==5.0.0
markdown==3.1.1

easy-thumbnails==2.8.1
django-widget-tweaks==1.3
raven==6.10.0
requests==2.27.1
django-hashedfilenamestorage==2.3
# pypandoc is an interface for pandoc converter
pypandoc==1.4
beautifulsoup4==4.11.1
# disqus
django-disqus==0.5
# custom slugify
awesome-slugify==1.6.5
#translation management tool
django-rosetta==0.9.8
awesome-slugify~=1.6
beautifulsoup4~=4.12
crispy-bootstrap3~=2024.1
Django~=4.2
git+https://github.com/Xpirix/dj-stripe.git@django4_update
django-allauth~=0.63
django-braces~=1.15
# disqus
django-disqus~=0.5
django-colorfield~=0.11
django-countries~=7.6
django-crispy-forms~=2.1
django-datatables-view~=1.20
# youtube embed
django-embed-video==1.4.3
django-grappelli==2.13.2
pytz==2020.5
django-allauth==0.50.0
# support special characters
Unidecode==0.4.20
Pillow==9.1.0
reportlab==3.6.9
xhtml2pdf==0.2.7
django-modeltranslation==0.16.1
django-colorfield==0.3.2
WeasyPrint==0.42.3
djangorestframework==3.11.2
django-simple-history==3.0.0
dj-stripe==2.1.1
django-preferences==1.0.0
pinax-notifications==6.0.0
pinax-templates==2.0.2
django-embed-video~=1.4
easy-thumbnails~=2.8
django-grappelli~=4.0
# Update for Django 4, the original package is broken
git+https://github.com/Xpirix/django-hashedfilenamestorage.git
django-modeltranslation~=0.18
django-model-utils~=4.5
django-pipeline~=3.1
django-preferences~=1.0
git+https://github.com/dimasciput/django-pure-pagination.git
django-reversion~=5.0
#translation management tool
django-rosetta~=0.10
django-simple-history~=3.5
# rich text editor
django-tinymce==3.4.0
django-datatables-view==1.19.1
django-tinymce~=4.0
django-widget-tweaks~=1.5
djangorestframework~=3.15
markdown~=3.6
Pillow~=10.3
# Update for Django 4, the original package is broken
git+https://github.com/Xpirix/pinax-notifications.git
pinax-templates~=3.0
# pypandoc is an interface for pandoc converter
pypandoc~=1.13
psycopg2-binary~=2.9
pytz~=2024.1
raven~=6.10
reportlab~=4.0
requests~=2.32
# support special characters
Unidecode~=0.4
WeasyPrint~=62.1
xhtml2pdf~=0.2
2 changes: 1 addition & 1 deletion deployment/sites-enabled/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ server {
}

# max upload size, adjust to taste
client_max_body_size 15M;
client_max_body_size 100M;
# Django media
location /media {
# your Django project's media files - amend as required
Expand Down
2 changes: 1 addition & 1 deletion django_project/base/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from django.contrib.flatpages.admin import FlatPageAdmin
from django.contrib.flatpages.models import FlatPage
from preferences.admin import PreferencesAdmin
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
import reversion
from .models import (
Project,
Expand Down
2 changes: 1 addition & 1 deletion django_project/base/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.contrib.auth.models import User
from django.contrib.flatpages.forms import FlatpageForm
from django.forms import inlineformset_factory
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from crispy_forms.helper import FormHelper
from crispy_forms.layout import (
Layout,
Expand Down
Loading