Skip to content

Commit 138b3c3

Browse files
committed
Database password from env, refactor docker-compose
1 parent 5f2f8e9 commit 138b3c3

File tree

5 files changed

+35
-20
lines changed

5 files changed

+35
-20
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,13 @@ Use `docker-compose.yml` included in this repo if you prefer to run dipdup in Do
158158

159159
```shell
160160
$ docker-compose build
161+
$ cp secrets.env.example secrets.env
162+
$ # edit `secrets.env` file, change credentials
161163
$ docker-compose up dipdup
162164
```
163165

166+
Note that can use `DIPDUP_DATABASE_PASSWORD` environment variable to avoid storing database password in `dipdup.yml`.
167+
164168
### Atomicity and persistency
165169

166170
Here's a few important things to keep in mind while running your indexer:

docker-compose.yml

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
version: "3.8"
2+
3+
x-dipdup: &x-dipdup
4+
build: .
5+
depends_on:
6+
- db
7+
volumes:
8+
- ./src/dipdup_hic_et_nunc/dipdup-docker.yml:/home/dipdup/dipdup.yml
9+
env_file: secrets.env
10+
211
services:
312
dipdup:
4-
build: .
13+
<<: *x-dipdup
14+
restart: always
515
command: ["-c", "dipdup.yml", "run"]
6-
depends_on:
7-
- db
8-
volumes:
9-
- ./src/dipdup_hic_et_nunc/dipdup-docker.yml:/home/dipdup/dipdup.yml
1016

1117
db:
1218
image: postgres
1319
restart: always
14-
environment:
15-
POSTGRES_USER: dipdup
16-
POSTGRES_DB: dipdup
17-
POSTGRES_PASSWORD: changeme
1820
volumes:
1921
- db:/var/lib/postgres/data
22+
env_file: secrets.env
2023

2124
graphql-engine:
2225
image: hasura/graphql-engine:v1.3.3
@@ -25,14 +28,7 @@ services:
2528
depends_on:
2629
- db
2730
restart: always
28-
environment:
29-
HASURA_GRAPHQL_DATABASE_URL: postgres://dipdup:changeme@db:5432/dipdup
30-
## enable the console served by server
31-
HASURA_GRAPHQL_ENABLE_CONSOLE: "true" # set to "false" to disable console
32-
## enable debugging mode. It is recommended to disable this in production
33-
HASURA_GRAPHQL_DEV_MODE: "true"
34-
HASURA_GRAPHQL_ENABLED_LOG_TYPES: startup, http-log, webhook-log, websocket-log, query-log
35-
## uncomment next line to set an admin secret
36-
# HASURA_GRAPHQL_ADMIN_SECRET: myadminsecretkey
31+
env_file: secrets.env
32+
3733
volumes:
3834
db:

secrets.env.example

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
DIPDUP_DATABASE_PASSWORD=changeme
2+
3+
POSTGRES_USER=dipdup
4+
POSTGRES_DB=dipdup
5+
POSTGRES_PASSWORD=changeme
6+
7+
HASURA_GRAPHQL_DATABASE_URL=postgres://dipdup:changeme@db:5432/dipdup
8+
HASURA_GRAPHQL_ENABLE_CONSOLE=true
9+
HASURA_GRAPHQL_DEV_MODE=true
10+
HASURA_GRAPHQL_ENABLED_LOG_TYPES=startup, http-log, webhook-log, websocket-log, query-log
11+
HASURA_GRAPHQL_ADMIN_SECRET=changeme

src/dipdup/config.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from cattrs_extras.converter import Converter
1212
from ruamel.yaml import YAML
1313
from tortoise import Model, Tortoise
14-
14+
from os import environ as env
1515
from dipdup.models import IndexType, State
1616

1717
ROLLBACK_HANDLER = 'on_rollback'
@@ -53,11 +53,16 @@ class DatabaseConfig:
5353
password: str = ''
5454
database: str
5555

56+
def __attrs_post_init__(self):
57+
if not self.password:
58+
self.password = env.get('DIPDUP_DATABASE_PASSWORD', '')
59+
5660
@property
5761
def connection_string(self):
5862
return f'{self.driver}://{self.user}:{self.password}@{self.host}:{self.port}/{self.database}'
5963

6064

65+
6166
@dataclass(kw_only=True)
6267
class TzktDatasourceConfig:
6368
"""TzKT datasource config

src/dipdup_hic_et_nunc/dipdup-docker.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ database:
77
port: 5432
88
user: dipdup
99
database: dipdup
10-
password: changeme
1110

1211
contracts:
1312
HEN_objkts:

0 commit comments

Comments
 (0)