Skip to content

Commit 35331d6

Browse files
Refactor tensorflow in Dockerfile (#100)
1 parent 7efbb45 commit 35331d6

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

Dockerfile

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ FROM arm64v8/ubuntu:${UBUNTU_VERSION} AS containerized_aarch64
99
FROM arm32v7/ubuntu:${UBUNTU_VERSION} AS containerized_armv7hf
1010

1111
FROM ${REPO}/acap-native-sdk:${VERSION}-${ARCH}-ubuntu${UBUNTU_VERSION} AS acap-native-sdk
12-
FROM acap-native-sdk AS build
12+
13+
FROM acap-native-sdk AS build_base
1314

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

2122
# Install openssl (to use instead of boringssl)
23+
# hadolint ignore=DL3009
2224
RUN <<EOF
2325
apt-get update
2426
apt-get install -y --no-install-recommends \
@@ -30,6 +32,18 @@ apt-get install -y --no-install-recommends \
3032
openssl
3133
EOF
3234

35+
FROM build_base AS tensorflow
36+
37+
WORKDIR /opt
38+
39+
# Get TensorFlow and TensorFlow Serving - doing this in parallel saves a little bit of time
40+
RUN <<EOF
41+
git clone -b r2.9 https://github.com/tensorflow/tensorflow.git /opt/tensorflow/tensorflow
42+
git clone -b r2.9 https://github.com/tensorflow/serving.git /opt/tensorflow/serving
43+
EOF
44+
45+
FROM build_base AS testdata
46+
3347
# Install Edge TPU compiler
3448
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
3549
RUN <<EOF
@@ -77,6 +91,11 @@ RUN <<EOF
7791
rm -rf tmp
7892
EOF
7993

94+
FROM build_base AS build_grpc
95+
96+
ARG ARCH
97+
ARG TARGETSYSROOT=/opt/axis/acapsdk/sysroots/${ARCH}
98+
8099
# Switch to build directory
81100
WORKDIR /opt
82101

@@ -108,6 +127,11 @@ RUN <<EOF
108127
make -j4 install
109128
EOF
110129

130+
FROM build_grpc AS build_grpc_arm
131+
132+
ARG ARCH
133+
ARG TARGETSYSROOT=/opt/axis/acapsdk/sysroots/${ARCH}
134+
111135
# return to build dir
112136
WORKDIR /opt
113137
# Build for ARM
@@ -151,11 +175,14 @@ RUN <<EOF
151175
"$SDKTARGETSYSROOT"/usr/include
152176
EOF
153177

154-
# Get TensorFlow and TensorFlow Serving
155-
RUN <<EOF
156-
git clone -b r2.9 https://github.com/tensorflow/tensorflow.git /opt/tensorflow/tensorflow
157-
git clone -b r2.9 https://github.com/tensorflow/serving.git /opt/tensorflow/serving
158-
EOF
178+
FROM build_grpc_arm AS build
179+
180+
ARG TEST
181+
ARG DEBUG
182+
183+
# Get TensorFlow, TensorFlow Serving and testdata that we pulled in paralell
184+
COPY --from=tensorflow /opt/tensorflow /opt/tensorflow
185+
COPY --from=testdata /opt/app/testdata /opt/app/testdata
159186

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

173200
# Building the ACAP application
174201

175-
ARG TEST
176-
ARG DEBUG
177-
178-
# hadolint ignore=SC2155
202+
# hadolint ignore=SC2046,SC2155
179203
RUN <<EOF
180204
export MANIFEST="manifest-$ARCH.json";
181205
export EXTRA_FLAGS=$([ "$ARCH" = "aarch64" ] && echo "-D__arm64__" || echo "");

0 commit comments

Comments
 (0)