From 104cf719696f3b09d2124dc427d5a3aac995a147 Mon Sep 17 00:00:00 2001 From: hexdev Date: Thu, 13 Aug 2026 11:10:33 +0700 Subject: [PATCH] feat: +Dockerfile --- Dockerfile | 42 +++++++++++++++++++++++++++++++++ docker-compose.yml | 59 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..87f919a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,42 @@ +FROM python:3.14-slim AS builder + +ENV PYTHONDONTWRITEBYTECODE=1 \ + PYTHONUNBUFFERED=1 \ + PIP_DISABLE_PIP_VERSION_CHECK=1 + +WORKDIR /app + +RUN apt-get update \ + && apt-get install --yes --no-install-recommends build-essential gcc \ + && rm -rf /var/lib/apt/lists/* + +COPY requirements.txt ./ + +RUN pip install --upgrade pip \ + && pip wheel --wheel-dir /wheels -r requirements.txt + + +FROM python:3.14-slim AS runtime + +ENV PYTHONDONTWRITEBYTECODE=1 \ + PYTHONUNBUFFERED=1 \ + PIP_DISABLE_PIP_VERSION_CHECK=1 + +WORKDIR /app + +RUN addgroup --system app && adduser --system --ingroup app app + +COPY requirements.txt ./ +COPY --from=builder /wheels /wheels + +RUN pip install --no-cache-dir --no-index --find-links=/wheels -r requirements.txt \ + && rm -rf /wheels + +COPY . . + +RUN mkdir -p /app/static/img /app/images \ + && chown -R app:app /app + +USER app + +CMD ["python", "main.py"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..d7ec34f --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,59 @@ +services: + postgres: + env_file: prod.env + image: postgres:16-alpine + container_name: shveitech_db + environment: + POSTGRES_USER: ${POSTGRES_USER:-postgres} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres} + POSTGRES_DB: ${POSTGRES_DB:-postgres} + volumes: + - postgres_data:/var/lib/postgresql/data + healthcheck: + test: + [ + "CMD-SHELL", + "pg_isready -U ${POSTGRES_USER:-postgres} -d ${POSTGRES_DB:-postgres}", + ] + interval: 10s + timeout: 5s + retries: 5 + ports: + - "5432:5432" + + redis: + image: redis:7-alpine + container_name: shveitech_redis + healthcheck: + test: ["CMD", "redis-cli", "ping"] + interval: 10s + timeout: 5s + retries: 5 + ports: + - "6379:6379" + + bot: + env_file: prod.env + build: + dockerfile: Dockerfile + container_name: shveitech_bot + depends_on: + postgres: + condition: service_healthy + redis: + condition: service_healthy + environment: + BOT_TOKEN: ${BOT_TOKEN} + ADMINS: ${ADMINS} + POSTGRES_URL: postgresql+asyncpg://${POSTGRES_USER:-postgres}:${POSTGRES_PASSWORD:-postgres}@postgres:5432/${POSTGRES_DB:-postgres} + CARD_NUMBER: ${CARD_NUMBER} + CARD_HOLDER: ${CARD_HOLDER} + REDIS_URL: ${REDIS_URL:-redis://redis:6379/0} + PROXY_URL: ${PROXY_URL} + command: ["sh", "-c", "alembic upgrade head && python main.py"] + restart: unless-stopped + volumes: + - ./images:/app/images + +volumes: + postgres_data: