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

New host setup dev #7

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
f7a37c6
Upgrade the stack from Django 2.2 to 3.2 (#233)
Gustry Aug 21, 2022
d4c8550
Update docker compose (#256)
dimasciput Aug 21, 2022
4a2431a
Fix docker-compose and dockerfile
Xpirix Nov 22, 2023
ada9b42
Merge branch 'master' of github.com:Xpirix/QGIS-Django into update_dj…
Xpirix Nov 22, 2023
a8349fd
Init starting docker dev environment
Xpirix Nov 22, 2023
ee066d2
Fixing docker container conflict, updating whoosh
Xpirix Nov 23, 2023
303bad8
Update testfiles and feedback test
Xpirix Nov 23, 2023
8559721
Update dockerfile for dev and prod
Xpirix Nov 23, 2023
8c46fed
Merge branch 'master' into update_django
Xpirix Feb 12, 2024
04c5ffe
Use main branch for whoosh in requirements
Xpirix Feb 13, 2024
a947f26
Merge branch 'master' of github.com:Xpirix/QGIS-Django into new_host_…
Xpirix Mar 20, 2024
16434e4
Django 4 update: Requirements, dockerfile and docker-compose
Xpirix Mar 21, 2024
c93fac6
Django 4 update: fixes for ifequal, ugettext_lazy, django.conf.urls.u…
Xpirix Mar 21, 2024
6e50f73
Django 4 update: Fix deprecated readfp
Xpirix Mar 21, 2024
63cfd3e
Django 4 update: update dbrestore in Makefile
Xpirix Mar 21, 2024
9d250fc
Django 4 update: Get static, media and backup volumes from the enviro…
Xpirix Mar 21, 2024
9dfbd35
Django 4 update: Use solr thumbnail default engine
Xpirix Mar 21, 2024
bd64930
Django 4 update: Fix Django warnings
Xpirix Mar 21, 2024
56f0ca8
Django 4 update: fix depecated tests, new migrations
Xpirix Mar 22, 2024
f0119d5
Django 4 update: Update django unit tests
Xpirix Mar 22, 2024
ecf9d40
Django 4 update: Add email environment variables
Xpirix Mar 22, 2024
e488644
Django 4 update: Nginx and uwsgi updates
Xpirix Mar 22, 2024
26de6e1
Django 4 update: Refactoring dockerfile
Xpirix Mar 22, 2024
1921119
Update makefile to use new docker compose
Xpirix Mar 27, 2024
c112431
Django 4 update: Specify devweb container_name, fix typo
Xpirix Mar 27, 2024
4466e94
Use existing nginx configuration
Xpirix Mar 27, 2024
d5483dd
Add DEFAULT_PLUGINS_SITE to environment variables
Xpirix Mar 28, 2024
ce76edc
Add nginx dev and prod configuration files
Xpirix Apr 2, 2024
9abe60f
Django 4 update: Generate a .env file in GH actions
Xpirix Apr 2, 2024
d6a7b2b
Django 4 update: Fix typo in Makefile
Xpirix Apr 2, 2024
fe4dd07
Django 4 update: Use updated docker compose in test.yaml
Xpirix Apr 2, 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
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dockerize/postgres_data
20 changes: 14 additions & 6 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,23 @@ jobs:
steps:
- uses: actions/checkout@v2

- 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: Run docker compose build
run: docker compose build devweb

- name: Run docker compose services
working-directory: dockerize
run: |
cp docker-compose.override.test.yml docker-compose.override.yml
make devweb-test
make wait-db
make create-test-db

- name: Run Coverage test
run: |
cat << EOF | docker-compose exec -T devweb bash
cat << EOF | docker compose exec -T devweb bash
pip install coverage
python manage.py makemigrations
python manage.py migrate
Expand All @@ -64,7 +72,7 @@ jobs:
EOF

- name: Upload coverage to codecov
uses: codecov/codecov-action@v2
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,5 @@ qgis-app/api/tests/*/

# whoosh_index
qgis-app/whoosh_index/
docker-compose.override.yml
.env
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
28 changes: 28 additions & 0 deletions dockerize/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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/'
103 changes: 76 additions & 27 deletions dockerize/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,63 @@ 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

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 +82,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 +117,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 +126,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
Loading