Add Docker support with multi-stage build

- Added `Dockerfile` to streamline application containerization.
- Introduced `.dockerignore` file for better build context management.
This commit is contained in:
TzuWei 2026-02-28 22:24:39 +09:00
parent b622883144
commit b3436707ad
Signed by: tzuwei-huang
GPG Key ID: 88A0D3DA7558EE01
3 changed files with 54 additions and 0 deletions

16
.dockerignore Normal file
View File

@ -0,0 +1,16 @@
__pycache__
.venv
.git
.idea
.env
Downloads/
test_downloads/
*.pyc
*.pyo
*.pyd
.Python
env/
venv/
ENV/
env.bak/
venv.bak/

38
Dockerfile Normal file
View File

@ -0,0 +1,38 @@
# Use a specialized uv image for faster dependency management
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim AS builder
# Set the working directory
WORKDIR /app
# Enable bytecode compilation
ENV UV_COMPILE_BYTECODE=1
# Copy from the cache instead of linking since it's a multi-stage build
ENV UV_LINK_MODE=copy
# Install dependencies first (for caching)
COPY pyproject.toml uv.lock ./
RUN --mount=type=cache,target=/root/.cache/uv
uv sync --frozen --no-install-project --no-dev
# Final stage
FROM python:3.12-slim-bookworm
WORKDIR /app
# Copy the environment from the builder
COPY --from=builder /app/.venv /app/.venv
# Copy the application code
COPY . .
# Set environment variables
ENV PATH="/app/.venv/bin:$PATH"
ENV PYTHONUNBUFFERED=1
ENV TZ=Asia/Taipei
# Create directory for downloads
RUN mkdir -p /app/Downloads
# The command to run the bot
CMD ["python", "bot/tg_bot.py"]

View File