diff --git a/INSTALL.md b/INSTALL.md index 3a2f7421..7cbcfe23 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -43,6 +43,8 @@ $ make rebuild_index ``` This command ensures that the search index accurately reflects the current state of the database, resolving the presence of 'None' in the search results. Automatic synchronization is currently managed in settings.py: `HAYSTACK_SIGNAL_PROCESSOR = "haystack.signals.RealtimeSignalProcessor"`. +For more information about make commands, please see the full docs [here](./dockerize/README.md). + --- ### Setup git-hooks and local linting diff --git a/dockerize/Makefile b/dockerize/Makefile index 43039c82..c58599c3 100644 --- a/dockerize/Makefile +++ b/dockerize/Makefile @@ -15,12 +15,6 @@ build: @echo "------------------------------------------------------------------" @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 @@ -57,27 +51,6 @@ certbot: web @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 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 - migrate: @echo @echo "------------------------------------------------------------------" @@ -105,26 +78,27 @@ collectstatic: @echo "Collecting static in production mode" @echo "------------------------------------------------------------------" @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 -reload: +start: @echo @echo "------------------------------------------------------------------" - @echo "Reload django project in production mode" + @echo "Starting a specific container(s) in production mode. Use web if you want to start all." @echo "------------------------------------------------------------------" - # no -it flag so we can run over remote shell - @docker exec $(PROJECT_ID)-web uwsgi --reload /tmp/django.pid + @docker compose -p $(PROJECT_ID) up -d $(c) +restart: + @echo + @echo "------------------------------------------------------------------" + @echo "Restarting all or a specific container(s) in production mode" + @echo "------------------------------------------------------------------" + @docker compose -p $(PROJECT_ID) restart $(c) kill: @echo @echo "------------------------------------------------------------------" - @echo "Killing in production mode" + @echo "Killing all or a specific container(s) in production mode" @echo "------------------------------------------------------------------" - @docker compose -p $(PROJECT_ID) kill + @docker compose -p $(PROJECT_ID) kill $(c) rm: rm-only @@ -135,20 +109,6 @@ rm-only: kill @echo "------------------------------------------------------------------" @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 "------------------------------------------------------------------" @@ -176,16 +136,111 @@ 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: +rebuild_index: @echo @echo "------------------------------------------------------------------" - @echo "Seed db with JSON data from /fixtures/*.json" + @echo "Rebuild search index in PRODUCTION mode" @echo "------------------------------------------------------------------" - @docker compose -p $(PROJECT_ID) exec devweb bash -c 'python manage.py loaddata fixtures/*.json' + @docker compose -p $(PROJECT_ID) exec uwsgi bash -c 'python manage.py rebuild_index' -rebuild_index: +uwsgi-shell: @echo @echo "------------------------------------------------------------------" - @echo "Rebuild search index in PRODUCTION mode" + @echo "Shelling into the uwsgi container(s)" @echo "------------------------------------------------------------------" - @docker compose -p $(PROJECT_ID) exec uwsgi bash -c 'python manage.py rebuild_index' + @docker compose -p $(PROJECT_ID) exec uwsgi bash + +uwsgi-reload: + @echo + @echo "------------------------------------------------------------------" + @echo "Reload django project in production mode" + @echo "------------------------------------------------------------------" + @docker compose -p $(PROJECT_ID) exec uwsgi bash -c 'uwsgi uwsgi --reload /tmp/django.pid' + +uwsgi-errors: + @echo + @echo "------------------------------------------------------------------" + @echo "Tailing errors in the uwsgi container(s)" + @echo "------------------------------------------------------------------" + @docker compose -p $(PROJECT_ID) exec uwsgi bash -c 'tail -f /var/log/uwsgi-errors.log' + +uwsgi-logs: + @echo + @echo "------------------------------------------------------------------" + @echo "Tailing access logs in uwsgi container(s)" + @echo "------------------------------------------------------------------" + @docker compose -p $(PROJECT_ID) exec uwsgi bash -c 'tail -f /var/log/uwsgi-requests.log' + +web-shell: + @echo + @echo "------------------------------------------------------------------" + @echo "Shelling into the NGINX/WEB container(s)" + @echo "------------------------------------------------------------------" + @docker compose -p $(PROJECT_ID) exec web bash + +web-logs: + @echo + @echo "------------------------------------------------------------------" + @echo "Tailing logs in NGINX/WEB container(s)" + @echo "------------------------------------------------------------------" + @docker compose -p $(PROJECT_ID) logs -f web + +logs: + @echo + @echo "------------------------------------------------------------------" + @echo "Tailing all logs or a specific container" + @echo "------------------------------------------------------------------" + @docker compose -p $(PROJECT_ID) logs -f $(c) + +shell: + @echo + @echo "------------------------------------------------------------------" + @echo "Shelling into a specific container" + @echo "------------------------------------------------------------------" + @docker compose -p $(PROJECT_ID) exec $(c) bash + +exec: + @echo + @echo "------------------------------------------------------------------" + @echo "Execute a specific docker command" + @echo "------------------------------------------------------------------" + @docker compose -p $(PROJECT_ID) $(c) + +# ---------------------------------------------------------------------------- +# D E V E L O P M E N T C O M M A N D S +# ---------------------------------------------------------------------------- + +build-dev: + @echo + @echo "------------------------------------------------------------------" + @echo "Building in development mode only" + @echo "------------------------------------------------------------------" + @docker compose -p $(PROJECT_ID) build devweb + +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 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 + +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' \ No newline at end of file diff --git a/dockerize/README.md b/dockerize/README.md new file mode 100644 index 00000000..aa59cea4 --- /dev/null +++ b/dockerize/README.md @@ -0,0 +1,181 @@ +# Docker compose commands Documentation + +## Overview +This doc is designed for managing a Docker-based project with the ID `qgis-plugins`. It includes various commands for building, running, and maintaining both production and development environments. Below is a detailed description of each command available in the Makefile. + +## Commands + +### Production Commands + +- **default**: Alias for the build command. +```sh +make +``` + +- **run**: Builds the project and runs the web, migrate, and collectstatic commands. +```sh +make run +``` + +- **build**: Builds Docker images for both production and development environments. +```sh +make build +``` + +- **db**: Starts the database container in production mode. +```sh +make db +``` + +- **metabase**: Starts the Metabase container after ensuring the database is running. +```sh +make metabase +``` + +- **web**: Starts the web container and scales the `uwsgi` service to 2 instances. +```sh +make web +``` + +- **dbbackups**: Starts the database backups container. +```sh +make dbbackups +``` + +- **certbot**: Starts the Certbot container for managing SSL certificates. +```sh +make certbot +``` + +- **migrate**: Runs database migrations, with the `auth` app being migrated first. +```sh +make migrate +``` + +- **update-migrations**: Creates new migration files based on changes in models. +```sh +make update-migrations +``` + +- **collectstatic**: Collects static files for the Django application. +```sh +make collectstatic +``` + +- **start**: Starts a specific container or all containers. Specify the container with the `c` variable. +```sh +make start c=container_name +``` + +- **restart**: Restarts a specific container or all containers. Specify the container with the `c` variable. +```sh +make restart c=container_name +``` + +- **kill**: Stops a specific container or all containers. Specify the container with the `c` variable. +```sh +make kill c=container_name +``` + +- **rm**: Removes all containers after stopping them. +```sh +make rm +``` + +- **rm-only:** Removes all containers without stopping them first. +```sh +make rm-only +``` + +- **dbrestore:** Restores the database from a backup file. +```sh +make dbrestore +``` + +- **wait-db:** Waits for the database to be ready. +```sh +make wait-db +``` + +- **create-test-db:** Creates a test database with PostGIS extension. +```sh +make create-test-db +``` + +- **rebuild_index:** Rebuilds the search index for the Django application. +```sh +make rebuild_index +``` + +- **uwsgi-shell:** Opens a shell in the `uwsgi` container. +```sh +make uwsgi-shell +``` + +- **uwsgi-reload:** Reloads the Django project in the `uwsgi` container. +```sh +make uwsgi-reload +``` + +- **uwsgi-errors:** Tails the error logs in the `uwsgi` container. +```sh +make uwsgi-errors +``` + +- **uwsgi-logs:** Tails the requests logs in the `uwsgi` container. +```sh +make uwsgi-logs +``` + +- **web-shell:** Opens a shell in the NGINX/web container. +```sh +make web-shell +``` + +- **web-logs:** Tails the logs in the NGINX/web container. +```sh +make web-logs +``` + +- **logs:** Tails logs for a specific container or all containers. Specify the container with the `c` variable. +```sh +make logs c=container_name +``` + +- **shell:** Opens a shell in a specific container. Specify the container with the `c` variable. +```sh +make shell c=container_name +``` + +- **exec:** Executes a specific Docker command. Specify the command with the `c` variable. +```sh +make exec c="command" +``` + +### Development Commands + +- **build-dev:** Builds Docker images for the development environment. +```sh +make build-dev +``` + +- **devweb-test:** Starts the `devweb` container for testing, ensuring the database is running. +```sh +make devweb-test +``` + +- **devweb:** Starts the `devweb` container for development, along with RabbitMQ, worker, and beat containers. +```sh +make devweb +``` + +- **devweb-runserver:** Runs the Django development server inside the `devweb` container. +```sh +make devweb-runserver +``` + +- **dbseed:** Seeds the database with initial data from JSON files in the `fixtures` directory. +```sh +make dbseed +``` + diff --git a/readme.md b/readme.md index ec2ea04c..56f730e2 100644 --- a/readme.md +++ b/readme.md @@ -33,7 +33,7 @@ docker and rancher. ## Token based authentication -Users have the ability to generate a Simple JWT token by providing their credentials, which can then be utilized to access endpoints requiring authentication. +Users can generate a Simple JWT token by providing their credentials, which can then be utilized to access endpoints requiring authentication. Users can create specific tokens for a plugin at `https://plugins.qgis.org//tokens/`.