Skip to content

Commit

Permalink
New host setup (#374)
Browse files Browse the repository at this point in the history
* Upgrade the stack from Django 2.2 to 3.2 (#233)

* Upgrade the stack from Django 2.2 to 3.2

* Upgrade pip as well when installing

Co-authored-by: Dimas Ciputra <[email protected]>

* Update docker compose (#256)

* Fix min_qg_version query in plugins.xml (#224)

* fix min_qg_version query

* added 0 patch value for qgis version against max_qg_version

* only add patch if it has major.minor version

* Update docker-compose and dockerfile

* Update nginx configuration

* Update smtp

* Add celery beat

* Add feedjack update celery task

* Add metabase configuration

* Update test.yaml

* Add test docker-compose

Co-authored-by: sumandari <[email protected]>

* Fix docker-compose and dockerfile

* Init starting docker dev environment

* Fixing docker container conflict, updating whoosh

* Update testfiles and feedback test

* Update dockerfile for dev and prod

* Use main branch for whoosh in requirements

* Django 4 update: Requirements, dockerfile and docker-compose

* Django 4 update: fixes for ifequal, ugettext_lazy, django.conf.urls.url occurences

* Django 4 update: Fix deprecated readfp

* Django 4 update: update dbrestore in Makefile

* Django 4 update: Get static, media and backup volumes from the environment variable

* Django 4 update: Use solr thumbnail default engine

* Django 4 update: Fix Django warnings

* Django 4 update: fix depecated tests, new migrations

* Django 4 update: Update django unit tests

* Django 4 update: Add email environment variables

* Django 4 update: Nginx and uwsgi updates

* Django 4 update: Refactoring dockerfile

* Update makefile to use new docker compose

* Django 4 update: Specify devweb container_name, fix typo

* Use existing nginx configuration

* Add DEFAULT_PLUGINS_SITE to environment variables

* Add nginx dev and prod configuration files

* Django 4 update: Generate a .env file in GH actions

* Django 4 update: Fix typo in Makefile

* Django 4 update: Use updated docker compose in test.yaml

* Django 4 update: Certbot service and SSL configuration

* Add a http configuration for Nginx

* Django 4 update: add SSL cert renewal script

* Redirect http to https

---------

Co-authored-by: Étienne Trimaille <[email protected]>
Co-authored-by: Dimas Ciputra <[email protected]>
Co-authored-by: sumandari <[email protected]>
  • Loading branch information
4 people authored May 6, 2024
1 parent 119269b commit b034b6b
Show file tree
Hide file tree
Showing 81 changed files with 1,033 additions and 301 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dockerize/postgres_data
8 changes: 4 additions & 4 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Run docker-compose build
run: docker-compose build
- name: Generate the .env file
run: cp .env.template .env


- name: Run the containers
run: docker-compose up -d db devweb


- name: Wait for the containers to start
run: sleep 15
Expand All @@ -65,4 +66,3 @@ jobs:
python manage.py migrate &&
python manage.py test
'
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ static_media
dockerize/static
dockerize/media
dockerize/logs
dockerize/certbot-etc
dockerize/webroot
.editorconfig

# test cache
Expand All @@ -51,3 +53,5 @@ qgis-app/api/tests/*/

# whoosh_index
qgis-app/whoosh_index/
docker-compose.override.yml
.env
2 changes: 2 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ $ make dbrestore

## Deploy Update with Rancher

**TO BE DEPRECATED**

- Go to [https://rancher.qgis.org](https://rancher.qgis.org)
- Click the home icon in the top left corner, and choose the environment: `plugins.qgis.org`
- You will be redirected to User Stacks page, choose the plugins stack by clicking on `plugins` link
Expand Down
18 changes: 12 additions & 6 deletions REQUIREMENTS.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
Django==2.2.25
Django==3.2.11

# Currently broken with 'no module named defaults' error
#Feedjack==0.9.18
# So use George's fork rather
# git+https://github.com/Erve1879/feedjack.git
# George's is also broken: use my fork (django 1.8 ready)
git+https://github.com/elpaso/feedjack.git
# George's is also broken: use elpaso fork (django 1.8 ready)
# git+https://github.com/elpaso/feedjack.git
# His is also broken, use dimasciput (django 3.2 ready)
git+https://github.com/dimasciput/feedjack.git

Markdown==2.3.1
#PIL==1.1.7
Pillow
Pygments==2.7.4

# Updates for Django 2 & Python 3.7
git+https://github.com/Xpirix/whoosh.git@a306553
git+https://github.com/Xpirix/whoosh.git@main
pickle5==0.0.12
django-haystack==3.2.1

Expand All @@ -21,16 +25,18 @@ argparse==1.2.1
django-annoying==0.7.7
django-auth-ldap==1.2.6
django-autoslug==1.7.1
django-debug-toolbar==1.11.1
django-debug-toolbar==3.2.4
django-endless-pagination==2.0
django-extensions==1.2.0
django-generic-aggregation==0.3.2
#django-olwidget==0.61.0 unmaintained, use this fork
git+https://github.com/Christophe31/olwidget.git
django-pagination==1.0.7

# Unmaintained!
#django-ratings==0.3.7
git+https://github.com/enikesha/django-ratings.git
git+https://github.com/gelo-zhukov/django-ratings.git

django-simple-ratings==0.3.2
# SIMPLEMENU
git+https://github.com/elpaso/django-simplemenu.git
Expand Down
31 changes: 31 additions & 0 deletions dockerize/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# RabbitMQ host
RABBITMQ_HOST=rabbitmq

# Database variables
DATABASE_NAME=gis
DATABASE_USERNAME=docker
DATABASE_PASSWORD=docker
DATABASE_HOST=db

# Django settings
DJANGO_SETTINGS_MODULE=settings_docker
DEBUG=False

# Docker volumes
QGISPLUGINS_STATIC_VOLUME=static-data
QGISPLUGINS_MEDIA_VOLUME=media-data
QGISPLUGINS_BACKUP_VOLUME=backups-data

# Email variables
EMAIL_BACKEND='django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST=''
EMAIL_PORT=587
EMAIL_USE_TLS=True
EMAIL_HOST_USER=''
EMAIL_HOST_PASSWORD=''

# URL
DEFAULT_PLUGINS_SITE='https://plugins.qgis.org/'

# ENV: debug or prod
QGISPLUGINS_ENV=debug
110 changes: 83 additions & 27 deletions dockerize/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,70 @@ build:
@echo "------------------------------------------------------------------"
@echo "Building in production and development mode"
@echo "------------------------------------------------------------------"
@docker-compose -p $(PROJECT_ID) build
@docker compose -p $(PROJECT_ID) build

build-dev:
@echo
@echo "------------------------------------------------------------------"
@echo "Building in development mode only"
@echo "------------------------------------------------------------------"
@docker compose -p $(PROJECT_ID) build devweb

db:
@echo
@echo "------------------------------------------------------------------"
@echo "Running db in production mode"
@echo "------------------------------------------------------------------"
@docker-compose -p $(PROJECT_ID) up -d db
@docker compose -p $(PROJECT_ID) up -d db

metabase: db
@echo
@echo "------------------------------------------------------------------"
@echo "Running metabase in production mode"
@echo "------------------------------------------------------------------"
@docker compose -p $(PROJECT_ID) up -d metabase

web: db
@echo
@echo "------------------------------------------------------------------"
@echo "Running in production mode"
@echo "------------------------------------------------------------------"
@docker-compose -p $(PROJECT_ID) up -d web
@docker compose -p $(PROJECT_ID) up -d uwsgi web worker beat

dbbackups: db
@echo
@echo "------------------------------------------------------------------"
@echo "Running dbbackups in production mode"
@echo "------------------------------------------------------------------"
@docker compose -p $(PROJECT_ID) up -d dbbackups

certbot: web
@echo
@echo "------------------------------------------------------------------"
@echo "Running cerbot in production mode"
@echo "------------------------------------------------------------------"
@docker compose -p $(PROJECT_ID) up -d certbot

devweb-test: db
@echo
@echo "------------------------------------------------------------------"
@echo "Running in TESTING mode"
@echo "------------------------------------------------------------------"
@docker compose up --no-deps -d devweb

devweb: db
@echo
@echo "------------------------------------------------------------------"
@echo "Running in DEVELOPMENT mode"
@echo "------------------------------------------------------------------"
@docker-compose -p $(PROJECT_ID) up --no-deps -d devweb
@docker compose -p $(PROJECT_ID) up --no-deps -d devweb rabbitmq worker beat

devweb-runserver: devweb
@echo
@echo "------------------------------------------------------------------"
@echo "Running in DEVELOPMENT mode"
@echo "------------------------------------------------------------------"
@docker-compose -p $(PROJECT_ID) exec devweb python manage.py runserver 0.0.0.0:8080
@docker compose -p $(PROJECT_ID) exec devweb python manage.py runserver 0.0.0.0:8080

migrate:
@echo
Expand All @@ -54,26 +89,26 @@ migrate:
@# We add the '-' prefix to the next line as the migration may fail
@# but we want to continue anyway.
@#We need to migrate accounts first as it has a reference to user model
-@docker-compose -p $(PROJECT_ID) exec web python manage.py migrate auth
@docker-compose -p $(PROJECT_ID) exec web python manage.py migrate
-@docker compose -p $(PROJECT_ID) exec uwsgi python manage.py migrate auth
@docker compose -p $(PROJECT_ID) exec uwsgi python manage.py migrate

update-migrations:
@echo
@echo "------------------------------------------------------------------"
@echo "Running update migrations in production mode"
@echo "------------------------------------------------------------------"
@docker-compose -p $(PROJECT_ID) exec web python manage.py makemigrations
@docker compose -p $(PROJECT_ID) exec uwsgi python manage.py makemigrations

collectstatic:
@echo
@echo "------------------------------------------------------------------"
@echo "Collecting static in production mode"
@echo "------------------------------------------------------------------"
#@docker-compose -p $(PROJECT_ID) run uwsgi python manage.py collectstatic --noinput
@docker compose -p $(PROJECT_ID) run uwsgi python manage.py collectstatic --noinput
#We need to run collect static in the same context as the running
# uwsgi container it seems so I use docker exec here
# no -it flag so we can run over remote shell
@docker exec $(PROJECT_ID)-web python manage.py collectstatic --noinput
# @docker exec $(PROJECT_ID)-web python manage.py collectstatic --noinput

reload:
@echo
Expand All @@ -89,7 +124,7 @@ kill:
@echo "------------------------------------------------------------------"
@echo "Killing in production mode"
@echo "------------------------------------------------------------------"
@docker-compose -p $(PROJECT_ID) kill
@docker compose -p $(PROJECT_ID) kill

rm: rm-only

Expand All @@ -98,38 +133,59 @@ rm-only: kill
@echo "------------------------------------------------------------------"
@echo "Removing production instance!!! "
@echo "------------------------------------------------------------------"
@docker-compose -p $(PROJECT_ID) rm
@docker compose -p $(PROJECT_ID) rm

maillogs:
@echo
@echo "------------------------------------------------------------------"
@echo "Showing smtp logs in production mode"
@echo "------------------------------------------------------------------"
@docker compose exec smtp tail -f /var/log/mail.log

mailerrorlogs:
@echo
@echo "------------------------------------------------------------------"
@echo "Showing smtp error logs in production mode"
@echo "------------------------------------------------------------------"
@docker compose exec smtp tail -f /var/log/mail.err

dbrestore:
@echo
@echo "------------------------------------------------------------------"
@echo "Restore dump from backups/latest.dmp in production mode"
@echo "------------------------------------------------------------------"
@# - prefix causes command to continue even if it fails
@echo "stopping web container"
@docker-compose -p $(PROJECT_ID) stop web
@echo "dropping gis"
@docker exec -t $(PROJECT_ID)-db su - postgres -c "dropdb gis"
@echo "creating gis"
@docker exec -t $(PROJECT_ID)-db su - postgres -c "createdb -O docker -T template_postgis gis"
@echo "restoring gis"
@# 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 exec -t $(PROJECT_ID)-db pg_restore /backups/latest.dmp | docker exec -i $(PROJECT_ID)-db su - postgres -c "psql gis"
@docker-compose -p $(PROJECT_ID) start web
@echo "starting web container"
@echo "stopping uwsgi container"
@docker compose -p $(PROJECT_ID) stop uwsgi
@echo "Dropping the gis and metabase databases"
-@docker compose -p $(PROJECT_ID) exec db su - postgres -c "dropdb --force gis"
-@docker compose -p $(PROJECT_ID) exec db su - postgres -c "dropdb --force metabase"
@echo "Creating the gis and metabase databases"
-@docker compose -p $(PROJECT_ID) exec db su - postgres -c "createdb -O docker -T template1 gis"
-@docker compose -p $(PROJECT_ID) exec db su - postgres -c "createdb -O docker -T template1 metabase"
@echo "Restore database from backups/latest-gis.dmp"
-@docker compose -p $(PROJECT_ID) exec db su - postgres -c "pg_restore -c /backups/latest-gis.dmp -d gis"
-@docker compose -p $(PROJECT_ID) exec db su - postgres -c "pg_restore -c /backups/latest-metabase.dmp -d metabase"
@echo "starting uwsgi container"
@docker compose -p $(PROJECT_ID) up -d uwsgi

wait-db:
@docker compose -p $(PROJECT_ID) exec db su - postgres -c "until pg_isready; do sleep 5; done"

create-test-db:
@docker compose -p $(PROJECT_ID) exec db su - postgres -c "psql -c 'create database test_db;'"
@docker compose -p $(PROJECT_ID) exec db su - postgres -c "psql -d test_db -c 'create extension postgis;'"

dbseed:
@echo
@echo "------------------------------------------------------------------"
@echo "Seed db with JSON data from /fixtures/*.json"
@echo "------------------------------------------------------------------"
@docker-compose -p $(PROJECT_ID) exec devweb bash -c 'python manage.py loaddata fixtures/*.json'
@docker compose -p $(PROJECT_ID) exec devweb bash -c 'python manage.py loaddata fixtures/*.json'

rebuild_index:
@echo
@echo "------------------------------------------------------------------"
@echo "Rebuild search index in PRODUCTION mode"
@echo "------------------------------------------------------------------"
@docker-compose -p $(PROJECT_ID) exec web bash -c 'python manage.py rebuild_index'
@docker compose -p $(PROJECT_ID) exec uwsgi bash -c 'python manage.py rebuild_index'
55 changes: 55 additions & 0 deletions dockerize/docker-compose.override.template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
version: '3'
services:
devweb:
# Note you cannot scale if you use container_name
image: kartoza/qgis-plugins-uwsgi:dev-latest
container_name: qgis-plugins-devweb
volumes:
- ../qgis-app:/home/web/django_project
- ./static:/home/web/static:rw
- ./media:/home/web/media:rw
build:
context: ${PWD}/../
dockerfile: dockerize/docker/Dockerfile
target: dev
ports:
# for django test server
- "62202:8080"
# for ssh
- "62203:22"

beat:
volumes:
- ../qgis-app:/home/web/django_project
- ./static:/home/web/static:rw
- ./media:/home/web/media:rw

worker:
volumes:
- ../qgis-app:/home/web/django_project
- ./static:/home/web/static:rw
- ./media:/home/web/media:rw

uwsgi:
container_name: qgis-plugins-uwsgi
volumes:
- ../qgis-app:/home/web/django_project
- ./static:/home/web/static:rw
- ./media:/home/web/media:rw
build:
context: ${PWD}/../
dockerfile: dockerize/docker/Dockerfile
target: prod

db:
volumes:
- ./postgres_data:/var/lib/postgresql
- ./backups:/backups

web:
volumes:
- ./sites-enabled:/etc/nginx/conf.d:ro
- ./static:/home/web/static:ro
- ./media:/home/web/media:ro
ports:
- "62201:8080"
19 changes: 19 additions & 0 deletions dockerize/docker-compose.override.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: '3'
services:
devweb:
# Note you cannot scale if you use container_name
image: kartoza/qgis-plugins-uwsgi:dev-latest
container_name: qgis-plugins-devweb
volumes:
- ../qgis-app:/home/web/django_project
- ./static:/home/web/static:rw
- ./media:/home/web/media:rw
build:
context: ${PWD}/../
dockerfile: dockerize/docker/Dockerfile
target: dev
ports:
# for django test server
- "62202:8080"
# for ssh
- "62203:22"
Loading

0 comments on commit b034b6b

Please sign in to comment.