From 6f3964bfa1fa2f69faaf6f9ee7a06df331241c3b Mon Sep 17 00:00:00 2001 From: V Date: Tue, 26 May 2020 05:20:16 +0000 Subject: [PATCH] Dockerization --- Dockerfile | 34 ++++++++++++++++++++++++++++++++++ README.md | 7 +++++++ docker-entrypoint.sh | 14 ++++++++++++++ gasExpress.py | 6 ++++-- 4 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 Dockerfile create mode 100755 docker-entrypoint.sh mode change 100644 => 100755 gasExpress.py diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..061dc30 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,34 @@ +FROM python:3.6-slim-buster as build + +COPY requirements.txt . + +RUN apt-get update -y \ + && apt-get install -y build-essential \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \ + && pip3 install wheel \ + && pip3 install --user -r requirements.txt + +FROM python:3.6-slim-buster + +ENV USER gasoracle + +RUN useradd -r $USER \ + && apt-get update -y \ + && apt-get install -y gosu \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + + +COPY --from=build --chown=$USER:root /root/.local /home/$USER/.local +COPY gasExpress.py /usr/local/bin/ + +ENV OUTPUT_DIR /data +VOLUME ["$OUTPUT_DIR"] +WORKDIR "$OUTPUT_DIR" + +COPY docker-entrypoint.sh /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] + +CMD ["gasExpress.py"] diff --git a/README.md b/README.md index 5bef4b2..99c0ba8 100644 --- a/README.md +++ b/README.md @@ -7,3 +7,10 @@ This is a simple gas price oracle that can be used if you are running a local ge usage: python3 gasExpress.py requirements: pip3 install -r requirements.txt + +## Docker +``` +docker build -t gasstation-express . +docker run -e ETH_NODE_URL=http://10.1.0.23:8545 -e OUTPUT_DIR=/data/mainnet \ +-v $(pwd)/data:/data -it gasstation-express +``` diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 0000000..7ec674d --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,14 @@ +#!/bin/sh +set -e + + +if [ "$1" = "gasExpress.py" ]; then + mkdir -p "$OUTPUT_DIR" + chmod 755 "$OUTPUT_DIR" + chown -R $USER "$OUTPUT_DIR" + cd "$OUTPUT_DIR" + exec gosu $USER "$@" +fi + +echo +exec "$@" diff --git a/gasExpress.py b/gasExpress.py old mode 100644 new mode 100755 index 65346d7..e95b003 --- a/gasExpress.py +++ b/gasExpress.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python3 + import time import sys import json @@ -8,8 +10,8 @@ import numpy as np from web3 import Web3, HTTPProvider - -web3 = Web3(HTTPProvider('http://localhost:8545')) +node_url = os.getenv('ETH_NODE_URL', 'http://localhost:8545') +web3 = Web3(HTTPProvider(node_url)) ### These are the threholds used for % blocks accepting to define the recommended gas prices. can be edited here if desired