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:
parent
b622883144
commit
b3436707ad
16
.dockerignore
Normal file
16
.dockerignore
Normal 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
38
Dockerfile
Normal 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"]
|
||||
Loading…
x
Reference in New Issue
Block a user