Skip to content

Commit 35156ba

Browse files
srao12srao12
authored andcommitted
fix: use optimized Dockerfile
Signed-off-by: srao12 <Shrivardhan_Rao@intuit.com>
1 parent 6466f31 commit 35156ba

8 files changed

Lines changed: 90 additions & 229 deletions

File tree

examples/accumulator/counter/Dockerfile

Lines changed: 0 additions & 55 deletions
This file was deleted.

examples/accumulator/counter/Makefile

Lines changed: 0 additions & 22 deletions
This file was deleted.

examples/accumulator/counter/entry.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.

examples/accumulator/counter/example.py

Lines changed: 0 additions & 46 deletions
This file was deleted.

examples/accumulator/counter/pipeline.yaml

Lines changed: 0 additions & 50 deletions
This file was deleted.

examples/accumulator/counter/pyproject.toml

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,56 @@
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"
1937
ENV EXAMPLE_PATH="$PYSETUP_PATH/examples/accumulator/streamsorter"
2038
ENV 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

4246
WORKDIR $PYSETUP_PATH
43-
COPY ./ ./
47+
COPY --from=udf-builder $VENV_PATH $VENV_PATH
48+
COPY --from=udf-builder $EXAMPLE_PATH $EXAMPLE_PATH
4449

4550
WORKDIR $EXAMPLE_PATH
46-
RUN poetry lock
47-
RUN poetry install --no-cache --no-root && \
48-
rm -rf ~/.cache/pypoetry/
49-
5051
RUN chmod +x entry.sh
5152

5253
ENTRYPOINT ["/dumb-init", "--"]
5354
CMD ["sh", "-c", "$EXAMPLE_PATH/entry.sh"]
5455

55-
EXPOSE 5000
56+
EXPOSE 5000
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
TAG ?= stable
2+
PUSH ?= false
3+
IMAGE_REGISTRY = quay.io/numaio/numaflow-python/streamsorter:${TAG}
4+
DOCKER_FILE_PATH = examples/map/even_odd/Dockerfile.optimized
5+
BASE_IMAGE_NAME = numaflow-python-base
6+
7+
.PHONY: base-image
8+
base-image:
9+
@echo "Building shared base image..."
10+
docker build -f Dockerfile.base -t ${BASE_IMAGE_NAME} .
11+
12+
.PHONY: update
13+
update:
14+
poetry update -vv
15+
16+
.PHONY: image-push
17+
image-push: base-image update
18+
cd ../../../ && docker buildx build \
19+
-f ${DOCKER_FILE_PATH} \
20+
-t ${IMAGE_REGISTRY} \
21+
--platform linux/amd64,linux/arm64 . --push
22+
23+
.PHONY: image
24+
image: base-image update
25+
cd ../../../ && docker build \
26+
-f ${DOCKER_FILE_PATH} \
27+
-t ${IMAGE_REGISTRY} .
28+
@if [ "$(PUSH)" = "true" ]; then docker push ${IMAGE_REGISTRY}; fi
29+
30+
.PHONY: image-fast
31+
image-fast: update
32+
@echo "Building with shared base image (fastest option)..."
33+
cd ../../../ && docker build \
34+
-f examples/map/even_odd/Dockerfile.shared-base \
35+
-t ${IMAGE_REGISTRY} .
36+
@if [ "$(PUSH)" = "true" ]; then docker push ${IMAGE_REGISTRY}; fi
37+
38+
.PHONY: clean
39+
clean:
40+
docker rmi ${BASE_IMAGE_NAME} 2>/dev/null || true
41+
docker rmi ${IMAGE_REGISTRY} 2>/dev/null || true
42+
43+
.PHONY: help
44+
help:
45+
@echo "Available targets:"
46+
@echo " base-image - Build the shared base image with pynumaflow"
47+
@echo " image - Build UDF image with optimized multi-stage build"
48+
@echo " image-fast - Build UDF image using shared base (fastest)"
49+
@echo " image-push - Build and push multi-platform image"
50+
@echo " update - Update poetry dependencies"
51+
@echo " clean - Remove built images"
52+
@echo " help - Show this help message"

0 commit comments

Comments
 (0)