forked from tornaria/cocalc-docker
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDockerfile
More file actions
313 lines (256 loc) · 10.7 KB
/
Dockerfile
File metadata and controls
313 lines (256 loc) · 10.7 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
FROM ubuntu:20.04
MAINTAINER William Stein <wstein@sagemath.com>
USER root
# See https://github.com/sagemathinc/cocalc/issues/921
ENV LC_ALL C.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV TERM screen
# So we can source (see http://goo.gl/oBPi5G)
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
# Ubuntu software that are used by CoCalc (latex, pandoc, sage)
RUN \
apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
software-properties-common \
texlive \
texlive-latex-extra \
texlive-extra-utils \
texlive-xetex \
texlive-luatex \
texlive-bibtex-extra \
liblog-log4perl-perl
RUN \
apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
tmux \
flex \
bison \
libreadline-dev \
htop \
screen \
pandoc \
aspell \
poppler-utils \
net-tools \
wget \
git \
python3 \
python \
python3-pip \
make \
g++ \
sudo \
psmisc \
rsync \
tidy
RUN \
apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
vim \
inetutils-ping \
lynx \
telnet \
git \
emacs \
subversion \
ssh \
m4 \
latexmk \
libpq5 \
libpq-dev \
build-essential \
automake \
jq
RUN \
apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
gfortran \
dpkg-dev \
libssl-dev \
imagemagick \
libcairo2-dev \
libcurl4-openssl-dev \
graphviz \
smem \
octave \
locales \
locales-all \
postgresql \
postgresql-contrib \
clang-format \
yapf3 \
golang \
r-cran-formatr \
yasm
# Build and install Sage -- see https://github.com/sagemath/docker-images
COPY scripts/ /tmp/scripts
RUN chmod -R +x /tmp/scripts
RUN adduser --quiet --shell /bin/bash --gecos "Sage user,101,," --disabled-password sage \
&& chown -R sage:sage /home/sage/
# make source checkout target, then run the install script
# see https://github.com/docker/docker/issues/9547 for the sync
# Sage can't be built as root, for reasons...
# Here -E inherits the environment from root, however it's important to
# include -H to set HOME=/home/sage, otherwise DOT_SAGE will not be set
# correctly and the build will fail!
RUN mkdir -p /usr/local/sage \
&& chown -R sage:sage /usr/local/sage \
&& sudo -H -E -u sage /tmp/scripts/install_sage.sh /usr/local/ master \
&& sync
RUN /tmp/scripts/post_install_sage.sh /usr/local/ && rm -rf /tmp/* && sync
# Install SageTex
RUN \
sudo -H -E -u sage sage -p sagetex \
&& cp -rv /usr/local/sage/local/share/texmf/tex/latex/sagetex/ /usr/share/texmf/tex/latex/ \
&& texhash
# Save nearly 5GB -- only do after installing all sage stuff!:
RUN rm -rf /usr/local/sage/build/pkgs/sagelib/src/build
# Misc python3 packages...
RUN pip3 install pyyaml matplotlib
# install the Octave kernel.
# NOTE: we delete the spec file and use our own spec for the octave kernel, since the
# one that comes with Ubuntu 20.04 crashes (it uses python instead of python3).
RUN \
pip3 install octave_kernel \
&& rm -rf /usr/local/share/jupyter/kernels/octave
# Pari/GP kernel support
RUN sage --pip install pari_jupyter
# Jupyter notebook and lab
RUN pip3 install jupyter notebook jupyterlab ipywidgets
# Hack1: I had weird issues with jupyterlab not loading,
# which gets fixed by upgrading to the latest pygments:
# RUN pip3 install --upgrade Pygments
# Hack2: For no reason I can discern the "jupyter-kernelspec"
# script doesn't get installed, which breaks a lot of things.
# It's just a simple wrapper around importing and running
# the right code, so I just copy it over from our sage install,
# but with the correct python3 script. This bug is discussed here:
# https://github.com/n-riesco/ijavascript/issues/135
# RUN \
# echo '#!'`which python3` > /usr/bin/jupyter-kernelspec \
# && cat /usr/local/sage/local/bin/jupyter-kernelspec >> /usr/bin/jupyter-kernelspec \
# && chmod a+x /usr/bin/jupyter-kernelspec
# Install LEAN proof assistant
RUN \
export VERSION=3.4.1 \
&& mkdir -p /opt/lean \
&& cd /opt/lean \
&& wget https://github.com/leanprover/lean/releases/download/v$VERSION/lean-$VERSION-linux.tar.gz \
&& tar xf lean-$VERSION-linux.tar.gz \
&& rm lean-$VERSION-linux.tar.gz \
&& rm -f latest \
&& ln -s lean-$VERSION-linux latest \
&& ln -s /opt/lean/latest/bin/lean /usr/local/bin/lean
# Install all aspell dictionaries, so that spell check will work in all languages. This is
# used by cocalc's spell checkers (for editors). This takes about 80MB, which is well worth it.
RUN \
apt-get update \
&& apt-get install -y aspell-*
# Install Node.js and specific version of npm
# (npm@7.20 has a bug that makes it crash at the end of trying to install cocalc packages,
# so I am avoiding it. We don't actually install cocalc packages below though, since we
# build from source.)
RUN \
wget -qO- https://deb.nodesource.com/setup_14.x | bash - \
&& apt-get install -y nodejs libxml2-dev libxslt-dev \
&& /usr/bin/npm install -g npm@7.19.1
# Kernel for javascript (the node.js Jupyter kernel)
RUN \
npm install --unsafe-perm -g ijavascript \
&& ijsinstall --install=global
# Kernel for Typescript -- commented out since seems flakie and
# probably not generally interesting.
#RUN \
# npm install --unsafe-perm -g itypescript \
# && its --install=global
# Install Julia
ARG JULIA=1.6.1
RUN cd /tmp \
&& wget https://julialang-s3.julialang.org/bin/linux/x64/${JULIA%.*}/julia-${JULIA}-linux-x86_64.tar.gz \
&& tar xf julia-${JULIA}-linux-x86_64.tar.gz -C /opt \
&& rm -f julia-${JULIA}-linux-x86_64.tar.gz \
&& mv /opt/julia-* /opt/julia \
&& ln -s /opt/julia/bin/julia /usr/local/bin
# Install R Jupyter Kernel package into R itself (so R kernel works), and some other packages e.g., rmarkdown which requires reticulate to use Python.
RUN echo "install.packages(c('repr', 'IRdisplay', 'evaluate', 'crayon', 'pbdZMQ', 'httr', 'devtools', 'uuid', 'digest', 'IRkernel', 'formatR'), repos='https://cloud.r-project.org')" | sage -R --no-save
RUN echo "install.packages(c('repr', 'IRdisplay', 'evaluate', 'crayon', 'pbdZMQ', 'httr', 'devtools', 'uuid', 'digest', 'IRkernel', 'rmarkdown', 'reticulate', 'formatR'), repos='https://cloud.r-project.org')" | R --no-save
## Xpra backend support -- we have to use the debs from xpra.org,
RUN \
apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y xvfb xsel websockify curl xpra
## X11 apps to make x11 support useful.
RUN \
apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y x11-apps dbus-x11 gnome-terminal \
vim-gtk lyx libreoffice inkscape gimp firefox texstudio evince mesa-utils \
xdotool xclip x11-xkb-utils
# Commit to checkout and build.
ARG BRANCH=master
ARG commit=HEAD
# Pull latest source code for CoCalc and checkout requested commit (or HEAD),
# install our Python libraries globally, then remove cocalc. We only need it
# for installing these Python libraries (TODO: move to pypi?).
RUN \
umask 022 && git clone --depth=1 https://github.com/sagemathinc/cocalc.git \
&& cd /cocalc && git pull && git fetch -u origin $BRANCH:$BRANCH && git checkout ${commit:-HEAD}
RUN umask 022 && pip3 install --upgrade /cocalc/src/smc_pyutil/
# Install code into Sage
RUN umask 022 && sage -pip install --upgrade /cocalc/src/smc_sagews/
# Build cocalc itself
RUN umask 022 && cd /cocalc/src && npm run make
# And cleanup npm cache, which is several hundred megabytes after building cocalc above.
RUN rm -rf /root/.npm
RUN echo "umask 077" >> /etc/bash.bashrc
# Install some Jupyter kernel definitions
COPY kernels /usr/local/share/jupyter/kernels
# Configure so that R kernel actually works -- see https://github.com/IRkernel/IRkernel/issues/388
COPY kernels/ir/Rprofile.site /usr/local/sage/local/lib/R/etc/Rprofile.site
# Build a UTF-8 locale, so that tmux works -- see https://unix.stackexchange.com/questions/277909/updated-my-arch-linux-server-and-now-i-get-tmux-need-utf-8-locale-lc-ctype-bu
RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && locale-gen
# Install IJulia kernel
# I figured out the dierectory /opt/julia/local/share/julia by inspecting the global varaible
# DEPOT_PATH from within a running Julia session as a normal user, and also reading julia docs:
# https://pkgdocs.julialang.org/v1/glossary/
# It was *incredibly* confusing, and the dozens of discussions of this problem that one finds
# via Google are all very wrong, incomplete, misleading, etc. It's truly amazing how
# disorganized-wrt-Google information about Julia is, as compared to Node.js and Python.
RUN echo 'using Pkg; Pkg.add("IJulia");' | JUPYTER=/usr/local/bin/jupyter JULIA_DEPOT_PATH=/opt/julia/local/share/julia JULIA_PKG=/opt/julia/local/share/julia julia
RUN mv "$HOME/.local/share/jupyter/kernels/julia"* "/usr/local/share/jupyter/kernels/"
# Also add Pluto system-wide, since we'll likely support it soon in cocalc, and also
# Nemo and Hecke (some math software).
RUN echo 'using Pkg; Pkg.add("Pluto"); Pkg.add("Nemo"); Pkg.add("Hecke")' | JULIA_DEPOT_PATH=/opt/julia/local/share/julia JULIA_PKG=/opt/julia/local/share/julia julia
### Configuration
COPY login.defs /etc/login.defs
COPY login /etc/defaults/login
COPY run.py /root/run.py
COPY bashrc /root/.bashrc
# CoCalc Jupyter widgets
RUN \
pip3 install --no-cache-dir ipyleaflet
# The Jupyter kernel that gets auto-installed with some other jupyter Ubuntu packages
# doesn't have some nice options regarding inline matplotlib (and possibly others), so
# we delete it.
RUN rm -rf /usr/share/jupyter/kernels/python3
# Fix pythontex for our use
RUN ln -sf /usr/bin/pythontex /usr/bin/pythontex3
# Fix yapf for our use
RUN ln -sf /usr/bin/yapf3 /usr/bin/yapf
# Other pip3 packages
# NOTE: Upgrading zmq is very important, or the Ubuntu version breaks everything..
RUN \
pip3 install --upgrade --no-cache-dir pandas plotly scipy scikit-learn seaborn bokeh zmq
# We stick with PostgreSQL 10 for now, to avoid any issues with users having to
# update to an incompatible version 12. We don't use postgresql-12 features *yet*,
# and won't upgrade until we need to or it becomes a security liability. Note that
# PostgreSQL 10 is officially supported until November 10, 2022 according to
# https://www.postgresql.org/support/versioning/
RUN \
sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' \
&& wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
&& apt-get update \
&& apt-get install -y postgresql-10
CMD /root/run.py
ARG BUILD_DATE
LABEL org.label-schema.build-date=$BUILD_DATE
EXPOSE 22 80 443