Skip to content

Commit

Permalink
Refactor tensorflow in Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
madelen-at-work committed Sep 9, 2024
1 parent 7efbb45 commit 1124a79
Showing 1 changed file with 34 additions and 10 deletions.
44 changes: 34 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ FROM arm64v8/ubuntu:${UBUNTU_VERSION} AS containerized_aarch64
FROM arm32v7/ubuntu:${UBUNTU_VERSION} AS containerized_armv7hf

FROM ${REPO}/acap-native-sdk:${VERSION}-${ARCH}-ubuntu${UBUNTU_VERSION} AS acap-native-sdk
FROM acap-native-sdk AS build

FROM acap-native-sdk AS build_base

ARG ARCH
ARG TARGETSYSROOT=/opt/axis/acapsdk/sysroots/${ARCH}
Expand All @@ -19,6 +20,7 @@ WORKDIR ${TARGETSYSROOT}/usr/lib
RUN [ -z "$(ls libabsl*.so*)" ] || rm -f libabsl*.so*

# Install openssl (to use instead of boringssl)
# hadolint ignore=DL3009
RUN <<EOF
apt-get update
apt-get install -y --no-install-recommends \
Expand All @@ -30,6 +32,18 @@ apt-get install -y --no-install-recommends \
openssl
EOF

FROM build_base AS tensorflow

WORKDIR /opt

# Get TensorFlow and TensorFlow Serving - doing this in parallel saves a little bit of time
RUN <<EOF
git clone -b r2.9 https://github.com/tensorflow/tensorflow.git /opt/tensorflow/tensorflow
git clone -b r2.9 https://github.com/tensorflow/serving.git /opt/tensorflow/serving
EOF

FROM build_base AS testdata

# Install Edge TPU compiler
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN <<EOF
Expand Down Expand Up @@ -77,6 +91,11 @@ RUN <<EOF
rm -rf tmp
EOF

FROM build_base AS build_grpc

ARG ARCH
ARG TARGETSYSROOT=/opt/axis/acapsdk/sysroots/${ARCH}

# Switch to build directory
WORKDIR /opt

Expand Down Expand Up @@ -108,6 +127,11 @@ RUN <<EOF
make -j4 install
EOF

FROM build_grpc AS build_grpc_arm

ARG ARCH
ARG TARGETSYSROOT=/opt/axis/acapsdk/sysroots/${ARCH}

# return to build dir
WORKDIR /opt
# Build for ARM
Expand Down Expand Up @@ -151,11 +175,14 @@ RUN <<EOF
"$SDKTARGETSYSROOT"/usr/include
EOF

# Get TensorFlow and TensorFlow Serving
RUN <<EOF
git clone -b r2.9 https://github.com/tensorflow/tensorflow.git /opt/tensorflow/tensorflow
git clone -b r2.9 https://github.com/tensorflow/serving.git /opt/tensorflow/serving
EOF
FROM build_grpc_arm AS build

ARG TEST
ARG DEBUG

# Get TensorFlow, TensorFlow Serving and testdata that we pulled in paralell
COPY --from=tensorflow /opt/tensorflow /opt/tensorflow
COPY --from=testdata /opt/app/testdata /opt/app/testdata

## Setup build structure
WORKDIR /opt/app
Expand All @@ -172,10 +199,7 @@ RUN patch /opt/app/apis/tensorflow_serving/apis/predict.proto /opt/app/apis/pred

# Building the ACAP application

ARG TEST
ARG DEBUG

# hadolint ignore=SC2155
# hadolint ignore=SC2046,SC2155
RUN <<EOF
export MANIFEST="manifest-$ARCH.json";
export EXTRA_FLAGS=$([ "$ARCH" = "aarch64" ] && echo "-D__arm64__" || echo "");
Expand Down

0 comments on commit 1124a79

Please sign in to comment.