-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
103 lines (89 loc) · 6.07 KB
/
Dockerfile
File metadata and controls
103 lines (89 loc) · 6.07 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
# Build via docker:
# If Ethereum RPC endpoint is localhost: docker build --build-arg cores=8 -t ethereum-webserver .
# If Ethereum RPC endpoint is not localhost: docker build --build-arg cores=8 --build-arg url=http://[ip]:[port] -t ethereum-webserver .
# If Ethereum RPC endpoint is Infura: docker build --build-arg cores=8 --build-arg url=https://mainnet.infura.io/v3/<api_key> -t ethereum-webserver-test .
# docker run -d --name ethereum-webserver -p 80:80 ethereum-webserver:latest
FROM nginx
ARG cores=1
ENV ecores=$cores
# Default Ethereum RPC endpoint is http://localhost:8545
ARG url=http://localhost:8545
ENV eurl=$url
RUN apt update \
&& apt install -y --no-install-recommends \
software-properties-common \
ca-certificates \
python3 nano \
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN apt update \
&& apt install -y --no-install-recommends \
build-essential \
python3-dev python3-pip python3-setuptools \
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Update pip
RUN pip3 install --upgrade pip
# Make directory and set as working directory
RUN mkdir -p /opt/app
WORKDIR /opt/app
# Write nginx.conf /etc/nginx/nginx.conf
RUN echo " \n\
user www-data; \n\
worker_processes $ecores; \n\
pid /run/nginx.pid; \n\
events { \n\
worker_connections 1024; \n\
use epoll; \n\
multi_accept on; \n\
} \n\
http { \n\
access_log /dev/stdout; \n\
error_log /dev/stdout; \n\
sendfile on; \n\
tcp_nopush on; \n\
tcp_nodelay on; \n\
keepalive_timeout 65; \n\
types_hash_max_size 2048; \n\
include /etc/nginx/mime.types; \n\
default_type application/octet-stream; \n\
index index.html index.htm; \n\
server { \n\
listen 8191; \n\
listen [::]:8191; \n\
server_name localhost; \n\
root /var/www/html; \n\
location / { \n\
include uwsgi_params; \n\
uwsgi_pass unix:/tmp/uwsgi.socket; \n\
} \n\
} \n\
} \n\
\n\
\n" > /etc/nginx/nginx.conf
# Write uwsgi.ini /opt/app/uwsgi.ini
RUN echo " \n\
[uwsgi] \n\
module = ethereum:app \n\
uid = www-data \n\
gid = www-data \n\
master = true \n\
processes = $ecores \n\
\n\
socket = /tmp/uwsgi.socket \n\
chmod-sock = 664 \n\
vacuum = true \n\
\n\
die-on-term = true \n\
\n\
\n" > /opt/app/uwsgi.ini
# Install app dependencies from requirements.txt
COPY requirements.txt /opt/app
RUN pip3 install --no-cache-dir -r requirements.txt
# Copy startup script
COPY start.sh /opt/app
# Bundle Python app source
COPY ethereum.py /opt/app
# Expose port 8191
EXPOSE 8191
# Execution rights and set default command
RUN chmod +x ./start.sh
CMD ["./start.sh"]