Skip to content

Commit ec54986

Browse files
authored
Refactor Dockerfile to use setuptools build (#21)
fix(docker): Refactor Dockerfile to use standard setuptools build This commit resolves a Docker build failure that occurred after migrating the project from Poetry to setuptools. The CI pipeline was failing because the Dockerfile still contained Poetry-specific commands. The Dockerfile has been refactored to use a standard, multi-stage build process: - The builder stage now uses `python -m build` to create a Python wheel. - The runtime stage installs the application and its dependencies from the wheel generated in the builder stage. Additionally, the `build` package version has been pinned to `1.3.0` in the Dockerfile to satisfy a `hadolint` pre-commit hook.
1 parent 0f2ef04 commit ec54986

1 file changed

Lines changed: 10 additions & 15 deletions

File tree

Dockerfile

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
# Stage 1: Builder
22
FROM python:3.12-slim AS builder
33

4-
# Install poetry
5-
RUN pip install --no-cache-dir poetry==1.8.2
4+
# Install build dependencies
5+
RUN pip install --no-cache-dir build==1.3.0
66

77
# Set the working directory
88
WORKDIR /app
99

10-
# Copy the project files and install dependencies
11-
COPY pyproject.toml poetry.lock* ./
10+
# Copy the project files
11+
COPY pyproject.toml .
1212
COPY src/ ./src/
1313

14-
# Export dependencies and install them
15-
RUN mkdir -p /install && \
16-
poetry export -f requirements.txt --output requirements.txt --without-hashes && \
17-
pip install --no-cache-dir --prefix="/install" -r requirements.txt
14+
# Build the wheel
15+
RUN python -m build --wheel --outdir /wheels
1816

1917

2018
# Stage 2: Runtime
@@ -30,11 +28,8 @@ ENV PATH="/home/appuser/.local/bin:${PATH}"
3028
# Set the working directory
3129
WORKDIR /home/appuser/app
3230

33-
# Copy the installed dependencies from the builder stage
34-
COPY --from=builder /install /usr/local
31+
# Copy the wheel from the builder stage
32+
COPY --from=builder /wheels /wheels
3533

36-
# Copy the application source code from the builder stage
37-
COPY --from=builder /app/src/my_python_project ./my_python_project
38-
39-
# Set the PYTHONPATH to include the installed packages
40-
ENV PYTHONPATH="/home/appuser/app"
34+
# Install the application wheel
35+
RUN pip install --no-cache-dir /wheels/*.whl

0 commit comments

Comments
 (0)