Skip to content

Commit abc00df

Browse files
committed
feat(docker): add Dockerfile and .dockerignore for containerized application setup
- Introduced a multi-stage Dockerfile to build and run the application in a lightweight environment. - Added a .dockerignore file to exclude unnecessary files from the Docker context, improving build efficiency.
1 parent 4a71659 commit abc00df

2 files changed

Lines changed: 90 additions & 0 deletions

File tree

.dockerignore

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Git
2+
.git
3+
.gitignore
4+
5+
# Virtual environments
6+
.venv
7+
venv
8+
__pycache__
9+
*.pyc
10+
*.pyo
11+
12+
# IDE and editor
13+
.cursor
14+
.vscode
15+
.idea
16+
*.swp
17+
*.swo
18+
19+
# Testing
20+
.pytest_cache
21+
.coverage
22+
htmlcov
23+
24+
# Environment files (secrets should be passed at runtime)
25+
.env
26+
.env.*
27+
!.env.example
28+
29+
# Documentation and misc
30+
*.md
31+
!README.md
32+
LICENSE
33+
34+
# Build artifacts
35+
dist
36+
build
37+
*.egg-info

Dockerfile

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Stage 1: Build the Application
2+
FROM python:3.14-slim AS build
3+
4+
WORKDIR /usr/src/app
5+
6+
# Install system dependencies needed for building Python packages
7+
RUN apt-get update && apt-get install -y --no-install-recommends \
8+
build-essential \
9+
gcc \
10+
&& rm -rf /var/lib/apt/lists/*
11+
12+
# Install uv for fast dependency management
13+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
14+
15+
# Copy dependency files
16+
COPY pyproject.toml uv.lock ./
17+
18+
# Install dependencies into a virtual environment
19+
RUN uv venv /opt/venv && \
20+
uv pip install --python /opt/venv/bin/python --no-cache -r pyproject.toml
21+
22+
# Copy the rest of the application source code
23+
COPY . .
24+
25+
# Install the package itself
26+
RUN uv pip install --python /opt/venv/bin/python --no-cache -e .
27+
28+
29+
# Stage 2: Create the Final Production Image
30+
FROM python:3.14-slim
31+
32+
WORKDIR /usr/src/app
33+
34+
# Install only runtime dependencies (libpq for psycopg)
35+
RUN apt-get update && apt-get install -y --no-install-recommends \
36+
libpq5 \
37+
&& rm -rf /var/lib/apt/lists/*
38+
39+
# Copy the virtual environment from the build stage
40+
COPY --from=build /opt/venv /opt/venv
41+
42+
# Copy the application code
43+
COPY --from=build /usr/src/app .
44+
45+
# Set the virtual environment as the active Python environment
46+
ENV PATH="/opt/venv/bin:$PATH"
47+
48+
# Create a non-root user to run the application
49+
RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /usr/src/app
50+
USER appuser
51+
52+
# Define the command to start the bot
53+
CMD ["python-italy-bot"]

0 commit comments

Comments
 (0)