-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lot of things, don't make commits like that :) (#39)
* update pyproject.toml * add init to be more efficient * changed a lot of things, didn't test * updated too many things * Well, it's time to test * Ready for prod ?
- Loading branch information
Showing
38 changed files
with
1,639 additions
and
390 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Required | ||
BOT_TOKEN=... | ||
FB_USERNAME=... # username for the filebrowser interface | ||
FB_PASSWORD=... # hash of the password for the filebrowser interface (bcrypt) | ||
|
||
# Optional (read the guidelines for more informations) | ||
LOGGER_WEBHOOK=... | ||
CTS_TOKEN=... | ||
OPENWEATHERMAP_API_KEY=... | ||
OPENAI_API_KEY=... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
|
||
jobs: | ||
check: | ||
name: Execute test, check style, lint... | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 60 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Install uv | ||
uses: astral-sh/setup-uv@v2 | ||
with: | ||
version: 0.4.0 | ||
- name: "Set up Python" | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version-file: "pyproject.toml" | ||
- name: Install the project | ||
run: uv sync --all-extras --dev | ||
- name: Execute pyright | ||
run: | | ||
uv run pyright src/ | ||
- name: Execute ruff | ||
run: | | ||
uv run ruff format --check src/ | ||
uv run ruff check | ||
# - name: Install tox | ||
# run: | | ||
# python -m pip install -U pip | ||
# pip install tox | ||
# - name: Test application with tox | ||
# run: | | ||
# tox | ||
# - name: Upload test artifacts | ||
# uses: actions/upload-artifact@v3 | ||
# with: | ||
# name: pytest_results | ||
# path: junit/test-results.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
https://yourdomain.com { | ||
reverse_proxy http://filebrowser:8080 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,31 @@ | ||
FROM python:3.12-alpine as base | ||
RUN apk update && apk add poppler-utils && apk add build-base | ||
# syntax=docker/dockerfile-upstream:master-labs | ||
|
||
FROM python:3.12-alpine AS build | ||
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv | ||
WORKDIR /app | ||
ENV PYTHONUNBUFFERED=0 | ||
COPY ./requirements.txt /app | ||
RUN pip install -r requirements.txt | ||
RUN --mount=type=cache,target=/var/cache/apk \ | ||
--mount=type=cache,target=/root/.cache/uv \ | ||
--mount=type=bind,source=uv.lock,target=uv.lock \ | ||
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \ | ||
: \ | ||
&& apk update && apk add poppler-utils build-base \ | ||
&& uv sync --no-dev --locked \ | ||
&& : | ||
|
||
FROM base as prod | ||
FROM python:3.12.0-alpine AS base | ||
# https://docs.docker.com/reference/dockerfile/#copy---parents | ||
COPY --parents --from=build /app/.venv / | ||
WORKDIR /app | ||
COPY ./src ./ | ||
CMD ["python", "./main.py"] | ||
ENV PATH="/app/.venv/bin:$PATH" | ||
ENV PYTHONUNBUFFERED=0 | ||
|
||
FROM base AS production | ||
CMD ["python", "./main.py"] | ||
|
||
FROM base as debug | ||
FROM base AS debug | ||
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv | ||
ENV DEBUG=1 | ||
ENV LOG_LEVEL=DEBUG | ||
RUN pip install debugpy | ||
CMD ["python", "-m", "debugpy", "--wait-for-client", "--listen", "0.0.0.0:5678", "./main.py"] | ||
# CMD ["python", "./main.py"] | ||
RUN uv pip install debugpy | ||
CMD ["python", "-Xfrozen_modules=off", "-m", "debugpy", "--wait-for-client", "--listen", "0.0.0.0:5678", "./main.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
|
||
# Pass all arguments to docker compose with both compose.yml and compose.caddy.yml | ||
docker compose -f compose.yml -f compose.caddy.yml "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
services: | ||
caddy: | ||
image: caddy:latest | ||
restart: unless-stopped | ||
cap_add: | ||
- NET_ADMIN | ||
ports: | ||
- "80:80" | ||
- "443:443" | ||
- "443:443/udp" | ||
volumes: | ||
- $PWD/Caddyfile:/etc/caddy/Caddyfile | ||
- $PWD/data/caddy_data:/data | ||
- $PWD/caddy_config:/config |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
services: | ||
mp2i-bot: | ||
image: airopi/mp2i-bot:latest | ||
user: "1000:1000" | ||
build: | ||
context: . | ||
dockerfile: ./Dockerfile | ||
target: production | ||
env_file: | ||
- .env | ||
init: true | ||
tty: true | ||
restart: no | ||
volumes: | ||
- ./data:/app/data | ||
- ./resources:/app/resources | ||
- ./external_data:/app/external_data | ||
- ./config.toml:/app/config.toml | ||
|
||
filebrowser: | ||
image: hurlenko/filebrowser | ||
user: "1000:1000" | ||
volumes: | ||
- ./external_data:/data | ||
- ./filebrowser_config:/config | ||
env_file: | ||
- .env | ||
restart: always | ||
expose: | ||
- 8080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
guild_id = 1015136740127821885 | ||
birthday_channel_id = 1015172827650998352 | ||
|
||
loaded_extensions = [ | ||
"weather_icon", | ||
"cts", | ||
"restauration", | ||
"fun", | ||
"mp2i", | ||
"openai_chatbot", | ||
"colloscope_helper", | ||
"birthday", | ||
"admin", | ||
] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,107 @@ | ||
[tool.tox] # A better implementation is planned. But this avoid to have an additional `tox.ini` file. | ||
[project] | ||
name = "MP2IBot" | ||
version = "1.0" | ||
dependencies = [ | ||
"discord.py", | ||
"httpx", | ||
"beautifulsoup4", | ||
"typing_extensions", | ||
"tzdata", | ||
"Pillow", | ||
"openai", | ||
"fpdf2", | ||
"pdf2image", | ||
] | ||
requires-python = ">=3.12" | ||
|
||
[tool.uv] | ||
dev-dependencies = [ | ||
# "uv", | ||
"pyright", | ||
"debugpy", | ||
"ruff", | ||
"types-beautifulsoup4", | ||
"tox", | ||
"tox-uv", | ||
] | ||
|
||
[tool.tox] | ||
legacy_tox_ini = """ | ||
[tox] | ||
skipsdist = true | ||
envlist = py312 | ||
[testenv] | ||
deps = | ||
-r requirements.txt | ||
-r requirements-dev.txt | ||
runner = uv-venv-lock-runner | ||
description = run all checks on the code | ||
extras = | ||
dev | ||
commands = | ||
# pytest | ||
black --check src/ | ||
bandit -r src/ tests/ -c pyproject.toml | ||
isort ./src/ --check | ||
ruff format --check src | ||
ruff check src | ||
pyright src/ | ||
""" | ||
|
||
[tool.bandit.assert_used] | ||
skips = ["*/test_*.py", "*/test_*.py"] | ||
[tool.ruff] | ||
line-length = 120 | ||
indent-width = 4 | ||
target-version = "py312" | ||
src = ["src"] | ||
exclude = ["bin"] | ||
|
||
[tool.pytest.ini_options] | ||
pythonpath = ". src" | ||
[tool.ruff.lint] | ||
select = [ | ||
"E", # pycodestyle Error | ||
"F", # pyflakes | ||
"UP", # pyupgrade | ||
"SIM", # flake8-simplify | ||
"I", # imports | ||
"S", # bandit (security) | ||
"N", # pep8-naming | ||
"ASYNC", # flake8-async | ||
"C4", # flake8-compehensions | ||
"FA", # flake8-future-annotations | ||
"ISC", # flake8-implicit-str-concat | ||
"ICN", # flake8-import-conventions | ||
"G", # flake8-logging-format | ||
"PIE", # flake8-pie | ||
"PYI", # flake8-pyi | ||
"RSE", # flake8-raise | ||
"SLOT", # flake8-slots | ||
"INT", # flake8-gettext | ||
"TRY", # tryceratops | ||
"FLY", # flynt | ||
"PERF", # Perflint | ||
"FURB", # refurb | ||
"LOG", # flake8-logging | ||
"RUF", # Ruff-specific-rules | ||
# "ERA", # locate commented codes | ||
# "FIX", # locate TODOs and FIXME | ||
# "PTH", # flake8-use-pathlib (maybe todo ?) | ||
# "TID", # flake8-tidy-imports (maybe todo ?) | ||
# "SLF", # flake8-self (managed by pyright) | ||
# "RET", # flake8-return | ||
# "Q", # flake8-quotes | ||
# "T20", # flake8-print | ||
# "DTZ", # flake8-datetimez (TODO) | ||
# "B", # flake8-bugbear | ||
] | ||
|
||
[tool.black] | ||
line-length = 120 | ||
ignore = [ | ||
"E501", # line too long (we relate on the formater) | ||
"N818", # Error suffix for exceptions names | ||
# "PIE796", # Enum contains duplicate value | ||
"TRY003", # Avoid specifying long messages outsides the exception class | ||
"ISC001", # To avoid conflicts with the formatter | ||
] | ||
dummy-variable-rgx = '^\*{0,2}(_$|__$|unused_|dummy_)' | ||
|
||
[tool.ruff.format] | ||
quote-style = "double" | ||
indent-style = "space" | ||
skip-magic-trailing-comma = false | ||
|
||
[tool.isort] | ||
profile = "black" | ||
combine_as_imports = true | ||
combine_star = true | ||
line_length = 120 | ||
[tool.ruff.lint.isort] | ||
combine-as-imports = true | ||
|
||
[tool.pyright] | ||
reportImportCycles = false | ||
[tool.ruff.lint.pyflakes] | ||
extend-generics = ["discord.app_commands.CommandTree"] |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.