Skip to content

Commit c603c4f

Browse files
committed
Add nix dev shell and simplify dependency management
1 parent eeb7a40 commit c603c4f

15 files changed

+416
-367
lines changed

.flake8

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

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ polls.yaml
1111
.env
1212
poetry.lock
1313
*/__pycache__
14+
.devenv

.pre-commit-config.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ repos:
33
rev: 23.7.0
44
hooks:
55
- id: black
6-
args: [--line-length=88]
76
language_version: python3
87

98
- repo: https://github.com/astral-sh/ruff-pre-commit
109
rev: v0.0.280
1110
hooks:
1211
- id: ruff
13-
args: [--line-length=100, --ignore=E501]
12+
args: [--ignore=E501]
1413

1514
- repo: https://github.com/pycqa/isort
1615
rev: 5.12.0

.reuse/addheader

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
# SPDX-License-Identifier: MPL-2.0
55
# https://git.joinemm.dev/miso-bot
66

7-
reuse addheader --copyright="Joonas Rautiola <[email protected]>" --license="MPL-2.0" --template="header.jinja2" $@
7+
reuse annotate --copyright="Joonas Rautiola <[email protected]>" --license="MPL-2.0" --template="header.jinja2" "$@"

.reuse/dep5

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ Files: downloads/* images/* data/*
77
Copyright: 2023 Joonas Rautiola <[email protected]>
88
License: CC0-1.0
99

10-
Files: *.md .* requirements.* dev-requirements.*
10+
Files: *.md .* *.lock
1111
Copyright: 2023 Joonas Rautiola <[email protected]>
12-
License: MPL-2.0
12+
License: MPL-2.0

Dockerfile

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,39 @@
22
# SPDX-License-Identifier: MPL-2.0
33
# https://git.joinemm.dev/miso-bot
44

5-
FROM python:3.11
5+
# The builder image, used to build the virtual environment
6+
FROM python:3.11-buster as builder
7+
8+
RUN pip install poetry==1.4.2
9+
10+
ENV POETRY_NO_INTERACTION=1 \
11+
POETRY_VIRTUALENVS_IN_PROJECT=1 \
12+
POETRY_VIRTUALENVS_CREATE=1 \
13+
POETRY_CACHE_DIR=/tmp/poetry_cache
614

715
WORKDIR /app
816

17+
COPY pyproject.toml poetry.lock ./
18+
RUN touch README.md
19+
20+
RUN poetry install --without dev --no-root && rm -rf $POETRY_CACHE_DIR
21+
22+
# The runtime image, used to just run the code provided its virtual environment
23+
FROM python:3.11-slim-buster as runtime
24+
25+
RUN apt-get update -y
26+
RUN apt-get install --no-install-recommends -y ffmpeg wget
927
RUN wget --progress=dot:giga https://github.com/isis-project/isis-fonts/blob/master/NanumGothic.ttf?raw=true -O NanumGothic.ttf
10-
RUN apt-get update -y \
11-
&& apt-get install --no-install-recommends -y ffmpeg \
12-
&& apt-get clean \
13-
&& rm -rf /var/lib/apt/lists/*
14-
COPY requirements.txt ./
15-
RUN pip install --no-cache-dir -r requirements.txt
28+
29+
RUN apt-get clean \
30+
&& rm -rf /var/lib/apt/lists/*
31+
32+
ENV VIRTUAL_ENV=/app/.venv \
33+
PATH="/app/.venv/bin:$PATH" \
34+
PYTHONUNBUFFERED=1
35+
36+
COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV}
1637

1738
COPY . .
1839

19-
ENV PYTHONUNBUFFERED=1
2040
CMD ["python", "-O", "main.py"]

README.md

Lines changed: 55 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# Miso Bot
2-
31
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
42
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/84479f7c0f4c44a6aa2ba435e0215436)](https://app.codacy.com/manual/joinemm/miso-bot?utm_source=github.com&utm_medium=referral&utm_content=joinemm/miso-bot&utm_campaign=Badge_Grade_Dashboard)
53
[![DeepSource](https://deepsource.io/gh/joinemm/miso-bot.svg/?label=active+issues&show_trend=true&token=0E1BBh1I4k_HkqRvfRy86yMc)](https://deepsource.io/gh/joinemm/miso-bot/?ref=repository-badge)
@@ -8,78 +6,81 @@
86
[![Discord](https://img.shields.io/discord/652904322706833409.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://discord.gg/RzDW3Ne)
97
[![Patreon](https://img.shields.io/badge/Patreon-donate-orange.svg)](https://www.patreon.com/joinemm)
108
[![Sponsor](https://img.shields.io/github/sponsors/joinemm?color=%23db61a2)](https://github.com/sponsors/joinemm)
11-
129
[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/B0B824LWC)
1310

14-
1511
* * *
1612

17-
A discord bot with over 100 commands and features, including but not limited to:
18-
19-
- Fishing
20-
- LastFM Integration
21-
- Melon charts
22-
- Youtube search
23-
- Twitter media extractor
24-
- Instagram media extractor
25-
- TikTok media extractor
26-
- Moderation (ban, mute, timeout, etc)
27-
- Logs bans, leaves, joins, deleted messages
28-
- Server and user information
29-
- Customizable profiles
30-
- Minecraft server status
31-
- Starboard
32-
- DuckDuckGo bangs
33-
- Colors and color palettes
34-
- Create and search gifs
35-
- Horoscope
36-
- Weather
37-
- Keyword notifications
38-
- Rolepicker
39-
- Color roles
40-
- Typing tests and Typeracer
41-
- Papago Naver and google translator
42-
- Wolfram alpha
43-
- Reminders
44-
- Custom commands
45-
- Configurable prefix
46-
- Cryptocurrency data
47-
- Kpop idol database
48-
49-
...and much more. Visit <https://misobot.xyz> for more detailed overview of the features.
13+
# Miso Bot
5014

51-
## Star History
15+
Miso is a multipurpose Discord bot with over 100 commands and features.
5216

53-
[![Star History Chart](https://api.star-history.com/svg?repos=joinemm/miso-bot&type=Date)](https://star-history.com/#joinemm/miso-bot&Date)
17+
For more information and command reference, visit <https://misobot.xyz>
5418

55-
## Contributor wall
19+
## Development
5620

57-
[![Contributors](https://contrib.rocks/image?repo=joinemm/miso-bot)](https://github.com/joinemm/miso-bot/graphs/contributors)
21+
A Nix development shell is included, using [devenv](https://github.com/cachix/devenv)
5822

59-
## Deployment using docker
23+
This environment installs poetry and some useful packages.
6024

61-
First copy/rename `.env.example` to `.env` and fill it with your own keys.
62-
Everything else should be handled by the `docker-compose.yml`
25+
```sh
26+
nix develop --impure
27+
```
28+
29+
The dependencies are managed using [Poetry](https://python-poetry.org/)
30+
31+
```sh
32+
poetry install
33+
```
6334

64-
$ docker-compose up --build
35+
The bot can then be run with
6536

66-
## Deploying locally
37+
```sh
38+
poetry run python main.py
39+
```
6740

68-
The dependencies are compiled using pip-tools from `requirements.in` and `dev-requirements.in`. the dev file just adds linters and pre-commit.
41+
but it will not function without a MariaDB database.
42+
This makes using docker compose the easiest way to run the bot.
6943

70-
Installation using pip-tools:
44+
## Contributing
7145

72-
$ pip-sync requirements.txt dev-requirements.txt
46+
Your pull requests are welcome, as long as they meet the code standards enforced by the [pre-commit](https://pre-commit.com/) hooks.
7347

74-
Installation using pip:
48+
- [Black](https://github.com/psf/black) and [isort](https://pycqa.github.io/isort/) for formatting.
49+
- [Ruff](https://github.com/astral-sh/ruff), for linting.
50+
- [Reuse](https://reuse.software/), for licensing.
7551

76-
$ pip install -r requirements.txt -r dev-requirements.txt
52+
To install the hooks, run this command:
7753

78-
You need to have a mysql/mariadb database running, then run the migrations in `sql/init/...`. After this, you can run the bot:
54+
```sh
55+
pre-commit install
56+
```
7957

80-
$ python main.py
58+
Now your code should be automatically checked for issues when you commit.
8159

82-
> Note: Running this way, the HTML rendering will not work as it relies on an external docker container. You will have to run that separately.
60+
## Deployment
8361

62+
First copy/rename `.env.example` to `.env` and fill it with your own keys.
63+
Everything else should be handled by the dockerfile.
64+
65+
```sh
66+
docker-compose up
67+
```
68+
69+
The docker compose file bootstraps the entire miso infrastructure,
70+
including prometheus metrics, grafana dashboards and nginx reverse proxy.
71+
72+
You likely don't want these if you're just running the bot.
73+
74+
To run only the containers needed for the functionality of the bot, you can specify the service names:
75+
76+
```sh
77+
docker-compose up db image-server emojifier bot
78+
```
8479

80+
## Star History
81+
82+
[![Star History Chart](https://api.star-history.com/svg?repos=joinemm/miso-bot&type=Date)](https://star-history.com/#joinemm/miso-bot&Date)
8583

84+
## Contributor wall
85+
86+
[![Contributors](https://contrib.rocks/image?repo=joinemm/miso-bot)](https://github.com/joinemm/miso-bot/graphs/contributors)

dev-requirements.in

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

dev-requirements.txt

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

docker-compose.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ services:
8181
expose:
8282
- 3000
8383
volumes:
84-
# Static files
8584
- ./static:/app/static:ro
86-
# Handlebar template files
8785
- ./templates:/app/templates:ro
8886

8987
shlink:

0 commit comments

Comments
 (0)