Skip to content

Docker container for Komodo Notary stats API using Django / PGSQL

Notifications You must be signed in to change notification settings

smk762/kmd_ntx_stats_docker

Repository files navigation

Dependancies:

Clone repo

git clone https://github.com/smk762/kmd_ntx_stats_docker

cd kmd_ntx_stats_docker

Install Python Packages: pip3 install -r requirements.txt

sudo docker compose build (needs to be run to apply code changes)

sudo docker compose up (run to launch containers)

Setup .env files (scripts pending...)

  • pgsql credentials

  • django secret key

  • allowed hosts

Create Database Tables

Make migrations: "docker compose run web python3 manage.py makemigrations"

Apply migrations: "docker compose run web python3 manage.py migrate"

Collect static files: "docker compose run web python3 manage.py collectstatic"

Create superuser:

docker compose run web python3 manage.py createsuperuser --email [email protected] --username messiah

See https://docs.djangoproject.com/en/3.0/ref/django-admin/ for more django admin commands.

Applying code changes

cd ~/kmd_ntx_stats_docker

docker compose build

sudo chown $USER:$USER /home/$USER/kmd_ntx_stats_docker/postgres-data -R

docker compose build

sudo cp -R static /var/www/stats.kmd.io/html

Adding new coins

add coin parmas to scripts/base_58.py

run scripts/populate_coins_table.py

run scripts/populate_balances_table.py

run scripts/populate_addresses_table.py

Check web pages to confirm display / no errors.

Reference

  • to make migrations, use docker compose run web python3 manage.py makemigrations
  • to apply migrations, use docker compose run web python3 manage.py migrate
  • to update static files, use docker compose run web python3 manage.py collectstatic

Editing pg.conf

  • docker exec -it <pgsql_container_name> bash
  • apt update & apt install nano
  • nano ./var/lib/postgresql/data/postgresql.conf
  • change max_connections to 1000
  • change max_wal_size to 2gb
  • log_rotation_size to 100mb

Find where colectstatic is looking

  • docker compose run web python3 manage.py findstatic --verbosity 2 static

PGSQL access config

  • sudo nano /home/$USER/kmd_ntx_stats_docker/postgres-data/pg_hba.conf

Fix permissions

  • sudo chown $USER:$USER /home/$USER/kmd_ntx_stats_docker/postgres-data -R

Prune old docker images (do while container is running so active containers are not removed)

  • docker system prune -a --volumes

Database Backup & Migration

Use the helper scripts in util/ to safely move the Postgres data directory between servers without copying raw volumes.

Exporting from the source server

  1. Ensure the stack is up with docker compose up -d db.
  2. Run ./util/export_postgres.sh /absolute/path/to/postgres.sql.gz (the path is optional; a timestamped file is written to backups/ by default).
  3. Copy the resulting .sql.gz file to secure storage or directly to the destination host.

Importing on the destination server

  1. Clone this repository, create the .env files, and bring the database online: docker compose up -d db.
  2. Transfer the dump file to the new host.
  3. Run ./util/import_postgres.sh /absolute/path/to/postgres.sql.gz. The script drops and recreates the public schema before streaming the dump into Postgres.
  4. Start or restart the rest of the stack (docker compose up -d) and follow the standard Django migration/static collection steps if needed.

This workflow keeps the migration deterministic, avoids mismatched Postgres minor versions, and allows you to archive backups under backups/ (ignored by git).

Production Deployment

See docs/production-deployment.md for a step-by-step server hardening and deployment checklist, including SSL termination, monitoring, and backup rotation guidance.

About

Docker container for Komodo Notary stats API using Django / PGSQL

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •