diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..171dae1 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,68 @@ +version: "3.8" +services: + + postgres: + image: postgres:14.10-alpine3.19 + container_name: crack-db + command: + - "postgres" + - "-c" + - "max_connections=50" + - "-c" + - "shared_preload_libraries=pg_stat_statements" + - "-c" + - "pg_stat_statements.max=10000" + - "-c" + - "pg_stat_statements.track=all" + environment: + POSTGRES_DB: "crack" + POSTGRES_USER: "crack_user" + POSTGRES_PASSWORD: "crack_pass" + PGDATA: "/var/lib/postgresql/data/pgdata" + volumes: + - ./rearguarde/configuration/init_scripts:/docker-entrypoint-initdb.d + - local_crack_storage:/var/lib/postgresql/data + ports: + - "5432:5432" + healthcheck: + test: ["CMD-SHELL", "pg_isready -U crack_user -d crack"] + interval: 15s + timeout: 5s + retries: 5 + start_period: 10s + restart: on-failure:2 + deploy: + resources: + limits: + cpus: '1' + memory: 2G + networks: + - main + + pgadmin: + image: dpage/pgadmin4:8.1 + container_name: crack-admin-dash + environment: + PGADMIN_DEFAULT_EMAIL: "admin@example.com" + PGADMIN_DEFAULT_PASSWORD: "crack_admin_pass" + PGADMIN_CONFIG_SERVER_MODE: "False" + volumes: + - local_pgadmin_storage:/var/lib/pgadmin + ports: + - "5433:80" + restart: unless-stopped + deploy: + resources: + limits: + cpus: '0.5' + memory: 1G + networks: + - main + +volumes: + local_crack_storage: + local_pgadmin_storage: + +networks: + main: + driver: bridge diff --git a/docs/db-postgresql-setup.md b/docs/db-postgresql-setup.md index 428a6c1..6638cb6 100644 --- a/docs/db-postgresql-setup.md +++ b/docs/db-postgresql-setup.md @@ -11,9 +11,23 @@ For the time being, a dedicated DB-user will be established for connection to th Before running python code for the database creation, one needs to create user via `psql` or `pgAdmin4` utilities. Here, the command line approach will be enlightened (i.e. through `psql`). -## Linux notes +## Option 1: containerized -### User initiation +It is straighforward to spin up a database container along with pgAdmin dashboard in an isolated environment. +Simply execute + +```shell +docker-compose --project-name="taburette-db-layer" up -d +``` + +while CWD in the same directory as `docker-compose.yaml`. You'll have two services with necessary +ports exposed to the host. + +## Option 2: system-wide + +### Linux notes + +#### User initiation In Unix, PostgreSQL uses role-based authentication, which is enabled by default so instead of logging in as a superuser (`postgres` initially), administrator should create another role with @@ -46,7 +60,7 @@ It will create a user with an ability to create any databases inside the DBMS en it can, use the `\du` command to display a table with roles configured in PostgreSQL and their attributes. -### Authentication settings +#### Authentication settings For making possible to login as a newly created `crack_user`, you need to edit the `/etc/postgresql/10/main/pg_hba.conf` to specify the authentication method for the user. Add the @@ -62,7 +76,7 @@ For the changes to be applied one should consider restarting the `postgresql` da `sudo service postgresql restart`. Finally, by the `psql -U crack_user -W -d medium` a newly created user can connect to the intermediate database. -### Database origination +#### Database origination Now it is time to 'crack' database to be created by the `crack_user`. Execute @@ -73,7 +87,7 @@ CREATE DATABASE "crack" ENCODING 'UTF8'; You can assure database is created by entering `\l` command. Since this moment, you can access the database from python's code. -## Windows notes +### Windows notes You can face an issue with 866 and 1251 encoding pages discrepancies in the Windows `cmd` and `psql` if the default OS locale is not US English. To avoid such problem, before running the `psql` diff --git a/rearguarde/configuration/init_scripts/setup_extensions.sql b/rearguarde/configuration/init_scripts/setup_extensions.sql new file mode 100644 index 0000000..0919ce0 --- /dev/null +++ b/rearguarde/configuration/init_scripts/setup_extensions.sql @@ -0,0 +1 @@ +create extension if not exists pg_stat_statements;