Skip to content

Commit 1231f96

Browse files
committed
Add docker infrastructure
1 parent 777d336 commit 1231f96

6 files changed

Lines changed: 64 additions & 19 deletions

File tree

‎README.md‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -362,21 +362,30 @@ The bot requires:
362362
- PostgreSQL 12+
363363
- Libraries listed in `requirements.txt`
364364

365-
You will need to create a static config file called `bot.conf` in the working
366-
directory of the bot, see `bot.conf.example`.
365+
It is recommended to use Docker Compose to satisfy these dependencies. To setup the Docker containers run:
366+
```sh
367+
docker-compose build
368+
```
369+
Next you will need to create a static config file called `bot.conf` in the root directory, based on `bot.conf.example`.
367370

368-
Next you will need to do a little bit of initial configuration so that the bot can respond to your commands. From the directory containing `bot.conf` run the following (adjust `PYTHONPATH` so that the necessary module is in scope):
371+
Next you will need to do a little bit of initial configuration so that the bot can respond to your commands:
369372
```sh
370-
python -m util.setup
373+
docker-compose run bot python -m util.setup
371374
```
372375
This will prompt you for your Discord user ID, and the command prefix.
373376

374-
Now you can run the bot by executing `main.py`. You can continue the configuration over Discord, for example:
377+
Now you can run the bot with:
378+
```sh
379+
docker-compose up
380+
```
381+
382+
You can continue the configuration over Discord, for example:
375383
```
376384
.load discord_log
377385
.config syslog 268882890576756737
378386
.config autoload add discord_log 0
379387
```
388+
(replace `.` with the command prefix you chose).
380389

381390
If you'd like to use your own plugins from a different repository, say from
382391
`$DIR`, you can put it on the `PYTHONPATH`, and the bot will look for plugins in

‎bot.conf.example‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
# A config with values that are very unlikely to change during execution
22
[DB]
3-
# Database connection string
4-
# If you have PostgreSQL running locally, most likely you want just the dbname= parameter
5-
dsn = dbname=db host=localhost port=12345
6-
# Directory with migration files
3+
# Database connection string, should work with the provided docker image
4+
dsn = host=db user=bot password=bot dbname=discord
5+
# Directory with migration files, should work with the provided docker image
76
migrations = migrations/
87
[Log]
98
# Log directory

‎docker-compose.yml‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
version: '3'
2+
services:
3+
bot:
4+
build: docker
5+
volumes:
6+
- type: bind
7+
source: $PWD
8+
target: /opt/bot/
9+
depends_on:
10+
db:
11+
condition: service_healthy
12+
13+
db:
14+
image: postgres:12.20-alpine
15+
environment:
16+
POSTGRES_USER: bot
17+
POSTGRES_PASSWORD: bot
18+
POSTGRES_DB: discord
19+
volumes:
20+
- db:/var/lib/postgresql/data
21+
healthcheck:
22+
test: ["CMD-SHELL", "pg_isready -U bot -d discord"]
23+
start_interval: 1s
24+
start_period: 1m
25+
interval: 10m
26+
27+
volumes:
28+
db:

‎docker/Dockerfile‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM python:3.9-alpine
2+
RUN apk add --no-cache gcc g++ musl-dev git
3+
COPY requirements_core.txt /
4+
RUN pip install --use-pep517 --requirement /requirements_core.txt \
5+
&& rm requirements_core.txt
6+
7+
WORKDIR /opt/bot/
8+
CMD ["python", "main.py"]

‎docker/requirements_core.txt‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
aiohttp
2+
aiohttp-session
3+
asyncpg
4+
datrie
5+
pyright==1.1.378
6+
PyYAML
7+
sqlalchemy >= 2
8+
types-requests
9+
types-PyYAML
10+
typing_extensions

‎requirements_core.txt‎

Lines changed: 0 additions & 10 deletions
This file was deleted.

‎requirements_core.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
docker/requirements_core.txt

0 commit comments

Comments
 (0)