3131#
3232# TF_DOCKER_BUILD_CENTRAL_PIP
3333# (Optional)
34- # If set to any non-0 and non-empty value, will attempt to use the PIP file
35- # located on the central repo, instead of locally built pip files.
36- # This option takes effect only for non-devel builds.
34+ # If set to a non-empty string, will use it as the URL from which the
35+ # pip wheel file will be downloaded (instead of building the pip locally).
3736#
3837# TF_DOCKER_BUILD_IMAGE_NAME:
3938# (Optional)
@@ -81,7 +80,6 @@ mark_check_failed() {
8180
8281TF_DOCKER_BUILD_TYPE=$( to_lower ${TF_DOCKER_BUILD_TYPE} )
8382TF_DOCKER_BUILD_IS_DEVEL=$( to_lower ${TF_DOCKER_BUILD_IS_DEVEL} )
84- TF_DOCKER_BUILD_CENTRAL_PIP=$( to_lower ${TF_DOCKER_BUILD_CENTRAL_PIP} )
8583TF_DOCKER_BUILD_PYTHON_VERSION=$( to_lower ${TF_DOCKER_BUILD_PYTHON_VERSION:- PYTHON2} )
8684TF_DOCKER_BUILD_OPTIONS=$( to_lower ${TF_DOCKER_BUILD_OPTIONS:- OPT} )
8785
@@ -144,6 +142,15 @@ else
144142" ${TF_DOCKER_BUILD_TYPE} "
145143fi
146144
145+ if [[ " ${TF_DOCKER_BUILD_PYTHON_VERSION} " == " python2" ]]; then
146+ :
147+ elif [[ " ${TF_DOCKER_BUILD_PYTHON_VERSION} " == " python3" ]]; then
148+ FINAL_TAG=" ${FINAL_TAG} -py3"
149+ else
150+ die " Unrecognized value in TF_DOCKER_BUILD_PYTHON_VERSION: " \
151+ " ${TF_DOCKER_BUILD_PYTHON_VERSION} "
152+ fi
153+
147154# Verify that the original Dockerfile exists
148155ORIG_DOCKERFILE=" ${SCRIPT_DIR} /${ORIG_DOCKERFILE} "
149156if [[ ! -f " ${ORIG_DOCKERFILE} " ]]; then
@@ -156,21 +163,6 @@ echo "FINAL_TAG: ${FINAL_TAG}"
156163echo " Original Dockerfile: ${ORIG_DOCKERFILE} "
157164echo " "
158165
159-
160- DO_PIP_BUILD=0
161- if [[ ${TF_DOCKER_BUILD_IS_DEVEL} == " yes" ]]; then
162- # Devel builds has pip build instructions in the Dockerfile
163- :
164- else
165- if [[ ! -z ${TF_DOCKER_BUILD_CENTRAL_PIP} ]] &&
166- [[ ${TF_DOCKER_BUILD_CENTRAL_PIP} != " 0" ]]; then
167- :
168- else
169- DO_PIP_BUILD=1
170- fi
171- fi
172-
173-
174166# Create tmp directory for Docker build
175167TMP_DIR=$( mktemp -d)
176168echo " "
@@ -179,67 +171,96 @@ echo "Docker build will occur in temporary directory: ${TMP_DIR}"
179171# Copy all files to tmp directory for Docker build
180172cp -r ${SCRIPT_DIR} /* " ${TMP_DIR} /"
181173
182-
183- if [[ " ${DO_PIP_BUILD} " == " 1" ]]; then
174+ if [[ " ${TF_DOCKER_BUILD_IS_DEVEL} " == " no" ]]; then
184175 DOCKERFILE=" ${TMP_DIR} /Dockerfile"
185176
186- # Perform local build of the required PIP whl file
187- export TF_BUILD_CONTAINER_TYPE=${TF_DOCKER_BUILD_TYPE}
188- export TF_BUILD_PYTHON_VERSION=${TF_DOCKER_BUILD_PYTHON_VERSION}
189- export TF_BUILD_OPTIONS=${TF_DOCKER_BUILD_OPTIONS}
190- export TF_BUILD_IS_PIP=" PIP"
191-
192- if [[ " ${TF_DOCKER_BUILD_TYPE} " == " gpu" ]]; then
193- export TF_BUILD_APPEND_CI_DOCKER_EXTRA_PARAMS=\
194- " ${TF_BUILD_APPEND_CI_DOCKER_EXTRA_PARAMS} -e TF_CUDA_COMPUTE_CAPABILITIES=3.0,3.5,5.2"
195- fi
196-
197- pushd " ${SCRIPT_DIR} /../../../"
198- rm -rf pip_test/whl &&
199- tensorflow/tools/ci_build/ci_parameterized_build.sh
200- PIP_BUILD_EXIT_CODE=$?
201- popd
202-
203- # Was the pip build successful?
204- if [[ ${PIP_BUILD_EXIT_CODE} != " 0" ]]; then
205- die " FAIL: Failed to build pip file locally"
206- fi
207-
208- PIP_WHL=$( ls pip_test/whl/* .whl | head -1)
209- if [[ -z " ${PIP_WHL} " ]]; then
210- die " ERROR: Cannot locate the locally-built pip whl file"
211- fi
212- echo " Locally-built PIP whl file is at: ${PIP_WHL} "
213-
214- # Copy the pip file to tmp directory
215- cp " ${PIP_WHL} " " ${TMP_DIR} /" || \
216- die " ERROR: Failed to copy wheel file: ${PIP_WHL} "
217-
218- # Use string replacement to put the correct file name into the Dockerfile
219- PIP_WHL=$( basename " ${PIP_WHL} " )
220-
221- # Modify the non-devel Dockerfile to point to the correct pip whl file
222- # location
223- sed -e " /# --- DO NOT EDIT OR DELETE BETWEEN THE LINES --- #/," \
177+ if [[ -z " ${TF_DOCKER_BUILD_CENTRAL_PIP} " ]]; then
178+ # Perform local build of the required PIP whl file
179+ export TF_BUILD_CONTAINER_TYPE=${TF_DOCKER_BUILD_TYPE}
180+ export TF_BUILD_PYTHON_VERSION=${TF_DOCKER_BUILD_PYTHON_VERSION}
181+ export TF_BUILD_OPTIONS=${TF_DOCKER_BUILD_OPTIONS}
182+ export TF_BUILD_IS_PIP=" PIP"
183+
184+ if [[ " ${TF_DOCKER_BUILD_TYPE} " == " gpu" ]]; then
185+ export TF_BUILD_APPEND_CI_DOCKER_EXTRA_PARAMS=\
186+ " ${TF_BUILD_APPEND_CI_DOCKER_EXTRA_PARAMS} -e TF_CUDA_COMPUTE_CAPABILITIES=3.0,3.5,5.2"
187+ fi
188+
189+ pushd " ${SCRIPT_DIR} /../../../"
190+ rm -rf pip_test/whl &&
191+ tensorflow/tools/ci_build/ci_parameterized_build.sh
192+ PIP_BUILD_EXIT_CODE=$?
193+ popd
194+
195+ # Was the pip build successful?
196+ if [[ ${PIP_BUILD_EXIT_CODE} != " 0" ]]; then
197+ die " FAIL: Failed to build pip file locally"
198+ fi
199+
200+ PIP_WHL=$( ls pip_test/whl/* .whl | head -1)
201+ if [[ -z " ${PIP_WHL} " ]]; then
202+ die " ERROR: Cannot locate the locally-built pip whl file"
203+ fi
204+ echo " Locally-built PIP whl file is at: ${PIP_WHL} "
205+
206+ # Copy the pip file to tmp directory
207+ cp " ${PIP_WHL} " " ${TMP_DIR} /" || \
208+ die " ERROR: Failed to copy wheel file: ${PIP_WHL} "
209+
210+ # Use string replacement to put the correct file name into the Dockerfile
211+ PIP_WHL=$( basename " ${PIP_WHL} " )
212+
213+ # Modify the non-devel Dockerfile to point to the correct pip whl file
214+ # location
215+ sed -e " /# --- DO NOT EDIT OR DELETE BETWEEN THE LINES --- #/," \
224216" /# --- ~ DO NOT EDIT OR DELETE BETWEEN THE LINES --- #/c" \
225217" COPY ${PIP_WHL} /\n" \
226218" RUN pip --no-cache-dir install /${PIP_WHL} " " ${ORIG_DOCKERFILE} " \
227219 > " ${DOCKERFILE} "
220+ else
221+ echo " Downloading pip wheel from: ${TF_DOCKER_BUILD_CENTRAL_PIP} "
222+ echo
223+
224+ # Modify the non-devel Dockerfile to point to the correct pip whl URL.
225+ sed -e " /# --- DO NOT EDIT OR DELETE BETWEEN THE LINES --- #/," \
226+ " /# --- ~ DO NOT EDIT OR DELETE BETWEEN THE LINES --- #/c" \
227+ " RUN pip --no-cache-dir install ${TF_DOCKER_BUILD_CENTRAL_PIP} " " ${ORIG_DOCKERFILE} " \
228+ > " ${DOCKERFILE} "
229+ fi
228230
229231 echo " Modified Dockerfile at: ${DOCKERFILE} "
232+ echo
233+
234+ # Modify python/pip version if necessary.
235+ if [[ " ${TF_DOCKER_BUILD_PYTHON_VERSION} " == " python3" ]]; then
236+ sed -i -e ' s/python /python3 /g' " ${DOCKERFILE} " && \
237+ sed -i -e ' s/python-dev/python3-dev/g' " ${DOCKERFILE} " && \
238+ sed -i -e ' s/pip /pip3 /g' " ${DOCKERFILE} " && \
239+ sed -i -e ' s^# RUN ln -s /usr/bin/python3 /usr/bin/python#^RUN ln -s /usr/bin/python3 /usr/bin/python^' " ${DOCKERFILE} " && \
240+ echo " Modified Dockerfile for python version " \
241+ " ${TF_DOCKER_BUILD_PYTHON_VERSION} at: ${DOCKERFILE} " || \
242+ die " FAILED to modify ${DOCKERFILE} for python3"
243+ fi
230244else
231- if [[ " ${TF_DOCKER_BUILD_IS_DEVEL} " == " yes" ]]; then
232- DOCKERFILE=" ${TMP_DIR} /Dockerfile"
245+ DOCKERFILE=" ${TMP_DIR} /Dockerfile"
233246
234- # Modify the devel Dockerfile to specify the git branch
235- sed -r " s/([\s]*git checkout )(.*)/\1${TF_DOCKER_BUILD_DEVEL_BRANCH} /g" \
236- " ${ORIG_DOCKERFILE} " > " ${DOCKERFILE} "
237- else
238- DOCKERFILE=" ${TMP_DIR} /" $( basename " ${ORIG_DOCKERFILE} " )
247+ # Modify the devel Dockerfile to specify the git branch
248+ sed -r " s/([\s]*git checkout )(.*)/\1${TF_DOCKER_BUILD_DEVEL_BRANCH} /g" \
249+ " ${ORIG_DOCKERFILE} " > " ${DOCKERFILE} "
250+
251+ # Modify python/pip version if necessary.
252+ if [[ " ${TF_DOCKER_BUILD_PYTHON_VERSION} " == " python3" ]]; then
253+ sed -i -e ' s/python-dev/python-dev python3-dev/g' " ${DOCKERFILE} " && \
254+ sed -i -e ' s/python /python3 /g' " ${DOCKERFILE} " && \
255+ sed -i -e ' s^/tmp/pip^/tmp/pip3^g' " ${DOCKERFILE} " && \
256+ sed -i -e ' s/pip /pip3 /g' " ${DOCKERFILE} " && \
257+ sed -i -e ' s/ENV CI_BUILD_PYTHON python/ENV CI_BUILD_PYTHON python3/g' " ${DOCKERFILE} " && \
258+ sed -i -e ' s^# RUN ln -s /usr/bin/python3 /usr/bin/python#^RUN ln -s /usr/bin/python3 /usr/bin/python^' " ${DOCKERFILE} " && \
259+ echo " Modified Dockerfile further for python version ${TF_DOCKER_BUILD_PYTHON_VERSION} at: ${DOCKERFILE} " || \
260+ die " FAILED to modify ${DOCKERFILE} for python3"
239261 fi
240262fi
241263
242-
243264# Perform docker build
244265# Intermediate image name with tag
245266IMG=" ${USER} /tensorflow:${FINAL_TAG} "
0 commit comments