Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerization #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
14 changes: 14 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"
6 changes: 4 additions & 2 deletions gasExpress.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python3

import time
import sys
import json
Expand All @@ -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

Expand Down