Skip to content

Commit 2dbe614

Browse files
authored
Merge pull request #7833 from dmiltr3/dev_new_image
fixing docker build and Vertex AI tests
2 parents 66d0d7b + ae70599 commit 2dbe614

7 files changed

Lines changed: 335 additions & 197 deletions

File tree

patches/tfx.patch

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -92,48 +92,17 @@ index 19489315a..05b464767 100644
9292
]
9393

9494

95-
@@ -173,7 +149,6 @@ def make_extra_packages_docker_image():
95+
@@ -173,7 +173,6 @@ def make_extra_packages_docker_image():
9696
"mmh>=2.2,<3",
9797
"python-snappy>=0.7",
9898
# Required for tfx/examples/penguin/penguin_utils_cloud_tuner.py
9999
- "tensorflow-cloud>=0.1,<0.2",
100100
"tensorflow-io>=0.9.0, <=0.24.0",
101101
]
102102

103-
@@ -246,7 +221,6 @@ def make_extra_packages_examples():
103+
@@ -246,5 +245,4 @@ def make_extra_packages_examples():
104104
# LINT.ThenChange(
105105
# examples/penguin/experimental/penguin_pipeline_sklearn_gcp.py)
106106
# Required for tfx/examples/penguin/penguin_utils_cloud_tuner.py
107107
- "tensorflow-cloud>=0.1,<0.2",
108108
]
109-
110-
111-
diff --git a/tfx/tools/docker/requirements.txt b/tfx/tools/docker/requirements.txt
112-
index d7b3e960e..7e7862afc 100644
113-
--- a/tfx/tools/docker/requirements.txt
114-
+++ b/tfx/tools/docker/requirements.txt
115-
@@ -300,8 +300,6 @@ tenacity==9.0.0
116-
tensorboard==2.17.1
117-
tensorboard-data-server==0.7.2
118-
tensorflow==2.17.1
119-
-tensorflow-cloud==0.1.16
120-
-tensorflow-data-validation==1.17.0
121-
tensorflow-datasets==4.9.3
122-
tensorflow-decision-forests==1.10.1
123-
tensorflow-estimator==2.15.0
124-
@@ -312,7 +310,6 @@ tensorflow-metadata>=1.17.1
125-
# tensorflow-ranking==0.5.5
126-
tensorflow-serving-api==2.17.1
127-
tensorflow-text==2.17.0
128-
-tensorflow-transform>=1.17.0
129-
tensorflow_model_analysis>=0.48.0
130-
tensorflowjs==4.17.0
131-
tensorstore==0.1.66
132-
@@ -320,7 +317,6 @@ termcolor==2.5.0
133-
terminado==0.18.1
134-
text-unidecode==1.3
135-
tflite-support==0.4.4
136-
-tfx-bsl>=1.17.1
137-
threadpoolctl==3.5.0
138-
time-machine==2.16.0
139-
tinycss2==1.3.0

tfx/tools/docker/Dockerfile

Lines changed: 137 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -17,61 +17,117 @@ ARG BASE_IMAGE
1717
# Apache beam version to get Beam binaries.
1818
ARG BEAM_VERSION
1919

20-
FROM gcr.io/tfx-oss-public/tfx_base:py310-20230921 as wheel-builder
21-
# docker build command should be run under root directory of github checkout.
22-
ENV TFX_DIR=/tfx
23-
ADD . ${TFX_DIR}/src
24-
WORKDIR ${TFX_DIR}
20+
FROM ${BASE_IMAGE} AS base-with-gcc13
21+
RUN /opt/conda/bin/conda install -y --override-channels -c conda-forge \
22+
gcc_linux-64=13 \
23+
gxx_linux-64=13 \
24+
binutils_linux-64=2.40 \
25+
ld_impl_linux-64=2.40
26+
27+
ENV CC=/opt/conda/bin/x86_64-conda-linux-gnu-gcc
28+
ENV CXX=/opt/conda/bin/x86_64-conda-linux-gnu-g++
29+
ENV LD=/opt/conda/bin/x86_64-conda-linux-gnu-ld
30+
ENV AR=/opt/conda/bin/x86_64-conda-linux-gnu-ar
31+
ENV NM=/opt/conda/bin/x86_64-conda-linux-gnu-nm
32+
ENV OBJCOPY=/opt/conda/bin/x86_64-conda-linux-gnu-objcopy
33+
ENV OBJDUMP=/opt/conda/bin/x86_64-conda-linux-gnu-objdump
34+
ENV RANLIB=/opt/conda/bin/x86_64-conda-linux-gnu-ranlib
35+
ENV STRIP=/opt/conda/bin/x86_64-conda-linux-gnu-strip
36+
37+
ENV BAZEL_COMPILER=gcc
38+
39+
FROM base-with-gcc13 AS wheel-builder
40+
ARG BASE_IMAGE
41+
ARG BEAM_VERSION
42+
# Whether to use C++ wheels (tfdv, tfx_bsl) from the host cache (/tmp/wheels).
43+
# If true, cached wheels are used if available (this saves time when debugging the docker build issues).
44+
# If false, wheels are built from source even if they exist in the cache.
45+
ARG USE_CPP_WHEELS_FROM_TEMP=false
46+
# Whether to clear the persistent build caches (/tmp/wheels and bazel cache).
47+
ARG CLEAN_CPP_TEMP_CACHE=false
2548

2649
# Specify what version of dependent libraries will be used. See dependencies.py.
2750
ARG TFX_DEPENDENCY_SELECTOR
2851
ENV TFX_DEPENDENCY_SELECTOR=${TFX_DEPENDENCY_SELECTOR}
52+
2953
ENV USE_BAZEL_VERSION=6.5.0
3054

31-
RUN python -m pip install --upgrade pip wheel setuptools==70.0.0 tomli
55+
RUN apt-get update && apt-get install -y curl git && \
56+
(find /opt/conda/bin -name "python3-config" | head -n 1 | xargs -I {} ln -sf {} /usr/bin/python-config) && \
57+
(find /opt/conda/bin -name "python3-config" | head -n 1 | xargs -I {} ln -sf {} /opt/conda/bin/python-config)
58+
RUN mkdir -p /usr/local/lib/bazel/bin && \
59+
curl -fLO https://github.com/bazelbuild/bazel/releases/download/${USE_BAZEL_VERSION}/bazel-${USE_BAZEL_VERSION}-linux-x86_64 && \
60+
mv bazel-${USE_BAZEL_VERSION}-linux-x86_64 /usr/local/lib/bazel/bin/bazel && \
61+
chmod +x /usr/local/lib/bazel/bin/bazel && \
62+
ln -sf /usr/local/lib/bazel/bin/bazel /usr/local/bin/bazel
63+
ENV PATH="/usr/local/lib/bazel/bin:${PATH}"
64+
65+
66+
COPY . /tfx/src/
67+
WORKDIR /tfx/src/
68+
69+
# 1. C++ Wheels (tfdv, tfx_bsl) - Normal production build path
70+
RUN if [ "$USE_CPP_WHEELS_FROM_TEMP" = "false" ]; then \
71+
echo "Rebuild of C++ wheels (tfdv, tfx_bsl)..." && \
72+
cp tfx/tools/docker/build_tfdv_wheels.sh /tmp/ && \
73+
cp tfx/tools/docker/build_tfx_bsl_wheels.sh /tmp/ && \
74+
cp tfx/tools/docker/*.patch /tmp/ && \
75+
mkdir -p /tfx/src/dist_wheels && \
76+
bash /tmp/build_tfdv_wheels.sh /tfx/src/dist_wheels && \
77+
bash /tmp/build_tfx_bsl_wheels.sh /tfx/src/dist_wheels ; \
78+
fi
79+
80+
# 2. C++ Wheels (tfdv, tfx_bsl) - Cached Path to avoid any CPP rebuilds
81+
RUN --mount=type=cache,target=/tmp/wheels --mount=type=cache,target=/root/.cache/bazel \
82+
if [ "$USE_CPP_WHEELS_FROM_TEMP" = "true" ]; then \
83+
echo "Re-use cached build of C++ wheels (tfdv, tfx_bsl)..." && \
84+
cp tfx/tools/docker/build_tfdv_wheels.sh /tmp/ && \
85+
cp tfx/tools/docker/build_tfx_bsl_wheels.sh /tmp/ && \
86+
cp tfx/tools/docker/*.patch /tmp/ && \
87+
if [ ! -f /tmp/wheels/tensorflow_data_validation-*.whl ]; then bash /tmp/build_tfdv_wheels.sh /tmp/wheels; fi && \
88+
if [ ! -f /tmp/wheels/tfx_bsl-*.whl ]; then bash /tmp/build_tfx_bsl_wheels.sh /tmp/wheels; fi && \
89+
mkdir -p /tfx/src/dist_wheels && \
90+
cp /tmp/wheels/tensorflow_data_validation-*.whl /tfx/src/dist_wheels/ && \
91+
cp /tmp/wheels/tfx_bsl-*.whl /tfx/src/dist_wheels/ ; \
92+
fi
3293

3394
# TODO(b/175089240): clean up conditional checks on whether ml-pipelines-sdk is
3495
# built after TFX versions <= 0.25 are no longer eligible for cherry-picks.
35-
RUN cd ${TFX_DIR}/src; \
96+
RUN echo "Building TFX and SDK wheels from source..." && \
97+
mkdir -p /tfx/src/dist_wheels && \
3698
if [ -e "package_build" ]; then \
37-
bash -x package_build/initialize.sh; \
38-
cd package_build/ml-pipelines-sdk; \
39-
CFLAGS=$(/usr/bin/python-config --cflags) \
40-
python setup.py bdist_wheel; \
41-
cd ../../package_build/tfx; \
42-
CFLAGS=$(/usr/bin/python-config --cflags) \
43-
python setup.py bdist_wheel; \
44-
cd ../..; \
45-
MLSDK_WHEEL=$(find dist -name "ml_pipelines_sdk-*.whl"); \
46-
TFX_WHEEL=$(find dist -name "tfx-*.whl"); \
99+
bash -x package_build/initialize.sh && \
100+
CFLAGS=$(python-config --cflags) python package_build/ml-pipelines-sdk/setup.py bdist_wheel && \
101+
CFLAGS=$(python-config --cflags) python package_build/tfx/setup.py bdist_wheel && \
102+
cp package_build/ml-pipelines-sdk/dist/*.whl /tfx/src/dist_wheels/ && \
103+
cp package_build/tfx/dist/*.whl /tfx/src/dist_wheels/ ; \
47104
else \
48-
CFLAGS=$(/usr/bin/python-config --cflags) \
49-
python setup.py bdist_wheel; \
50-
MLSDK_WHEEL=; \
51-
TFX_WHEEL=$(find dist -name "tfx-*.whl"); \
52-
fi; \
53-
if [ "${TFX_DEPENDENCY_SELECTOR}" = "NIGHTLY" ]; then \
54-
CFLAGS=$(/usr/bin/python-config --cflags) \
55-
python -m pip install \
56-
--extra-index-url https://pypi-nightly.tensorflow.org/simple \
57-
${MLSDK_WHEEL} ${TFX_WHEEL}[docker-image] -c tfx/tools/docker/requirements.txt -c tfx/tools/docker/build_constraints.txt; \
58-
else \
59-
CFLAGS=$(/usr/bin/python-config --cflags) \
60-
python -m pip install ${MLSDK_WHEEL} ${TFX_WHEEL}[docker-image] -c tfx/tools/docker/requirements.txt -c tfx/tools/docker/build_constraints.txt; \
61-
fi;
62-
63-
# We need to name this step for the next COPY --from command.
64-
FROM apache/beam_python3.10_sdk:${BEAM_VERSION} as beam-worker
105+
CFLAGS=$(python-config --cflags) python setup.py bdist_wheel && \
106+
cp dist/*.whl /tfx/src/dist_wheels/ ; \
107+
fi
65108

66-
# Build stage to extend DLVM image.
67-
FROM ${BASE_IMAGE} as install
109+
# --- Stage 2: beam-worker ---
110+
FROM apache/beam_python3.10_sdk:${BEAM_VERSION} AS beam-worker
68111

69-
# Additional Python packages which will be installed.
112+
# --- Stage 3: install (Final) ---
113+
FROM base-with-gcc13 AS install
114+
ARG BASE_IMAGE
70115
ARG ADDITIONAL_PACKAGES
71-
72-
# Specify what version of dependent libraries will be used. See dependencies.py.
116+
ENV TF_CPP_MIN_LOG_LEVEL=3
117+
# Disables Legacy "Virtual" Devices
118+
ENV TF_XLA_FLAGS="--tf_xla_enable_xla_devices=false"
73119
ARG TFX_DEPENDENCY_SELECTOR
74120
ENV TFX_DEPENDENCY_SELECTOR=${TFX_DEPENDENCY_SELECTOR}
121+
ENV TF_USE_LEGACY_KERAS=1
122+
123+
# 1. Apply OS security updates and install required system libraries
124+
RUN apt-get update && \
125+
apt-get install -y --no-install-recommends \
126+
ca-certificates \
127+
libsnappy-dev \
128+
libcurl4-openssl-dev \
129+
&& apt-get clean && \
130+
rm -rf /var/lib/apt/lists/*
75131

76132
# Copy from image matching installed version of 'apache-beam'.
77133
COPY --from=beam-worker /opt/apache/beam /opt/apache/beam
@@ -84,60 +140,48 @@ ENTRYPOINT ["/opt/apache/beam/boot"]
84140

85141
LABEL maintainer="tensorflow-extended-dev@googlegroups.com"
86142

87-
RUN sed -i 's/python3/python/g' /usr/bin/pip
88-
89-
RUN python -m pip install --upgrade pip setuptools==70.0.0 wheel
90-
91-
RUN CURRENT_DIR="$(pwd)" && \
92-
mkdir -p /usr/local/lib/bazel/bin && \
93-
cd "/usr/local/lib/bazel/bin" && \
94-
curl -fLO https://releases.bazel.build/6.5.0/release/bazel-6.5.0-linux-x86_64 && \
95-
chmod +x bazel-6.5.0-linux-x86_64 && \
96-
ln -sf /usr/local/lib/bazel/bin/bazel-6.5.0-linux-x86_64 /usr/local/bin/bazel && \
97-
cd "$CURRENT_DIR"
98-
99-
# Build tensorflow-data-validation wheels from source with patch
100-
RUN /opt/conda/bin/conda install -y -c conda-forge \
101-
gcc_linux-64=13 \
102-
gxx_linux-64=13 \
103-
binutils_linux-64=2.40 \
104-
ld_impl_linux-64=2.40
105-
106-
ENV CC=/opt/conda/bin/x86_64-conda-linux-gnu-gcc
107-
108-
ENV CXX=/opt/conda/bin/x86_64-conda-linux-gnu-g++
109-
110-
ENV LD=/opt/conda/bin/x86_64-conda-linux-gnu-ld
111-
112-
COPY tfx/tools/docker/build_tfdv_wheels.sh /tmp/
113-
COPY tfx/tools/docker/tfdv.patch /tmp/
114-
RUN mkdir -p /tmp/wheels && \
115-
bash /tmp/build_tfdv_wheels.sh /tmp/wheels
116-
117-
# Build tfx-bsl wheels from source with patch
118-
COPY tfx/tools/docker/build_tfx_bsl_wheels.sh /tmp/
119-
COPY tfx/tools/docker/tfx_bsl.patch /tmp/
120-
RUN bash /tmp/build_tfx_bsl_wheels.sh /tmp/wheels
121-
122-
# Copy constraint file and wheels
123-
COPY tfx/tools/docker/build_constraints.txt /tmp/
124-
COPY tfx/tools/docker/wheels/*.whl /tmp/wheels/
125-
126-
# Install tensorflow-data-validation, tfx-bsl, tensorflow-model-analysis, tensorflow-transform, and tensorflow-cloud first
127-
RUN PIP_CONSTRAINT=/tmp/build_constraints.txt python -m pip install /tmp/wheels/tensorflow_data_validation-*.whl /tmp/wheels/tfx_bsl-*.whl /tmp/wheels/tensorflow_model_analysis-*.whl /tmp/wheels/tensorflow_transform-*.whl /tmp/wheels/tensorflow_cloud-*.whl
128-
129-
COPY --from=wheel-builder /tfx/src/dist/*.whl /tfx/src/dist/
130-
WORKDIR /tfx/src
131-
132-
RUN MLSDK_WHEEL=$(find dist -name "ml_pipelines_sdk-*.whl"); \
133-
TFX_WHEEL=$(find dist -name "tfx-*.whl"); \
134-
if [ "${TFX_DEPENDENCY_SELECTOR}" = "NIGHTLY" ]; then \
135-
PIP_CONSTRAINT=/tmp/build_constraints.txt python -m pip install \
136-
--extra-index-url https://pypi-nightly.tensorflow.org/simple \
137-
${MLSDK_WHEEL} ${TFX_WHEEL}[docker-image] ${ADDITIONAL_PACKAGES} ; \
143+
COPY --from=wheel-builder /tfx/src /tfx/src
144+
145+
# 2. Upgrade core python build tools and remove unused vulnerable components
146+
# setuptools==78.1.1 is required for the pkg_resources shim (needed by apache-beam),
147+
# while providing the security fix for CVE-2025-47273.
148+
RUN python -m pip install --upgrade pip setuptools==78.1.1 wheel \
149+
-c /tfx/src/tfx/tools/docker/requirements.txt \
150+
-c /tfx/src/tfx/tools/docker/build_constraints.txt
151+
152+
# 3. Main installation: consolidated to a single RUN for single-pass resolution.
153+
# We explicitly include setuptools==78.1.1 as a top-level requirement here
154+
# to ensure the resolver doesn't downgrade it or use a broken version
155+
# that lacks the pkg_resources shim (needed by apache-beam).
156+
RUN if [ "${TFX_DEPENDENCY_SELECTOR}" = "NIGHTLY" ]; then \
157+
python -m pip install --no-cache-dir \
158+
--extra-index-url https://pypi-nightly.tensorflow.org/simple \
159+
-c /tfx/src/tfx/tools/docker/requirements.txt \
160+
-c /tfx/src/tfx/tools/docker/build_constraints.txt \
161+
/tfx/src/dist_wheels/*.whl \
162+
/tfx/src/tfx/tools/docker/wheels/*.whl \
163+
"$(find /tfx/src/dist_wheels/ \( -name 'tfx_dev-*.whl' -o -name 'tfx-*.whl' \) | head -n 1)[docker-image]" \
164+
tf_keras setuptools==78.1.1 ${ADDITIONAL_PACKAGES} ; \
138165
else \
139-
PIP_CONSTRAINT=/tmp/build_constraints.txt python -m pip install ${MLSDK_WHEEL} ${TFX_WHEEL}[docker-image] \
140-
${ADDITIONAL_PACKAGES} ; \
166+
python -m pip install --no-cache-dir \
167+
-c /tfx/src/tfx/tools/docker/requirements.txt \
168+
-c /tfx/src/tfx/tools/docker/build_constraints.txt \
169+
/tfx/src/dist_wheels/*.whl \
170+
/tfx/src/tfx/tools/docker/wheels/*.whl \
171+
"$(find /tfx/src/dist_wheels/ \( -name 'tfx_dev-*.whl' -o -name 'tfx-*.whl' \) | head -n 1)[docker-image]" \
172+
tf_keras setuptools==78.1.1 ${ADDITIONAL_PACKAGES} ; \
141173
fi && \
142-
echo "Installed python packages:\n" && python -m pip list && \
174+
(python -m pip uninstall -y jupyter jupyter-server jupyterlab notebook nbconvert jaraco-context jaraco.context || true)
175+
176+
# 4. Final OS cleanup: remove Go toolchain and other unused tools to fix Go-related CVEs
177+
# Many High/Critical CVEs are in the Go stdlib/toolchain which we don't need at runtime.
178+
# We use a loop to avoid build failures if a package name is not found in the repo.
179+
RUN for pkg in golang-go golang git binutils wget policykit-1 packagekit gnupg2 gcc-12; do apt-get purge -y $pkg || echo "Package $pkg not found, skipping"; done && \
180+
rm -rf /usr/local/go && \
181+
rm -rf /opt/apache/beam && \
182+
find /opt/conda/lib/python3.10/site-packages/apache_beam -type f -name "boot" -delete || true && \
183+
apt-get autoremove -y && \
184+
apt-get clean
185+
186+
RUN echo "Installed python packages:\n" && python -m pip list && \
143187
echo "Setuptools version:" && python -c "import setuptools; print(setuptools.__version__)"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM python:3.10-slim@sha256:c299e10e0070171113f9a1f109dd05e7e634fa94589b056e0e87bb22b2b382a2
2+
3+
WORKDIR /src
4+
5+
COPY tfx/dependencies.py .
6+
COPY tfx/tools/docker/discover_versions.py .
7+
COPY tfx/tools/docker/requirements.txt tfx/tools/docker/
8+
COPY tfx/tools/docker/build_constraints.txt tfx/tools/docker/
9+
10+
ENV PIP_CONSTRAINT="/src/tfx/tools/docker/build_constraints.txt"
11+
12+
RUN pip install --upgrade pip setuptools wheel tomli \
13+
-c tfx/tools/docker/requirements.txt \
14+
-c tfx/tools/docker/build_constraints.txt
15+
16+
# Ensure dependencies.py can be imported
17+
ENV PYTHONPATH="/src"
18+
19+
ENTRYPOINT ["python3", "discover_versions.py"]
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
setuptools==70.0.0
2-
wheel==0.43.0
1+
setuptools==78.1.1
2+
wheel==0.45.1

0 commit comments

Comments
 (0)