forked from quantbelt/jupyter-quant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
119 lines (104 loc) · 4.78 KB
/
Dockerfile
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
###############################################################################
# Builder stage
###############################################################################
# hadolint global ignore=DL3003,DL3008,SC2028
ARG IMG_PYTHON_VERSION
FROM python:"${IMG_PYTHON_VERSION}" AS builder
ENV APT_PROXY_FILE=/etc/apt/apt.conf.d/01proxy
COPY requirements.txt /.
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN if [ -n "$APT_PROXY" ]; then \
echo "Acquire::http { Proxy \"${APT_PROXY}\"; }" \
| tee "${APT_PROXY_FILE}" \
;fi && \
echo "deb http://deb.debian.org/debian bookworm contrib" | tee /etc/apt/sources.list.d/contrib.list && \
apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
libatlas-base-dev gfortran msttcorefonts pkg-config \
libfreetype6-dev libhdf5-dev cmake && \
apt-get clean && rm -rf /var/lib/apt/lists/* && \
# # TA-Lib
cd /tmp && \
curl -LO https://github.com/quantbelt/jupyter-quant/releases/download/ta-lib-0.4.0-linux/ta-lib-0.4.0-linux_"$(uname -m)".tgz && \
curl -LO https://github.com/quantbelt/jupyter-quant/releases/download/ta-lib-0.4.0-linux/ta-lib-0.4.0-linux_"$(uname -m)".tgz.sha256 && \
sha256sum -c ta-lib-0.4.0-linux_"$(uname -m)".tgz.sha256 && \
cd / && tar xzf /tmp/ta-lib-0.4.0-linux_"$(uname -m)".tgz && \
export PREFIX=/usr/local/ta-lib && \
export TA_LIBRARY_PATH="$PREFIX/lib" && \
export TA_INCLUDE_PATH="$PREFIX/include" && \
# end TA-Lib
pip wheel --no-cache-dir --wheel-dir /wheels -r /requirements.txt
###############################################################################
# Final stage
###############################################################################
ARG IMG_PYTHON_VERSION
FROM python:"${IMG_PYTHON_VERSION}"-slim
ENV APT_PROXY_FILE=/etc/apt/apt.conf.d/01proxy
ENV USER="${USER:-gordon}"
ARG USER_ID="${USER_ID:-1000}"
ARG USER_GID="${USER_GID:-1000}"
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV PIP_USER true
ENV PATH="$PATH:/home/$USER/.local/bin"
# base data directory
ENV BASE_DATA="/home/${USER}/.local"
ENV BASE_CONFIG="/home/${USER}/.config"
# XDG env
ENV XDG_CACHE_HOME="${BASE_DATA}/cache"
ENV XDG_CONFIG_HOME="${BASE_CONFIG}"
ENV XDG_DATA_HOME="${BASE_DATA}/share "
ENV XDG_STATE_HOME="${BASE_DATA}/state"
# ipython
ENV IPYTHONDIR="${BASE_CONFIG}/ipython"
# jupyter
ENV JUPYTER_CONFIG_DIR="${BASE_CONFIG}/jupyter"
ENV JUPYTER_DATA_DIR="${BASE_DATA}/share/jupyter"
ENV JUPYTERLAB_DIR="${BASE_DATA}/share/jupyter/lab"
ENV JUPYTERLAB_SETTINGS_DIR="${JUPYTER_CONFIG_DIR}/lab/user-settings"
ENV JUPYTERLAB_WORKSPACES_DIR="${JUPYTER_CONFIG_DIR}/lab/workspaces"
ENV JUPYTER_SERVER_ROOT="/home/${USER}/Notebooks"
# matplotlib
ENV MPLCONFIGDIR="${BASE_CONFIG}/matplotlib"
# ta-lib
ENV TA_PREFIX=/usr/local/ta-lib
ENV TA_LIBRARY_PATH=$TA_PREFIX/lib
ENV TA_INCLUDE_PATH=$TA_PREFIX/include
# shell
ENV SHELL="/bin/bash"
COPY --from=builder /usr/share/fonts/truetype /usr/share/fonts/truetype
COPY --from=builder /usr/local/ta-lib/ /usr/local/ta-lib/
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN if [ -n "$APT_PROXY" ]; then \
echo "Acquire::http { Proxy \"${APT_PROXY}\"; }" \
| tee "${APT_PROXY_FILE}" \
;fi && \
apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
openssh-client sudo curl graphviz git tzdata unzip less xclip nano-tiny \
ffmpeg pandoc stow jq bash-completion procps && \
apt-get clean && rm -rf /var/lib/apt/lists/* && \
if [ -f "${APT_PROXY_FILE}" ]; then \
rm "${APT_PROXY_FILE}" \
;fi && \
groupadd --gid "${USER_GID}" "${USER}" && \
useradd -ms /bin/bash --uid "${USER_ID}" --gid "${USER_GID}" "${USER}" && \
echo "${USER} ALL=(ALL) NOPASSWD:ALL" | tee -a /etc/sudoers && \
python -c "import compileall; compileall.compile_path(maxlevels=10)"
USER $USER_ID:$USER_GID
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN --mount=type=bind,from=builder,source=/wheels,target=/wheels \
pip install --user --no-cache-dir /wheels/* && \
# Import matplotlib the first time to build the font cache.
MPLBACKEND=Agg python -c "import matplotlib.pyplot" && \
mkdir "${JUPYTER_SERVER_ROOT}" && \
python -c "import compileall; compileall.compile_dir('${BASE_DATA}/lib/python$(echo "$PYTHON_VERSION" | cut -d '.' -f1,2)/site-packages', force=True)"
COPY entrypoint.sh /
WORKDIR ${JUPYTER_SERVER_ROOT}
CMD ["jupyter-lab", "--no-browser", "--ip=0.0.0.0"]
ENTRYPOINT ["/entrypoint.sh"]
LABEL org.opencontainers.image.source=https://github.com/quantbelt/jupyter-quant
LABEL org.opencontainers.image.url=https://github.com/quantbelt/jupyter-quant/pkgs/container/jupyter-quant
LABEL org.opencontainers.image.description="A dockerized Jupyter quant research enviroment. "
LABEL org.opencontainers.image.licenses="Apache License Version 2.0"
LABEL org.opencontainers.image.version=${IMAGE_VERSION}