-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile.bases
111 lines (104 loc) · 4.04 KB
/
Dockerfile.bases
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# syntax=docker.io/docker/dockerfile:1.2@sha256:e2a8561e419ab1ba6b2fe6cbdf49fd92b95912df1cf7d313c3e2230a333fdbcc
# DOCKER_BUILDKIT=1 docker build --target=hello_world_cpu -o=bin/ .
# GLOG_logtostderr=1 ./hello_world_cpu
FROM --platform=$BUILDPLATFORM docker.io/library/alpine@sha256:234cb88d3020898631af0ccbbcca9a66ae7306ecd30c9720690858c1b007d2a0 AS mediapipe-src-builder
WORKDIR /w
ARG MEDIAPIPE_COMMIT
RUN set -ux \
&& apk update \
&& apk add git \
&& git init \
&& git remote add origin https://github.com/google/mediapipe \
&& git fetch --depth 1 origin $MEDIAPIPE_COMMIT \
&& git checkout FETCH_HEAD
FROM scratch AS mediapipe-src
COPY --from=mediapipe-src-builder /w /
###FROM ubuntu:20.04 AS base-cpu
FROM --platform=$BUILDPLATFORM docker.io/library/ubuntu:18.04@sha256:139b3846cee2e63de9ced83cee7023a2d95763ee2573e5b0ab6dea9dfbd4db8f AS base-cpu
WORKDIR /mediapipe
ENV DEBIAN_FRONTEND=noninteractive
RUN set -ux \
&& apt update \
&& apt install -y --no-install-recommends \
build-essential \
gcc-8 g++-8 \
ca-certificates \
curl \
ffmpeg \
git \
wget \
unzip \
python3-dev \
python3-opencv \
python3-pip \
libopencv-core-dev \
libopencv-highgui-dev \
libopencv-imgproc-dev \
libopencv-video-dev \
libopencv-calib3d-dev \
libopencv-features2d-dev \
software-properties-common \
&& add-apt-repository -y ppa:openjdk-r/ppa \
&& apt update \
&& apt install -y openjdk-8-jdk
RUN set -ux \
&& update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 800 --slave /usr/bin/g++ g++ /usr/bin/g++-8 \
&& update-alternatives --install /usr/bin/python python /usr/bin/python3 1
RUN set -ux \
&& pip3 install --upgrade setuptools \
&& pip3 install wheel \
&& pip3 install future \
&& pip3 install six==1.14.0
# && pip3 install tensorflow==1.14.0 \
# && pip3 install tf_slim
ARG BAZEL_VERSION=3.7.2
RUN set -ux \
&& mkdir /bazel \
&& wget --no-check-certificate -O /bazel/installer.sh "https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-installer-linux-x86_64.sh" \
&& wget --no-check-certificate -O /bazel/LICENSE.txt "https://raw.githubusercontent.com/bazelbuild/bazel/master/LICENSE" \
&& chmod +x /bazel/installer.sh \
&& /bazel/installer.sh \
&& rm /bazel/installer.sh
#full static
# https://github.com/bazelbuild/bazel/issues/8672#issuecomment-505064783
# https://github.com/bazelbuild/bazel/issues/8672#issuecomment-507634776
# https://blog.jessfraz.com/post/top-10-favorite-ldflags/
# --unresolved-symbols=ignore-all
RUN set -ux \
&& echo ' --platform_suffix=-cpu' >/bazelflags
COPY --from=mediapipe-src / /mediapipe/
### RUN set -ux \
### # # Fix for OpenCV v4
### # && sed -i 's%#include <opencv2/optflow.hpp>%#include <opencv2/video/tracking.hpp>%' mediapipe/framework/port/opencv_video_inc.h \
### # Use OpenCV v4
### && sed -i 's%# "include/%"include/%g' third_party/opencv_linux.BUILD
RUN \
--mount=type=cache,target=/root/.cache/bazel \
set -ux \
&& bazel build $(cat /bazelflags) \
-c opt \
--define MEDIAPIPE_DISABLE_GPU=1 \
mediapipe/examples/desktop/hello_world:hello_world \
&& mkdir /x \
&& cp ./bazel-bin/mediapipe/examples/desktop/hello_world/hello_world /x/hello_world_cpu
FROM scratch AS hello_world_cpu
COPY --from=base-cpu /x/hello_world_cpu /
FROM base-cpu AS base-gpu
RUN set -ux \
&& apt install -y --no-install-recommends \
mesa-common-dev \
libegl1-mesa-dev \
libgles2-mesa-dev \
mesa-utils
RUN set -ux \
&& echo ' --platform_suffix=-gpu' >/bazelflags
RUN \
--mount=type=cache,target=/root/.cache/bazel \
set -ux \
&& bazel build $(cat /bazelflags) \
-c opt \
--copt -DMESA_EGL_NO_X11_HEADERS --copt -DEGL_NO_X11 \
mediapipe/examples/desktop/hello_world:hello_world \
&& cp ./bazel-bin/mediapipe/examples/desktop/hello_world/hello_world /x/hello_world_gpu
FROM scratch AS hello_world_gpu
COPY --from=base-gpu /x/hello_world_gpu /