Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Byte-compiled / cache
__pycache__/
*.py[cod]

# Virtual environments
.venv/
env/
venv/

# Editors & IDEs
.vscode/
.idea/
*.swp

# Git
.git/
.gitignore
.gitattributes
.gitkeep

# Python tooling
*.egg-info/
.eggs/
pip-wheel-metadata/
.pytest_cache/
.ruff_cache/
.python-version
tests/

# Logs and temp files
logs/
temp/
*.log
*.bak
*.tmp

# Environment files
.env*

# Docker Compose files (not needed in container)
docker_compose/

# Static/media files (unless needed)
static/
assets/
var/
*.png
*.jpeg
*.jpg
*.webp

# Exclude other files
docs/
.github/
.DS_Store
*.md
LICENSE
.pre-commit-config.yaml
requirements-dev.txt
22 changes: 22 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
root = true

[**]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
max_line_length = 99

[**.{yml,yaml,json,conf}]
indent_size = 2

[**.{md,txt,rst}]
trim_trailing_whitespace = false

[**.rst]
indent_size = 2

[Makefile]
indent_style = tab
46 changes: 46 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Fill in the actual secrets before using the app!
# Note: This is a template file. Create a copy as ".env" and fill in the actual values.
# Never commit your actual ".env" file to version control!

# ========================
# Bot Configuration
# ========================
BOT_TOKEN=your_bot_token_here
BOT_ADMIN_ACCESS_IDs=[12345]
BOT_SUPPORT_USERNAME=support_user
BOT_USERNAME=bot_name


# ========================
# Database Configuration
# ========================
POSTGRES_NAME=postgres
POSTGRES_USER=postgres
POSTGRES_PASSWORD=your_secure_password
POSTGRES_PORT=5432
POSTGRES_HOST=0.0.0.0
DATABASE_DRIVER=postgresql+asyncpg


# ========================
# Redis Configuration
# ========================
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_DB=0
REDIS_PASSWORD=
REDIS_TTL=3600


# ========================
# Logging Configuration
# ========================
LOG_LEVEL=DEBUG
LOG_FILE_ENABLED=true
LOG_BACKUP_COUNT=15


# ========================
# Environment Mode
# ========================
IMAGE_TAG=latest
65 changes: 65 additions & 0 deletions .github/workflows/docker-publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Publish Docker Image
# Builds and pushes a multi-platform Docker image to ghcr.io on push to main, tags (v*.*.*), or PR to main.
# Includes artifact attestation for supply chain security.
name: Publish Docker Image

on:
push:
tags: [ 'v*.*.*' ]

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-publish-image:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write
attestations: write
id-token: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0

- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}}
type=sha
type=raw,value=latest

- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1 # v6.16.0
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Generate artifact attestation
uses: actions/attest-build-provenance@v2
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.build-and-push.outputs.digest }}
push-to-registry: true
21 changes: 21 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Runs linting for Python code on every push to any branch.
name: Lint

on: [push]

jobs:
lint:
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
matrix:
python-version: [ "3.12.5" ]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Run pre-commit
uses: pre-commit/action@v3.0.1
10 changes: 8 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ cover/
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
Expand Down Expand Up @@ -165,10 +164,17 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.idea/

# Ruff stuff:
.ruff_cache/

# PyPI configuration file
.pypirc

# Exclude log files
logs/
*.log

# MacOS
.DS_Store
21 changes: 21 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-toml
- id: check-case-conflict
- id: detect-private-key
- id: check-added-large-files
args: [--maxkb=500]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.11.9
hooks:
- id: ruff
args:
- --fix
- id: ruff-format
types: [python]
58 changes: 58 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# -----------------------------
# Stage 1: Build dependencies
# -----------------------------
FROM python:3.12.5-slim AS builder

WORKDIR /app
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
POETRY_VERSION=2.1.3

# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
libpq-dev \
curl \
&& rm -rf /var/lib/apt/lists/*

# Install Poetry via official installer
RUN curl -sSL https://install.python-poetry.org | POETRY_HOME=/opt/poetry python3 - --version ${POETRY_VERSION}

ENV PATH="/opt/poetry/bin:${PATH}"

# Copy only dependency files
COPY pyproject.toml poetry.lock /app/

# Install production dependencies
RUN poetry config virtualenvs.create false \
&& poetry install --only main --no-interaction --no-ansi --no-root

# -----------------------------
# Stage 2: Final image
# -----------------------------
FROM python:3.12.5-slim
WORKDIR /app

ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1

# Install runtime dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
libpq5 \
postgresql-client \
redis-tools \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Copy installed dependencies from builder
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin

# Copy application code
COPY . /app

# Make entrypoint executable
RUN chmod +x /app/entrypoint.sh

# Entrypoint
ENTRYPOINT ["./entrypoint.sh"]
Loading