Skip to content

Commit 3a3431d

Browse files
authored
[Bugfix:Autograding] CSCI4270 OpenCV Fix (#39)
The previous docker images are fine, but because OpenCV (and perhaps other libraries) spawns a lot of threads on import, we need to limit the number of threads at a time. Otherwise, executing a Jupyter notebook will fail with an ambiguous error message of "Kernel died." --------- Signed-off-by: Christopher Poon <christopherpoonc@gmail.com> Co-authored-by: Barb Cutler <Barb Cutler>
1 parent d3a3184 commit 3a3431d

File tree

2 files changed

+171
-1
lines changed

2 files changed

+171
-1
lines changed

dockerfiles/csci4270/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"pushLatest": true,
3-
"latestTag": "spring26_v2"
3+
"latestTag": "spring26_v3"
44
}
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
FROM ubuntu:22.04
2+
3+
ARG TARGETPLATFORM
4+
5+
# runtime dependencies
6+
RUN apt-get update \
7+
&& apt-get -y --no-install-recommends install \
8+
grep \
9+
libseccomp-dev \
10+
libseccomp2 \
11+
procps \
12+
ca-certificates \
13+
netbase \
14+
libgl1 \
15+
libglib2.0-0 \
16+
libsqlite3-0 \
17+
&& rm -rf /var/lib/apt/lists/*
18+
#
19+
# Source: https://github.com/docker-library/python/blob/master/3.6/stretch/slim/Dockerfile
20+
#
21+
22+
# ensure local python is preferred over distribution python
23+
ENV PATH=/usr/local/bin:$PATH
24+
25+
# http://bugs.python.org/issue19846
26+
# > At the moment, setting "LANG=C" on a Linux system *fundamentally breaks Python 3*, and that's not OK.
27+
ENV LANG=C.UTF-8
28+
ENV GPG_KEY=64E628F8D684696D
29+
ENV PYTHON_VERSION=3.11.14
30+
31+
RUN set -ex \
32+
\
33+
&& savedAptMark="$(apt-mark showmanual)" \
34+
&& apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
35+
dpkg-dev \
36+
gcc \
37+
libbz2-dev \
38+
libc6-dev \
39+
libexpat1-dev \
40+
libffi-dev \
41+
libgdbm-dev \
42+
liblzma-dev \
43+
libncursesw5-dev \
44+
libreadline-dev \
45+
libsqlite3-dev \
46+
libssl-dev \
47+
make \
48+
tk-dev \
49+
wget \
50+
xz-utils \
51+
zlib1g-dev \
52+
# as of Stretch, "gpg" is no longer included by default
53+
$(command -v gpg > /dev/null || echo 'gnupg dirmngr') \
54+
\
55+
&& wget -O python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \
56+
&& wget -O python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \
57+
&& export GNUPGHOME="$(mktemp -d)" \
58+
&& gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys "$GPG_KEY" \
59+
&& gpg --batch --verify python.tar.xz.asc python.tar.xz \
60+
&& { command -v gpgconf > /dev/null && gpgconf --kill all || :; } \
61+
&& rm -rf "$GNUPGHOME" python.tar.xz.asc \
62+
&& mkdir -p /usr/src/python \
63+
&& tar -xJC /usr/src/python --strip-components=1 -f python.tar.xz \
64+
&& rm python.tar.xz \
65+
\
66+
&& cd /usr/src/python \
67+
&& gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)" \
68+
&& ./configure \
69+
--build="$gnuArch" \
70+
--enable-loadable-sqlite-extensions \
71+
--enable-shared \
72+
--with-system-expat \
73+
--with-system-ffi \
74+
--without-ensurepip \
75+
&& make -j "$(nproc)" \
76+
&& make install \
77+
&& ldconfig \
78+
\
79+
&& apt-mark auto '.*' > /dev/null \
80+
&& apt-mark manual $savedAptMark \
81+
&& find /usr/local -type f -executable -not \( -name '*tkinter*' \) -exec ldd '{}' ';' \
82+
| awk '/=>/ { print $(NF-1) }' \
83+
| sort -u \
84+
| xargs -r dpkg-query --search \
85+
| cut -d: -f1 \
86+
| sort -u \
87+
| xargs -r apt-mark manual \
88+
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
89+
&& rm -rf /var/lib/apt/lists/* \
90+
\
91+
&& find /usr/local -depth \
92+
\( \
93+
\( -type d -a \( -name test -o -name tests \) \) \
94+
-o \
95+
\( -type f -a \( -name '*.pyc' -o -name '*.pyo' \) \) \
96+
\) -exec rm -rf '{}' + \
97+
&& rm -rf /usr/src/python \
98+
\
99+
&& python3 --version
100+
101+
# make some useful symlinks that are expected to exist
102+
RUN cd /usr/local/bin \
103+
&& ln -s idle3 idle \
104+
&& ln -s pydoc3 pydoc \
105+
&& ln -s python3 python \
106+
&& ln -s python3-config python-config
107+
108+
# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
109+
ENV PYTHON_PIP_VERSION=23.3.2
110+
111+
RUN set -ex; \
112+
\
113+
savedAptMark="$(apt-mark showmanual)"; \
114+
apt-get update; \
115+
apt-get install -y --no-install-recommends wget; \
116+
\
117+
wget -O get-pip.py 'https://bootstrap.pypa.io/pip/get-pip.py'; \
118+
\
119+
apt-mark auto '.*' > /dev/null; \
120+
[ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; \
121+
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
122+
rm -rf /var/lib/apt/lists/*; \
123+
\
124+
python get-pip.py \
125+
--disable-pip-version-check \
126+
--no-cache-dir \
127+
"pip==$PYTHON_PIP_VERSION" \
128+
; \
129+
pip --version; \
130+
\
131+
find /usr/local -depth \
132+
\( \
133+
\( -type d -a \( -name test -o -name tests \) \) \
134+
-o \
135+
\( -type f -a \( -name '*.pyc' -o -name '*.pyo' \) \) \
136+
\) -exec rm -rf '{}' +; \
137+
rm -f get-pip.py; \
138+
pip3 install --no-cache-dir \
139+
numpy \
140+
pandas \
141+
matplotlib \
142+
scipy \
143+
scikit-learn \
144+
opencv-python-headless \
145+
jupyter; \
146+
pip3 install --no-cache-dir \
147+
torch \
148+
torchvision \
149+
--index-url https://download.pytorch.org/whl/cpu; \
150+
\
151+
pip3 uninstall --yes pip setuptools
152+
153+
# Necessary as Submitty does path expansion of commands in compiling a homework,
154+
# and so resolves "python" -> "/usr/bin/python"
155+
RUN cd /usr/bin \
156+
&& ln -s /usr/local/bin/python3 python3 \
157+
&& ln -s /usr/local/bin/python3 python \
158+
&& ln -s /usr/local/bin/pip3 pip3 \
159+
&& ln -s /usr/local/bin/pip3 pip
160+
161+
# Necessary to limit thread spawning to avoid jupyter kernel crashes
162+
ENV OMP_NUM_THREADS=2 \
163+
OPENBLAS_NUM_THREADS=2 \
164+
MKL_NUM_THREADS=2 \
165+
NUMEXPR_NUM_THREADS=2 \
166+
BLIS_NUM_THREADS=2 \
167+
VECLIB_MAXIMUM_THREADS=2 \
168+
TORCH_NUM_THREADS=2
169+
170+
CMD ["/bin/bash"]

0 commit comments

Comments
 (0)