feat: +Dockerfile

This commit is contained in:
2026-08-13 11:10:33 +07:00
parent 8444386885
commit 104cf71969
2 changed files with 101 additions and 0 deletions

42
Dockerfile Normal file
View File

@@ -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"]

59
docker-compose.yml Normal file
View File

@@ -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: