Skip to content

Commit acd0004

Browse files
committed
Updated README, env_dist, pg_init_user.sh and docker example
1 parent a3ce21c commit acd0004

File tree

4 files changed

+65
-40
lines changed

4 files changed

+65
-40
lines changed

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ with bombs on them. If you open a cell with a bomb, the game is over.
1010
![screenshot](screenshot.png)
1111

1212
## Used technology
13-
* Python (tested with 3.9, should work on 3.7+);
14-
* aiogram (Telegram Bot framework);
13+
* Python 3.9;
14+
* aiogram 3.x (Telegram Bot framework);
1515
* Docker and Docker Compose (containerization);
1616
* PostgreSQL (database);
1717
* Redis (persistent storage for some ongoing game data);
@@ -21,16 +21,18 @@ with bombs on them. If you open a cell with a bomb, the game is over.
2121

2222
## Installation
2323

24-
Create a directory of your choice. Inside it, make 3 directories for bot's data:
25-
`mkdir -p {pg-data,redis-data,redis-config}`
24+
Create a directory of your choice, let's say `/opt/bombsweeper`. Inside it, make 3 directories for bot's data:
25+
`mkdir -p {pg/init,pg/data,redis/config,redis/data}`
2626

27-
Grab `docker-compose-example.yml`, rename it to `docker-compose.yml` and put it next to your
28-
directories.
27+
Grab `docker-compose-example.yml`, rename it to `docker-compose.yml` and put it to `/opt/bombsweeper`.
2928

30-
Grab `redis.example.conf` file, rename it to `redis.conf` and put into `redis-config` directory.
29+
Grab `redis.example.conf` file, rename it to `redis.conf` and put into `redis/config` directory.
3130
Change its values for your preference.
3231

32+
Grab `pg_init_user.sh`, put it into `pg/init` and make executable (add "x" flag). Open it, replace
33+
`myuser` and `mydb` values with your own. Save file.
34+
3335
Grab `env_dist` file, rename it to `.env` and put it next to your `docker-compose.yml`, open
34-
and fill the necessary data.
36+
and fill the necessary data. Pay attention to POSTGRES_DSN value, sync it with `pg_init_user` values.
3537

3638
Finally, start your bot with `docker-compose up -d` command.

docker-compose-example.yml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,32 @@
11
version: '3.8'
22
services:
3+
# You can remove redis section and all its mentions if using "memory" storage
34
redis:
4-
image: redis:6.0-alpine
5+
image: redis:6-alpine
56
restart: "unless-stopped"
6-
environment:
7-
- REDIS_HOST
87
volumes:
98
# don't forget to put redis.conf to redis_config directory!
10-
- "/path/to/bombsweeper/redis_config:/usr/local/etc/redis"
11-
- "/path/to/bombsweeper/redis_data:/data"
9+
- "/opt/bombsweeper/redis/config:/usr/local/etc/redis"
10+
- "/opt/bombsweeper/redis/data:/data"
1211
command: "redis-server /usr/local/etc/redis/redis.conf"
1312
db:
1413
image: postgres:13-alpine
1514
restart: "unless-stopped"
1615
environment:
17-
POSTGRES_USER: ${DB_USER}
18-
POSTGRES_PASSWORD: ${DB_PASS}
19-
POSTGRES_DB: ${DB_NAME}
16+
POSTGRES_PASSWORD: ${SUPERUSER_PASSWORD}
2017
volumes:
21-
- "/path/to/bombsweeper/postgres_data:/var/lib/postgresql/data"
18+
- "/opt/bombsweeper/pg/data:/var/lib/postgresql/data"
19+
- "/opt/bombsweeper/pg/init:/docker-entrypoint-initdb.d"
2220
db_migration:
23-
image: "groosha/telegram-bombsweeper-bot:${IMAGE}"
21+
# You can override this tag using docker-compose.override.yml
22+
image: "groosha/telegram-bombsweeper-bot:latest"
2423
restart: "on-failure"
2524
depends_on:
26-
- db
25+
- db
2726
env_file: .env
2827
command: sh -c "python -m alembic upgrade head"
2928
bot:
30-
image: "groosha/telegram-bombsweeper-bot:${IMAGE}"
29+
image: "groosha/telegram-bombsweeper-bot:latest"
3130
stop_signal: SIGINT
3231
restart: "unless-stopped"
3332
env_file: .env

env_dist

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,39 @@
1-
# telegram
1+
# Bot settings
2+
## Token (required). Get it from @BotFather
23
BOT_TOKEN=1234567890:abcdefghijklmnopqrstuvwxyz
3-
# database
4-
DB_HOST=db
5-
DB_PORT=5432
6-
DB_NAME=yourdb
7-
DB_USER=user
8-
DB_PASS=s3cr3t
9-
# redis (FSM)
10-
REDIS_HOST=redis
11-
# docker image
12-
IMAGE=latest
13-
# webhooks
14-
WEBHOOK_ENABLED=1
15-
WEBHOOK_DOMAIN=bombsweeper.example.com
16-
WEBHOOK_PATH=/extra/path/from/root
17-
APP_HOST=0.0.0.0
18-
APP_PORT=9000
4+
## FSM Storage for game data. Values allowed: memory, redis
5+
BOT_FSM_STORAGE=redis
6+
7+
# Storages
8+
## Redis connection string. Required if BOT_FSM_STORAGE=redis
9+
REDIS_DSN=redis://localhost:6379/0
10+
## PostgreSQL connection string. Always required
11+
POSTGRES_DSN=postgresql+asyncpg://USER:PASSWORD@HOST:PORT/DBNAME
12+
13+
# Database settings
14+
## Password for superuser in PostgreSQL.
15+
## If upgrading from existing versions, this is PASSWORD from POSTGRES_DSN above
16+
## If creating a new instance, set it to some strong random password
17+
SUPERUSER_PASSWORD=1234567890
18+
19+
## Name of superuser in PostgreSQL
20+
## If upgrading from existing versions, this is USER from POSTGRES_DSN above
21+
## If creating a new instance, either skip it or set it to both here and docker-compose.yml
22+
## SUPERUSER_USER=admin
23+
24+
# Webhooks (optional)
25+
# You can skip this section if you want to use polling
26+
## Domain part of your webhook.
27+
# WEBHOOK_DOMAIN=http://localhost:9000
28+
## Actual path for your webhook on your domain
29+
# WEBHOOK_PATH=/bombsweeper/s89ytjr5dh
30+
31+
# App settings (optional)
32+
# You can skip this section if you want to use polling
33+
# or if default settings are sufficient.
34+
# APP_HOST=0.0.0.0
35+
# APP_PORT=9000
36+
37+
# Using local Bot API server (Optional)
38+
# You can skip this section if you want to use primary Bot API server
39+
# CUSTOM_BOT_API=http://localhost:8081

pg_init_user.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
set -e
44

5+
# Replace myuser and mydb with your own values
6+
# Don't forget to change them in .env file too!
7+
58
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
6-
CREATE USER user;
7-
CREATE DATABASE sweeperdb;
8-
GRANT ALL PRIVILEGES ON DATABASE sweeperdb TO user;
9+
CREATE USER myuser;
10+
CREATE DATABASE mydb;
11+
GRANT ALL PRIVILEGES ON DATABASE mydb TO myuser;
912
EOSQL

0 commit comments

Comments
 (0)