11# ###################################################################################################
2- # builder: install needed dependencies
2+ # Stage 1: Base Builder - installs core dependencies using poetry
33# ###################################################################################################
4+ FROM python:3.10-slim-bullseye AS base-builder
45
5- FROM python:3.11-slim-bullseye AS builder
6+ ENV PYSETUP_PATH="/opt/pysetup"
7+ WORKDIR $PYSETUP_PATH
8+
9+ # Copy only core dependency files first for better caching
10+ COPY pyproject.toml poetry.lock README.md ./
11+ COPY pynumaflow/ ./pynumaflow/
12+ RUN echo "Simulating long build step..." && sleep 20
13+ RUN apt-get update && apt-get install --no-install-recommends -y \
14+ curl wget build-essential git \
15+ && apt-get clean && rm -rf /var/lib/apt/lists/* \
16+ && pip install poetry \
17+ && poetry install --no-root --no-interaction
18+
19+ # ###################################################################################################
20+ # Stage 2: UDF Builder - adds UDF code and installs UDF-specific deps
21+ # ###################################################################################################
22+ FROM base-builder AS udf-builder
23+
24+ ENV EXAMPLE_PATH="/opt/pysetup/examples/accumulator/streamsorter"
25+ ENV POETRY_VIRTUALENVS_IN_PROJECT=true
26+
27+ WORKDIR $EXAMPLE_PATH
28+ COPY examples/accumulator/streamsorter/ ./
29+ RUN poetry install --no-root --no-interaction
630
7- ENV PYTHONFAULTHANDLER=1 \
8- PYTHONUNBUFFERED=1 \
9- PYTHONHASHSEED=random \
10- PIP_NO_CACHE_DIR=on \
11- PIP_DISABLE_PIP_VERSION_CHECK=on \
12- PIP_DEFAULT_TIMEOUT=100 \
13- POETRY_VERSION=1.2.2 \
14- POETRY_HOME="/opt/poetry" \
15- POETRY_VIRTUALENVS_IN_PROJECT=true \
16- POETRY_NO_INTERACTION=1 \
17- PYSETUP_PATH="/opt/pysetup"
31+ # ###################################################################################################
32+ # Stage 3: UDF Runtime - clean container with only needed stuff
33+ # ###################################################################################################
34+ FROM python:3.10-slim-bullseye AS udf
1835
36+ ENV PYSETUP_PATH="/opt/pysetup"
1937ENV EXAMPLE_PATH="$PYSETUP_PATH/examples/accumulator/streamsorter"
2038ENV VENV_PATH="$EXAMPLE_PATH/.venv"
21- ENV PATH="$POETRY_HOME/bin:$VENV_PATH/bin:$PATH"
22-
23- RUN apt-get update \
24- && apt-get install --no-install-recommends -y \
25- curl \
26- wget \
27- # deps for building python deps
28- build-essential \
29- && apt-get install -y git \
39+ ENV PATH="$VENV_PATH/bin:$PATH"
40+
41+ RUN apt-get update && apt-get install --no-install-recommends -y wget \
3042 && apt-get clean && rm -rf /var/lib/apt/lists/* \
31- \
32- # install dumb-init
3343 && wget -O /dumb-init https://github.com/Yelp/dumb-init/releases/download/v1.2.5/dumb-init_1.2.5_x86_64 \
34- && chmod +x /dumb-init \
35- && curl -sSL https://install.python-poetry.org | python3 -
36-
37- # ###################################################################################################
38- # udf: used for running the udf vertices
39- # ###################################################################################################
40- FROM builder AS udf
44+ && chmod +x /dumb-init
4145
4246WORKDIR $PYSETUP_PATH
43- COPY ./ ./
47+ COPY --from=udf-builder $VENV_PATH $VENV_PATH
48+ COPY --from=udf-builder $EXAMPLE_PATH $EXAMPLE_PATH
4449
4550WORKDIR $EXAMPLE_PATH
46- RUN poetry lock
47- RUN poetry install --no-cache --no-root && \
48- rm -rf ~/.cache/pypoetry/
49-
5051RUN chmod +x entry.sh
5152
5253ENTRYPOINT ["/dumb-init" , "--" ]
5354CMD ["sh" , "-c" , "$EXAMPLE_PATH/entry.sh" ]
5455
55- EXPOSE 5000
56+ EXPOSE 5000
0 commit comments