forked from hummingbot/hummingbot
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Dockerfile
122 lines (98 loc) · 4.29 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
# Set the base image
FROM ubuntu:20.04 AS builder
# Install linux dependencies
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y gcc \
build-essential pkg-config libusb-1.0 curl git \
sudo && \
rm -rf /var/lib/apt/lists/*
# Add hummingbot user
RUN useradd -m -s /bin/bash hummingbot
# Switch to hummingbot user
USER hummingbot:hummingbot
WORKDIR /home/hummingbot
# Install miniconda
RUN curl https://repo.anaconda.com/miniconda/Miniconda3-py38_4.8.2-Linux-x86_64.sh -o ~/miniconda.sh && \
/bin/bash ~/miniconda.sh -b && \
rm ~/miniconda.sh && \
~/miniconda3/bin/conda update -n base conda -y && \
~/miniconda3/bin/conda clean -tipsy
# Dropping default ~/.bashrc because it will return if not running as interactive shell, thus not invoking PATH settings
RUN :> ~/.bashrc
# Install nvm and CeloCLI; note: nvm adds own section to ~/.bashrc
SHELL [ "/bin/bash", "-lc" ]
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash && \
export NVM_DIR="/home/hummingbot/.nvm" && \
source "/home/hummingbot/.nvm/nvm.sh" && \
nvm install 10 && \
npm install --only=production -g @celo/[email protected] && \
nvm cache clear && \
npm cache clean --force && \
rm -rf /home/hummingbot/.cache
# Copy environment only to optimize build caching, so changes in sources will not cause conda env invalidation
COPY --chown=hummingbot:hummingbot setup/environment-linux.yml setup/
# ./install | create hummingbot environment
RUN ~/miniconda3/bin/conda env create -f setup/environment-linux.yml && \
~/miniconda3/bin/conda clean -tipsy && \
# clear pip cache
rm -rf /home/hummingbot/.cache
# Copy remaining files
COPY --chown=hummingbot:hummingbot bin/ bin/
COPY --chown=hummingbot:hummingbot hummingbot/ hummingbot/
COPY --chown=hummingbot:hummingbot setup.py .
COPY --chown=hummingbot:hummingbot LICENSE .
COPY --chown=hummingbot:hummingbot README.md .
COPY --chown=hummingbot:hummingbot DATA_COLLECTION.md .
# activate hummingbot env when entering the CT
RUN echo "source /home/hummingbot/miniconda3/etc/profile.d/conda.sh && conda activate $(head -1 setup/environment-linux.yml | cut -d' ' -f2)" >> ~/.bashrc
# ./compile + cleanup build folder
RUN /home/hummingbot/miniconda3/envs/$(head -1 setup/environment-linux.yml | cut -d' ' -f2)/bin/python3 setup.py build_ext --inplace -j 8 && \
rm -rf build/ && \
find . -type f -name "*.cpp" -delete
# Build final image using artifacts from builer
FROM ubuntu:20.04 AS release
# Dockerfile author / maintainer
LABEL maintainer="CoinAlpha, Inc. <[email protected]>"
# Build arguments
ARG BRANCH=""
ARG COMMIT=""
ARG BUILD_DATE=""
LABEL branch=${BRANCH}
LABEL commit=${COMMIT}
LABEL date=${BUILD_DATE}
# Set ENV variables
ENV COMMIT_SHA=${COMMIT}
ENV COMMIT_BRANCH=${BRANCH}
ENV BUILD_DATE=${DATE}
ENV STRATEGY=${STRATEGY}
ENV CONFIG_FILE_NAME=${CONFIG_FILE_NAME}
ENV WALLET=${WALLET}
ENV CONFIG_PASSWORD=${CONFIG_PASSWORD}
ENV INSTALLATION_TYPE=docker
# Add hummingbot user
RUN useradd -m -s /bin/bash hummingbot && \
ln -s /conf /home/hummingbot/conf && \
ln -s /logs /home/hummingbot/logs && \
ln -s /data /home/hummingbot/data && \
ln -s /certs /home/hummingbot/certs && \
ln -s /scripts /home/hummingbot/scripts
# Create mount points
RUN mkdir /conf /logs /data /certs /scripts && chown -R hummingbot:hummingbot /conf /logs /data /certs /scripts
VOLUME /conf /logs /data /certs /scripts
# Pre-populate scripts/ volume with default scripts
COPY --chown=hummingbot:hummingbot scripts/ scripts/
# Install packages required in runtime
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y sudo libusb-1.0 && \
rm -rf /var/lib/apt/lists/*
# Switch to hummingbot user
USER hummingbot:hummingbot
WORKDIR /home/hummingbot
# Copy all build artifacts from builder image
COPY --from=builder --chown=hummingbot:hummingbot /home/ /home/
# additional configs (sudo)
COPY docker/etc /etc
# Setting bash as default shell because we have .bashrc with customized PATH (setting SHELL affects RUN, CMD and ENTRYPOINT, but not manual commands e.g. `docker run image COMMAND`!)
SHELL [ "/bin/bash", "-lc" ]
CMD /home/hummingbot/miniconda3/envs/$(head -1 setup/environment-linux.yml | cut -d' ' -f2)/bin/python3 bin/hummingbot_quickstart.py \
--auto-set-permissions $(id -nu):$(id -ng)