-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
51 lines (36 loc) · 1.07 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Stage 1: Base image; exporting wheel
FROM python:3.12-slim-bookworm AS builder
# Set environment variables
ENV POETRY_VIRTUALENVS_CREATE=false
# Install pipx
RUN python3 -m pip install -U --no-cache-dir pipx && \
pipx ensurepath
# Install Poetry via pipx
RUN pipx install --global poetry
# Set work directory
WORKDIR /app
# Copy the pyproject.toml and poetry.lock files
COPY . ./
# Install dependencies and build the wheel
RUN poetry install \
--no-root \
--no-directory \
--without dev,test \
--no-interaction \
--no-ansi
RUN poetry build -f wheel --no-interaction --no-ansi
# Stage 2: Runner image, installing wheel, running the application
FROM python:3.12-slim-bookworm AS runner
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_DISABLE_PIP_VERSION_CHECK=on
# Set work directory
WORKDIR /src
# Copy the built wheel from the builder stage
COPY --from=builder /app/dist/*.whl ./
# Install the wheel
RUN pip install --no-cache-dir *.whl
# Copy application code
COPY . .
CMD ["python", "-m", "src", "hello", "Ben"]