Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolve issue #176 #177

Closed
wants to merge 11 commits into from
58 changes: 58 additions & 0 deletions tensorflow_runtime_dockerfiles/build_images.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash

#
# build the CPU images
#
docker build --target=jupyter \
--build-arg TENSORFLOW_PACKAGE=tf-nightly-cpu \
--build-arg TENSORFLOW_USER=tf \
--build-arg TENSORFLOW_GROUP=tfuser \
--build-arg TENSORFLOW_UID=2024 \
--build-arg TENSORFLOW_GID=2024 \
-t tensorflow-nightly-cpu -f cpu.Dockerfile .

docker build --target=test \
--build-arg TENSORFLOW_PACKAGE=tf-nightly-cpu \
--build-arg TENSORFLOW_USER=tf \
--build-arg TENSORFLOW_GROUP=tfuser \
--build-arg TENSORFLOW_UID=2024 \
--build-arg TENSORFLOW_GID=2024 \
-t tensorflow-nightly-cpu-test -f cpu.Dockerfile .

#
# build the GPU images
#
docker build --target=jupyter \
--build-arg TENSORFLOW_PACKAGE=tf-nightly-gpu \
--build-arg TENSORFLOW_USER=tf \
--build-arg TENSORFLOW_GROUP=tfuser \
--build-arg TENSORFLOW_UID=2024 \
--build-arg TENSORFLOW_GID=2024 \
-t tensorflow-nightly-gpu -f gpu.Dockerfile .

docker build --target=test \
--build-arg TENSORFLOW_PACKAGE=tf-nightly-gpu \
--build-arg TENSORFLOW_USER=tf \
--build-arg TENSORFLOW_GROUP=tfuser \
--build-arg TENSORFLOW_UID=2024 \
--build-arg TENSORFLOW_GID=2024 \
-t tensorflow-nightly-gpu-test -f cpu.Dockerfile .

#
# build the TPU images
#
docker build --target=jupyter \
--build-arg TENSORFLOW_PACKAGE=tf-nightly-tpu \
--build-arg TENSORFLOW_USER=tf \
--build-arg TENSORFLOW_GROUP=tfuser \
--build-arg TENSORFLOW_UID=2024 \
--build-arg TENSORFLOW_GID=2024 \
-t tensorflow-nightly-tpu -f cpu.Dockerfile .

docker build --target=test \
--build-arg TENSORFLOW_PACKAGE=tf-nightly-tpu \
--build-arg TENSORFLOW_USER=tf \
--build-arg TENSORFLOW_GROUP=tfuser \
--build-arg TENSORFLOW_UID=2024 \
--build-arg TENSORFLOW_GID=2024 \
-t tensorflow-nightly-tpu-test -f cpu.Dockerfile .
44 changes: 36 additions & 8 deletions tensorflow_runtime_dockerfiles/cpu.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,62 @@ ENV LANG C.UTF-8
COPY setup.sources.sh /setup.sources.sh
COPY setup.packages.sh /setup.packages.sh
COPY cpu.packages.txt /cpu.packages.txt
# set up apt sources (must be done as root):
RUN /setup.sources.sh
# install required packages (must be done as root):
RUN /setup.packages.sh /cpu.packages.txt


ARG PYTHON_VERSION=python3.11
ARG TENSORFLOW_PACKAGE=tf-nightly
ARG TENSORFLOW_USER=tfuser
ARG TENSORFLOW_GROUP=tensorflow
ARG TENSORFLOW_UID=2234
ARG TENSORFLOW_GID=5567
ARG TENSORFLOW_NOTEBOOK_DIR=/home/${TENSORFLOW_USER}/notebooks
ENV TENSORFLOW_USER=${TENSORFLOW_USER}
ENV TENSORFLOW_GROUP=${TENSORFLOW_GROUP}
ENV TENSORFLOW_UID=${TENSORFLOW_UID}
ENV TENSORFLOW_GID=${TENSORFLOW_GID}
ENV TENSORFLOW_NOTEBOOK_DIR=${TENSORFLOW_NOTEBOOK_DIR}
COPY setup.python.sh /setup.python.sh
COPY cpu.requirements.txt /cpu.requirements.txt
# install python (must be done as root):
RUN /setup.python.sh $PYTHON_VERSION /cpu.requirements.txt
RUN pip install --no-cache-dir ${TENSORFLOW_PACKAGE}

COPY bashrc /etc/bash.bashrc
RUN chmod a+rwx /etc/bash.bashrc
# create and setup user ${TENSORFLOW_USER}:${TENSORFLOW_GROUP} (must be done as root):
COPY setup.tensorflow.user.sh /setup.tensorflow.user.sh
RUN /setup.tensorflow.user.sh && \
mkdir -p /home/${TENSORFLOW_USER}/.local && \
chown -R ${TENSORFLOW_USER}:${TENSORFLOW_GROUP} /home/${TENSORFLOW_USER}/.local
ENV PATH="${PATH}:/home/${TENSORFLOW_USER}/.local/bin"

# the rest of the commands is run by TENSORFLOW_USER
USER ${TENSORFLOW_USER}

RUN pip install --no-cache-dir ${TENSORFLOW_PACKAGE}


FROM base as jupyter

COPY jupyter.requirements.txt /jupyter.requirements.txt
COPY setup.jupyter.sh /setup.jupyter.sh
USER ${TENSORFLOW_USER}
# install and setup jupyter (should be done as TENSORFLOW_USER):
COPY --chown=${TENSORFLOW_USER}:${TENSORFLOW_GROUP} jupyter.requirements.txt /jupyter.requirements.txt
COPY --chown=${TENSORFLOW_USER}:${TENSORFLOW_GROUP} setup.jupyter.sh /setup.jupyter.sh
RUN python3 -m pip install --no-cache-dir -r /jupyter.requirements.txt -U
RUN /setup.jupyter.sh
COPY jupyter.readme.md /tf/tensorflow-tutorials/README.md
COPY --chown=${TENSORFLOW_USER}:${TENSORFLOW_GROUP} jupyter.readme.md ${TENSORFLOW_NOTEBOOK_DIR}/tensorflow-tutorials/README.md



WORKDIR /tf
WORKDIR ${TENSORFLOW_NOTEBOOK_DIR}
EXPOSE 8888

CMD ["bash", "-c", "source /etc/bash.bashrc && jupyter notebook --notebook-dir=/tf --ip 0.0.0.0 --no-browser --allow-root"]
# finally start jupyter (this should be done as TENSORFLOW_USER):
CMD ["bash", "-c", "source /etc/bash.bashrc && jupyter notebook --notebook-dir=${TENSORFLOW_NOTEBOOK_DIR} --ip 0.0.0.0 --no-browser --allow-root"]

FROM base as test

COPY test.import_cpu.sh /test.import_cpu.sh
COPY --chown=${TENSORFLOW_USER}:${TENSORFLOW_GROUP} test.import_cpu.sh /test.import_cpu.sh
RUN /test.import_cpu.sh
44 changes: 38 additions & 6 deletions tensorflow_runtime_dockerfiles/gpu.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,69 @@ ENV LANG C.UTF-8
COPY setup.sources.sh /setup.sources.sh
COPY setup.packages.sh /setup.packages.sh
COPY gpu.packages.txt /gpu.packages.txt
# set up apt sources (must be done as root):
RUN /setup.sources.sh
# install required packages (must be done as root):
RUN /setup.packages.sh /gpu.packages.txt


ARG PYTHON_VERSION=python3.11
ARG TENSORFLOW_PACKAGE=tf-nightly
ARG TENSORFLOW_USER=tfuser
ARG TENSORFLOW_GROUP=tensorflow
ARG TENSORFLOW_UID=2234
ARG TENSORFLOW_GID=5567
ARG TENSORFLOW_NOTEBOOK_DIR=/home/${TENSORFLOW_USER}/notebooks
ENV TENSORFLOW_USER=${TENSORFLOW_USER}
ENV TENSORFLOW_GROUP=${TENSORFLOW_GROUP}
ENV TENSORFLOW_UID=${TENSORFLOW_UID}
ENV TENSORFLOW_GID=${TENSORFLOW_GID}
ENV TENSORFLOW_NOTEBOOK_DIR=${TENSORFLOW_NOTEBOOK_DIR}
COPY setup.python.sh /setup.python.sh
COPY gpu.requirements.txt /gpu.requirements.txt
# install python (must be done as root):
RUN /setup.python.sh $PYTHON_VERSION /gpu.requirements.txt
RUN pip install --no-cache-dir ${TENSORFLOW_PACKAGE}

COPY setup.cuda.sh /setup.cuda.sh
RUN /setup.cuda.sh

# setup cuda (must be done as root):
COPY bashrc /etc/bash.bashrc
RUN chmod a+rwx /etc/bash.bashrc
# create and setup user ${TENSORFLOW_USER}:${TENSORFLOW_GROUP} (must be done as root):
COPY setup.tensorflow.user.sh /setup.tensorflow.user.sh
RUN /setup.tensorflow.user.sh && \
mkdir -p /home/${TENSORFLOW_USER}/.local && \
chown -R ${TENSORFLOW_USER}:${TENSORFLOW_GROUP} /home/${TENSORFLOW_USER}/.local
ENV PATH="${PATH}:/home/${TENSORFLOW_USER}/.local/bin"

# the rest of the commands is run by TENSORFLOW_USER
USER ${TENSORFLOW_USER}

RUN pip install --no-cache-dir ${TENSORFLOW_PACKAGE}


FROM base as jupyter

COPY jupyter.requirements.txt /jupyter.requirements.txt
COPY setup.jupyter.sh /setup.jupyter.sh
USER ${TENSORFLOW_USER}
# install and setup jupyter (should be done as TENSORFLOW_USER):
COPY --chown=${TENSORFLOW_USER}:${TENSORFLOW_GROUP} jupyter.requirements.txt /jupyter.requirements.txt
COPY --chown=${TENSORFLOW_USER}:${TENSORFLOW_GROUP} setup.jupyter.sh /setup.jupyter.sh
RUN python3 -m pip install --no-cache-dir -r /jupyter.requirements.txt -U
RUN /setup.jupyter.sh
COPY jupyter.readme.md /tf/tensorflow-tutorials/README.md
COPY --chown=${TENSORFLOW_USER}:${TENSORFLOW_GROUP} jupyter.readme.md ${TENSORFLOW_NOTEBOOK_DIR}/tensorflow-tutorials/README.md



WORKDIR /tf
WORKDIR ${TENSORFLOW_NOTEBOOK_DIR}
EXPOSE 8888

CMD ["bash", "-c", "source /etc/bash.bashrc && jupyter notebook --notebook-dir=/tf --ip 0.0.0.0 --no-browser --allow-root"]
# finally start jupyter (this should be done as TENSORFLOW_USER):
CMD ["bash", "-c", "source /etc/bash.bashrc && jupyter notebook --notebook-dir=${TENSORFLOW_NOTEBOOK_DIR} --ip 0.0.0.0 --no-browser --allow-root"]

FROM base as test

ENV LD_LIBRARY_PATH /usr/local/cuda/lib64/stubs/:$LD_LIBRARY_PATH
COPY test.import_cpu.sh /test.import_cpu.sh
COPY --chown=${TENSORFLOW_USER}:${TENSORFLOW_GROUP} test.import_cpu.sh /test.import_cpu.sh
RUN /test.import_cpu.sh
16 changes: 6 additions & 10 deletions tensorflow_runtime_dockerfiles/setup.jupyter.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
#!/bin/bash
jupyter serverextension enable --py jupyter_http_over_ws

mkdir -p /tf/tensorflow-tutorials
chmod -R a+rwx /tf/
mkdir /.local
chmod a+rwx /.local
apt-get update
apt-get install -y --no-install-recommends wget git
cd /tf/tensorflow-tutorials
TENSORFLOW_TUTORIALS="${TENSORFLOW_NOTEBOOK_DIR}/tensorflow-tutorials"
mkdir -p -v ${TENSORFLOW_TUTORIALS}

cd ${TENSORFLOW_TUTORIALS}
wget https://raw.githubusercontent.com/tensorflow/docs/master/site/en/tutorials/keras/classification.ipynb
wget https://raw.githubusercontent.com/tensorflow/docs/master/site/en/tutorials/keras/overfit_and_underfit.ipynb
wget https://raw.githubusercontent.com/tensorflow/docs/master/site/en/tutorials/keras/regression.ipynb
wget https://raw.githubusercontent.com/tensorflow/docs/master/site/en/tutorials/keras/save_and_load.ipynb
wget https://raw.githubusercontent.com/tensorflow/docs/master/site/en/tutorials/keras/text_classification.ipynb
wget https://raw.githubusercontent.com/tensorflow/docs/master/site/en/tutorials/keras/text_classification_with_hub.ipynb

apt-get autoremove -y
apt-get remove -y wget

python3 -m ipykernel.kernelspec
python3 -m ipykernel install --user
python3 -m ipykernel.kernelspec --user
1 change: 1 addition & 0 deletions tensorflow_runtime_dockerfiles/setup.packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ set -e
export DEBIAN_FRONTEND=noninteractive

apt-get update
apt-get install -y --no-install-recommends wget git

# Remove commented lines and blank lines from the package list
apt-get install -y --no-install-recommends $(sed -e '/^\s*#.*$/d' -e '/^\s*$/d' "$1" | sort -u)
Expand Down
25 changes: 25 additions & 0 deletions tensorflow_runtime_dockerfiles/setup.tensorflow.user.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
#
# Copyright 2022 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
#
# setup.tensorflow.user.sh: create an user account used to run tensorflow
# Usage: set envrionment variables TENSORFLOW_USER, TENSORFLOW_GROUP, TENSORFLOW_UID, TENSORFLOW_GID and run script setup.tensorflow.user.sh
#

echo "creating group ${TENSORFLOW_GROUP} with gid ${TENSORFLOW_GID} ..." && \
groupadd --system --gid ${TENSORFLOW_GID} ${TENSORFLOW_GROUP} && \
echo "creating user ${TENSORFLOW_USER}:${TENSORFLOW_GROUP} (${TENSORFLOW_UID}:${TENSORFLOW_GID}) ..." && \
useradd --system --uid ${TENSORFLOW_UID} --home-dir=/home/${TENSORFLOW_USER} --create-home --gid ${TENSORFLOW_GID} ${TENSORFLOW_USER}
42 changes: 34 additions & 8 deletions tensorflow_runtime_dockerfiles/tpu.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,60 @@ ENV LANG C.UTF-8
COPY setup.sources.sh /setup.sources.sh
COPY setup.packages.sh /setup.packages.sh
COPY tpu.packages.txt /tpu.packages.txt
# set up apt sources (must be done as root):
RUN /setup.sources.sh
# install required packages (must be done as root):
RUN /setup.packages.sh /tpu.packages.txt


ARG PYTHON_VERSION=python3.11
ARG TENSORFLOW_PACKAGE=tf-nightly-tpu
ARG TENSORFLOW_USER=tfuser
ARG TENSORFLOW_GROUP=tensorflow
ARG TENSORFLOW_UID=2234
ARG TENSORFLOW_GID=5567
ARG TENSORFLOW_NOTEBOOK_DIR=/home/${TENSORFLOW_USER}/notebooks
ENV TENSORFLOW_USER=${TENSORFLOW_USER}
ENV TENSORFLOW_GROUP=${TENSORFLOW_GROUP}
ENV TENSORFLOW_UID=${TENSORFLOW_UID}
ENV TENSORFLOW_GID=${TENSORFLOW_GID}
ENV TENSORFLOW_NOTEBOOK_DIR=${TENSORFLOW_NOTEBOOK_DIR}
COPY setup.python.sh /setup.python.sh
COPY cpu.requirements.txt /tpu.requirements.txt
# install python (must be done as root):
RUN /setup.python.sh $PYTHON_VERSION /tpu.requirements.txt
RUN pip install --no-cache-dir ${TENSORFLOW_PACKAGE} -f https://storage.googleapis.com/libtpu-tf-releases/index.html

COPY bashrc /etc/bash.bashrc
RUN chmod a+rwx /etc/bash.bashrc
# create and setup user ${TENSORFLOW_USER}:${TENSORFLOW_GROUP} (must be done as root):
COPY setup.tensorflow.user.sh /setup.tensorflow.user.sh
RUN /setup.tensorflow.user.sh && \
mkdir -p /home/${TENSORFLOW_USER}/.local && \
chown -R ${TENSORFLOW_USER}:${TENSORFLOW_GROUP} /home/${TENSORFLOW_USER}/.local
ENV PATH="${PATH}:/home/${TENSORFLOW_USER}/.local/bin"

# the rest of the commands is run by TENSORFLOW_USER
USER ${TENSORFLOW_USER}

RUN pip install --no-cache-dir ${TENSORFLOW_PACKAGE} -f https://storage.googleapis.com/libtpu-tf-releases/index.html

FROM base as jupyter

COPY jupyter.requirements.txt /jupyter.requirements.txt
COPY setup.jupyter.sh /setup.jupyter.sh
USER ${TENSORFLOW_USER}
# install and setup jupyter (should be done as TENSORFLOW_USER):
COPY --chown=${TENSORFLOW_USER}:${TENSORFLOW_GROUP} jupyter.requirements.txt /jupyter.requirements.txt
COPY --chown=${TENSORFLOW_USER}:${TENSORFLOW_GROUP} setup.jupyter.sh /setup.jupyter.sh
RUN python3 -m pip install --no-cache-dir -r /jupyter.requirements.txt -U
RUN /setup.jupyter.sh
COPY jupyter.readme.md /tf/tensorflow-tutorials/README.md
COPY --chown=${TENSORFLOW_USER}:${TENSORFLOW_GROUP} jupyter.readme.md ${TENSORFLOW_NOTEBOOK_DIR}/tensorflow-tutorials/README.md



WORKDIR /tf
WORKDIR ${TENSORFLOW_NOTEBOOK_DIR}
EXPOSE 8888

CMD ["bash", "-c", "source /etc/bash.bashrc && jupyter notebook --notebook-dir=/tf --ip 0.0.0.0 --no-browser --allow-root"]
CMD ["bash", "-c", "source /etc/bash.bashrc && jupyter notebook --notebook-dir=${TENSORFLOW_NOTEBOOK_DIR} --ip 0.0.0.0 --no-browser --allow-root"]

FROM base as test

COPY test.import_tpu.sh /test.import_tpu.sh
COPY --chown=${TENSORFLOW_USER}:${TENSORFLOW_GROUP} test.import_tpu.sh /test.import_tpu.sh
RUN /test.import_tpu.sh