-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathDockerfile
171 lines (137 loc) · 6.24 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
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
FROM python:3.7-buster
# FROM ubuntu:18.04
# RUN rm /bin/sh && ln -s /bin/bash /bin/sh
ENV DEBIAN_FRONTEND noninteractive
ENV TZ=Asia/Taipei
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
ARG USERNAME
ENV USERNAME ${USERNAME}
ENV WORKSPACE /home/$USERNAME/workspace
# base
RUN apt-get update && apt-get install -y build-essential wget curl vim git libtool automake \
sudo openssh-server \
mesa-utils libgl1-mesa-glx python3-dev \
libqt5gui5 postgresql libpq-dev \
locales locales-all \
libfontconfig \
libfreetype6 \
xfonts-cyrillic \
xfonts-scalable \
fonts-liberation \
fonts-ipafont-gothic \
fonts-wqy-zenhei \
fonts-wqy-microhei
#---------------------------------------------------------------------------
# lang
#---------------------------------------------------------------------------
ENV LC_ALL en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US.UTF-8
#---------------------------------------------------------------------------
# ssh
#---------------------------------------------------------------------------
RUN ssh-keygen -A
RUN mkdir /var/run/sshd
ADD ./files/sshd_config /etc/ssh/sshd_config
RUN echo "AcceptEnv LANG LC_*" >> /etc/ssh/sshd_config
RUN echo "AllowUsers $USERNAME" >> /etc/ssh/sshd_config
# still need to run with -p to export ports
EXPOSE 23456
# RUN service ssh restart
RUN echo 'root:root' | chpasswd
RUN echo "$USERNAME ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
# add user
RUN useradd -rm -d /home/${USERNAME} -s /bin/bash -g root -G sudo -u 1001 ${USERNAME}
RUN echo "${USERNAME}:${USERNAME}" | chpasswd
RUN usermod -aG sudo ${USERNAME}
# vscode
# https://code.visualstudio.com/docs/remote/containers-advanced#_avoiding-extension-reinstalls-on-container-rebuild
USER ${USERNAME}
WORKDIR /home/${USERNAME}
# fonts
ADD ./files/fontconfig /home/$USERNAME/.config/fontconfig
RUN mkdir -p /home/$USERNAME/.vscode-server/extensions \
/home/$USERNAME/.vscode-server-insiders/extensions \
&& chown -R $USERNAME \
/home/$USERNAME/.vscode-server \
/home/$USERNAME/.vscode-server-insiders
#---------------------------------------------------------------------------
# vnpy
#---------------------------------------------------------------------------
# ta-lib underlying lib (must have before pip install)
RUN mkdir -p /tmp && cd /tmp && wget https://artiya4u.keybase.pub/TA-lib/ta-lib-0.4.0-src.tar.gz
RUN cd /tmp && tar -xvf /tmp/ta-lib-0.4.0-src.tar.gz
RUN cd /tmp/ta-lib && ./configure --prefix=/usr && make && sudo make install
RUN ta-lib-config --libs
# quickfix lib
# RUN mkdir -p /tmp && cd /tmp && git clone https://github.com/quickfix/quickfix.git
RUN mkdir -p /tmp && cd /tmp && \
wget https://github.com/quickfix/quickfix/archive/v1.15.1.tar.gz && \
tar xvf v1.15.1.tar.gz
RUN mv /tmp/quickfix-1.15.1 /tmp/quickfix
RUN cd /tmp/quickfix && ./bootstrap && ./configure --with-python3 && make && sudo make install
# python
RUN mkdir -p $WORKSPACE
RUN cd $WORKSPACE && python3 -m venv venv
RUN $WORKSPACE/venv/bin/pip install pip --upgrade && \
$WORKSPACE/venv/bin/pip install wheel && \
$WORKSPACE/venv/bin/pip install backtrader pandas && \
$WORKSPACE/venv/bin/pip install shioaji --upgrade && \
$WORKSPACE/venv/bin/pip install git+https://github.com/happydasch/btplotting && \
$WORKSPACE/venv/bin/pip install matplotlib==3.2.2 && \
$WORKSPACE/venv/bin/pip install ta-lib && \
$WORKSPACE/venv/bin/pip install requests
RUN $WORKSPACE/venv/bin/pip install tzlocal plotly pyqtgraph qdarkstyle rqdatac peewee
# clone vnpy (commit: b4e8a079be2123e72bfa9a8cccebc784aaee3789)
# RUN cd $WORKSPACE && git clone https://github.com/vnpy/vnpy.git
# RUN cd $WORKSPACE/vnpy && git checkout b4e8a079be2123e72bfa9a8cccebc784aaee3789
RUN cd $WORKSPACE && \
wget https://github.com/vnpy/vnpy/archive/2.1.9.tar.gz && \
tar xvf 2.1.9.tar.gz && mv $WORKSPACE/vnpy-2.1.9 $WORKSPACE/vnpy
ADD ./vnpy-files/patches $WORKSPACE/patches
RUN cd $WORKSPACE/vnpy && git apply $WORKSPACE/patches/*.patch
# get sinopac gateway
RUN mkdir -p $WORKSPACE/vnpy/vnpy/gateway/sinopac
RUN cd $WORKSPACE/vnpy/vnpy/gateway/sinopac && \
wget https://raw.githubusercontent.com/ypochien/vnpy/SinopacGateway/vnpy/gateway/sinopac/__init__.py
RUN cd $WORKSPACE/vnpy/vnpy/gateway/sinopac && \
wget https://raw.githubusercontent.com/ypochien/vnpy/SinopacGateway/vnpy/gateway/sinopac/sinopac_gateway.py
# RUN chmod +x ./vnpy/install.sh
# RUN cd $WORKSPACE/vnpy && source $WORKSPACE/venv/bin/activate && ./install.sh
RUN $WORKSPACE/venv/bin/pip install psycopg2-binary
RUN $WORKSPACE/venv/bin/pip install https://pip.vnpy.com/colletion/ibapi-9.76.1.tar.gz
# quickfix
# RUN cd $WORKSPACE/vnpy && sed -i.bak '/quickfix/d' requirements.txt
RUN $WORKSPACE/venv/bin/pip install -r $WORKSPACE/vnpy/requirements.txt
# upgrade numpy
RUN $WORKSPACE/venv/bin/pip install numpy --upgrade
# build wheel (skip)
RUN cd $WORKSPACE/vnpy && $WORKSPACE/venv/bin/python setup.py build
RUN cd $WORKSPACE/vnpy && $WORKSPACE/venv/bin/python -m pip install .
# workaround extensions .so
ADD ./vnpy-files/copy-so.sh $WORKSPACE
# RUN cd $WORKSPACE && chmod +x ./copy-so.sh && ./copy-so.sh
RUN cd $WORKSPACE && sudo chmod +x ./copy-so.sh && ./copy-so.sh
#---------------------------------------------------------------------------
# environment
#---------------------------------------------------------------------------
# python additional package path
RUN echo "export WORKSPACE=$WORKSPACE" >> ~/.bashrc
RUN echo "export LD_LIBRARY_PATH=$WORKSPACE/vnpy/vnpy/api/xtp/libs" >> ~/.bashrc
RUN echo "export PYTHONPATH=$PYTHONPATH:$WORKSPACE/vnpy" >> ~/.bashrc
RUN echo "source ~/workspace/venv/bin/activate" >> ~/.bashrc
# timezone
RUN echo "export TZ=Asia/Taipei" >> ~/.profile
RUN echo "export LC_CTYPE=en_US.utf-8" >> ~/.profile
RUN echo "export LANG=en_US.UTF-8" >> ~/.profile
# supress libGL error: No matching fbConfigs or visuals found
RUN echo "export LIBGL_ALWAYS_INDIRECT=1" >> ~/.profile
#---------------------------------------------------------------------------
# run
#---------------------------------------------------------------------------
# cleanup
RUN sudo rm -rf /var/lib/apt/lists/*
RUN sudo apt-get -qyy clean
RUN sudo rm -rf /tmp/ta-lib*
RUN sudo rm -rf /tmp/quickfix
ENTRYPOINT sudo service ssh restart && bash