Repository navigation
Expand file tree
/
Copy pathDockerfile_mediapipe
More file actions
171 lines (146 loc) · 5.61 KB
/
Copy pathDockerfile_mediapipe
File metadata and controls
171 lines (146 loc) · 5.61 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# Copyright 2019 The MediaPipe Authors.
#
# 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.
FROM ubuntu:22.04
# Setting up workspaces
WORKDIR /io
WORKDIR /mediapipe
# Setting noninteractive installation
ENV DEBIAN_FRONTEND=noninteractive
# Setting pip defaults for faster, cleaner installs
ENV PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1
# Adding apt retry defaults for transient mirror/index inconsistencies
RUN printf 'Acquire::Retries "5";\nAcquire::http::No-Cache "true";\nAcquire::https::No-Cache "true";\n' > /etc/apt/apt.conf.d/99retries
# Installing dependencies
RUN set -eux; \
for attempt in 1 2 3 4 5; do \
rm -rf /var/lib/apt/lists/*; \
if apt-get update; then \
break; \
fi; \
if [ "${attempt}" -eq 5 ]; then \
echo "apt-get update failed after ${attempt} attempts" >&2; \
exit 1; \
fi; \
echo "Retrying apt-get update after transient failure (attempt ${attempt})" >&2; \
sleep $((attempt * 5)); \
done; \
apt-get install -y --no-install-recommends \
build-essential \
ca-certificates \
curl \
ffmpeg \
git \
wget \
unzip \
nodejs \
npm \
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 \
openjdk-21-jdk \
mesa-common-dev \
libegl1-mesa-dev \
libgles2-mesa-dev \
mesa-utils; \
apt-get clean; \
rm -rf /var/lib/apt/lists/*
# Install Clang 16
RUN wget -q https://apt.llvm.org/llvm.sh && \
chmod +x llvm.sh && \
./llvm.sh 16 && \
ln -sf /usr/bin/clang-16 /usr/bin/clang && \
ln -sf /usr/bin/clang++-16 /usr/bin/clang++ && \
ln -sf /usr/bin/clang-format-16 /usr/bin/clang-format && \
rm -f llvm.sh
# Installing Python packages (system Python 3.x)
RUN pip3 install --upgrade "pip<25" && \
pip3 install "setuptools<71" "setuptools-scm<8" wheel && \
pip3 install "numpy==1.26.4" && \
pip3 install --only-binary=:all: "opencv-contrib-python==4.10.0.84" && \
pip3 install protobuf==3.20.1 six==1.14.0 && \
pip3 install future absl-py "numpy<2" && \
pip3 install "jax[cpu]" && \
pip3 install tensorflow tf_slim && \
pip3 install jupyter notebook && \
pip3 install mediapipe-model-maker && \
pip3 install ultralytics && \
pip3 install --use-pep517 "seqeval==1.2.2"
# Ensure python symlink points to system python3 (3.10 on Ubuntu 22.04)
RUN ln -sf /usr/bin/python3 /usr/bin/python
# Installing bazel
ARG BAZEL_VERSION=7.4.1
RUN mkdir /bazel && \
wget --no-check-certificate -O /bazel/installer.sh "https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/b\
azel-${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 -f /bazel/installer.sh
# Setting up bazelrc
COPY . /mediapipe/
# Setting up the working directory
WORKDIR /workspace/project
# Setting up password-protected Jupyter entrypoint
RUN cat <<'EOF' > /usr/local/bin/start-jupyter.sh
#!/bin/bash
set -euo pipefail
if [ -z "${JUPYTER_PASSWORD:-}" ]; then
echo "JUPYTER_PASSWORD environment variable is not set." >&2
exit 1
fi
python3 <<'PY'
import os
try:
from jupyter_server.auth import passwd
except ImportError:
from notebook.auth import passwd
password = os.environ.get("JUPYTER_PASSWORD")
if not password:
raise SystemExit("JUPYTER_PASSWORD environment variable is not set.")
hashed = passwd(password)
config_dir = os.path.expanduser("~/.jupyter")
os.makedirs(config_dir, exist_ok=True)
notebook_path = os.path.join(config_dir, "jupyter_notebook_config.py")
server_path = os.path.join(config_dir, "jupyter_server_config.py")
content = (
"c = get_config()\n"
f"c.NotebookApp.password = u'{hashed}'\n"
"c.NotebookApp.password_required = True\n"
"c.NotebookApp.token = ''\n"
)
with open(notebook_path, "w", encoding="utf-8") as notebook_file:
notebook_file.write(content)
server_content = (
"c = get_config()\n"
f"c.ServerApp.password = u'{hashed}'\n"
"c.ServerApp.password_required = True\n"
"c.ServerApp.token = ''\n"
)
with open(server_path, "w", encoding="utf-8") as server_file:
server_file.write(server_content)
PY
exec jupyter notebook --ip=0.0.0.0 --no-browser --port=8888 --allow-root
EOF
# Setting permissions of the entrypoint script
RUN chmod +x /usr/local/bin/start-jupyter.sh
# Hosting the Jupyter server on the default port
ENTRYPOINT ["/usr/local/bin/start-jupyter.sh"]