From c15ec12361d0fdfebe22e4af80aa0a959c0b665b Mon Sep 17 00:00:00 2001 From: Luke Van Seters Date: Thu, 22 Jul 2021 15:45:12 -0400 Subject: [PATCH 01/10] Move Dockerfile to top level + simplify. Add docker compose --- Dockerfile | 7 +++++++ docker-compose.yml | 5 +++++ docker/Dockerfile | 19 ------------------- docker/requirements.txt | 2 -- 4 files changed, 12 insertions(+), 21 deletions(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml delete mode 100644 docker/Dockerfile delete mode 100644 docker/requirements.txt diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..832b85c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.9 + +COPY ./requirements.txt /app/requirements.txt +RUN pip install -r /app/requirements.txt + +COPY . /app +WORKDIR /app/ diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..4e859e8 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,5 @@ +services: + mev-inspect: + build: . + volumes: + - .:/app diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 100644 index 7c8995e..0000000 --- a/docker/Dockerfile +++ /dev/null @@ -1,19 +0,0 @@ -FROM python:3.9 -LABEL maintainer "Nicola Bernini " -COPY requirements.txt . -RUN apt-get update && apt-get -y install sudo - -# Create User -ARG user=mev -ARG password=mev -RUN useradd -m ${user} && echo "${user}:${password}" | chpasswd && adduser mev sudo - -# Switch to user -USER mev - -# Install Python Requirements -RUN pip3 install -r requirements.txt - - -# Initial Dir -WORKDIR /project diff --git a/docker/requirements.txt b/docker/requirements.txt deleted file mode 100644 index dc29617..0000000 --- a/docker/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -web3 -pyyaml From b0a93feb79a36d5daddedd331bbe2fdd20ecb978 Mon Sep 17 00:00:00 2001 From: Luke Van Seters Date: Thu, 22 Jul 2021 15:45:43 -0400 Subject: [PATCH 02/10] Remove scripts replaced by docker compose --- build.sh | 2 -- enter.sh | 2 -- 2 files changed, 4 deletions(-) delete mode 100755 build.sh delete mode 100755 enter.sh diff --git a/build.sh b/build.sh deleted file mode 100755 index dc365e8..0000000 --- a/build.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -docker build -t flashbots/mev-inspector-py:0.1 docker/. diff --git a/enter.sh b/enter.sh deleted file mode 100755 index 6130eb0..0000000 --- a/enter.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -docker run -it --rm -v $(pwd):/project flashbots/mev-inspector-py:0.1 /bin/bash From 652f7e48783d8784902e5e7c6989321f58c201ad Mon Sep 17 00:00:00 2001 From: Luke Van Seters Date: Thu, 22 Jul 2021 16:35:19 -0400 Subject: [PATCH 03/10] Add DB + PGAdmin --- .env | 10 ++++++++++ Dockerfile | 3 +++ docker-compose.yml | 27 +++++++++++++++++++++++++++ run.sh | 4 ++++ 4 files changed, 44 insertions(+) create mode 100644 .env create mode 100755 run.sh diff --git a/.env b/.env new file mode 100644 index 0000000..c9a9b94 --- /dev/null +++ b/.env @@ -0,0 +1,10 @@ +# Postgres +POSTGRES_SERVER=db +POSTGRES_USER=postgres +POSTGRES_PASSWORD=password +POSTGRES_DB=mev_inspect + +# PgAdmin +PGADMIN_LISTEN_PORT=5050 +PGADMIN_DEFAULT_EMAIL=admin@example.com +PGADMIN_DEFAULT_PASSWORD=password diff --git a/Dockerfile b/Dockerfile index 832b85c..df98198 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,3 +5,6 @@ RUN pip install -r /app/requirements.txt COPY . /app WORKDIR /app/ + +ENTRYPOINT ["./run.sh"] +CMD [] diff --git a/docker-compose.yml b/docker-compose.yml index 4e859e8..a82f926 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,32 @@ services: mev-inspect: build: . + depends_on: + - db + env_file: + - .env volumes: - .:/app + + db: + image: postgres:12 + volumes: + - mev-inspect-db-data:/var/lib/postgresql/data/pgdata + env_file: + - .env + environment: + - PGDATA=/var/lib/postgresql/data/pgdata + + pgadmin: + image: dpage/pgadmin4 + networks: + - default + depends_on: + - db + env_file: + - .env + ports: + - "5050:5050" + +volumes: + mev-inspect-db-data: diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..db2c946 --- /dev/null +++ b/run.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +# Ah, ha, ha, ha, stayin' alive... +while :; do :; done & kill -STOP $! && wait $! From 9ab63b5ddb4a3e772312229fb8e300f457fdecb0 Mon Sep 17 00:00:00 2001 From: Luke Van Seters Date: Thu, 22 Jul 2021 16:41:10 -0400 Subject: [PATCH 04/10] Rename to app --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index a82f926..daac090 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,5 @@ services: - mev-inspect: + app: build: . depends_on: - db From bdb21570381faba44ee6aefa511d2ad4588991bb Mon Sep 17 00:00:00 2001 From: Luke Van Seters Date: Thu, 22 Jul 2021 17:05:41 -0400 Subject: [PATCH 05/10] Rename back to mev-inspect. Update README --- README.md | 92 ++++++++++++++++++++++++++++++++++------------ docker-compose.yml | 2 +- 2 files changed, 70 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index b804463..9520e97 100644 --- a/README.md +++ b/README.md @@ -1,29 +1,75 @@ +# mev-inspect -### Local setup +## Running locally +Setup Docker -Requirements: +Start the services with Docker Compose +``` +docker compose up +``` +or to run in the background +``` +docker compose up -d +``` -* python3 and pip3 +To stop the services +``` +docker compose down +``` -Instructions to run: +## Executing scripts +To run a command, prefix it with +``` +docker compose exec mev-inspect +``` -* Setup a virtual enviroment to manage dependencies (optional) - * `python3 -m venv env` -* Activate it - * `. env/bin/activate` (exit with `deactivate`) -* web3 build-related dependencies (on Ubuntu 20.04) - * `sudo apt-get install libevent-dev libpython3.8-dev python3.8-dev libssl-dev` -* Install python libraries - * `pip3 install -r requirements.txt` -* Run tests for token flow - * `python -m unittest tests/tokenflow_test.py` +For example, to run `testing_file.py`: +``` +docker compose exec mev-inspect python testing_file.py \ + -block_number 11931271 \ + -rpc 'http://111.11.11.111:8545' +``` -If contributing: -* Install dev libraries - * `pip3 install -r requirements_dev.txt` -* Setup pre-commit - * `pre-commit install` -* Install dependencies and verify it's working - * `pre-commit run --all-files` - * If you see "failed to find interpreter for..." it means you're missing the correct python version - * The current version is python3.9 - [pyenv](https://github.com/pyenv/pyenv) is a great option for managing python versions +Or to run the tests: +``` +docker compose exec mev-inspect python -m unittest test/*py +``` + +## Rebuilding containers +After changes to the app's Dockerfile, rebuild with +``` +docker compose build +``` + +## Contributing +Contributing requires installing the pre-commit hooks + +1 . Ensure you're using python 3.9 + +If not, [pyenv](https://github.com/pyenv/pyenv) is a great option for managing python versions + +2. Create a virtualenv +``` +python3 -m venv venv +``` + +3. Activate it +``` +. venv/bin/activate +``` +(exit with `deactivate`) + +4. Install dev libraries +``` +pip install -r requirements_dev.txt +``` + +5. Install pre-commit +``` +pre-commit install +``` + +6. Install pre-commit's dependencies and ensure it's working +``` +pre-commit run --all-files +``` diff --git a/docker-compose.yml b/docker-compose.yml index daac090..a82f926 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,5 @@ services: - app: + mev-inspect: build: . depends_on: - db From 710c011575ea2f4d182efd54333b3a988d1e96a8 Mon Sep 17 00:00:00 2001 From: Luke Van Seters Date: Thu, 22 Jul 2021 17:06:54 -0400 Subject: [PATCH 06/10] Add the source for run.sh --- run.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/run.sh b/run.sh index db2c946..434b3e6 100755 --- a/run.sh +++ b/run.sh @@ -1,4 +1,6 @@ #!/bin/bash +# Source: https://github.com/docker/compose/issues/1926#issuecomment-505294443 + # Ah, ha, ha, ha, stayin' alive... while :; do :; done & kill -STOP $! && wait $! From b563162b7ef3baf860141be6a0e1bc7e43c87938 Mon Sep 17 00:00:00 2001 From: Luke Van Seters Date: Thu, 22 Jul 2021 17:10:04 -0400 Subject: [PATCH 07/10] Include a link to docker --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9520e97..e85a528 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # mev-inspect ## Running locally -Setup Docker +Setup [Docker](https://www.docker.com/products/docker-desktop) Start the services with Docker Compose ``` @@ -17,6 +17,8 @@ To stop the services docker compose down ``` +Check `docker compose help` for more tools available + ## Executing scripts To run a command, prefix it with ``` From 47e778d851111a8750ff981eba1e776710583c24 Mon Sep 17 00:00:00 2001 From: Luke Van Seters Date: Thu, 22 Jul 2021 17:13:36 -0400 Subject: [PATCH 08/10] A little more in the readme --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e85a528..01ab08d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,13 @@ # mev-inspect +## Containers +mev-inspect's local setup is built on [Docker Compose](https://docs.docker.com/compose/) + +By default it starts up: +- `mev-insepct` - a container with the code in this repo used for running scripts +- `db` - a postgres database instance +- `pgadmin` - a postgres DB UI for querying and more (avaiable at localhost:5050) + ## Running locally Setup [Docker](https://www.docker.com/products/docker-desktop) @@ -34,7 +42,7 @@ docker compose exec mev-inspect python testing_file.py \ Or to run the tests: ``` -docker compose exec mev-inspect python -m unittest test/*py +docker compose exec mev-inspect python -m unittest tests/*py ``` ## Rebuilding containers From 76f89981d45ab0ea9fa3bf18045f7351132de3bb Mon Sep 17 00:00:00 2001 From: Luke Van Seters Date: Thu, 22 Jul 2021 17:23:08 -0400 Subject: [PATCH 09/10] Add a subtitle --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 01ab08d..e86817b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # mev-inspect +A [WIP] Ethereum MEV Inspector in Python ## Containers mev-inspect's local setup is built on [Docker Compose](https://docs.docker.com/compose/) @@ -20,7 +21,7 @@ or to run in the background docker compose up -d ``` -To stop the services +To stop the services (if running in the background, otherwise just ctrl+c) ``` docker compose down ``` From efce0914427f43923578f3b94eafb1a74cf498eb Mon Sep 17 00:00:00 2001 From: Luke Van Seters Date: Thu, 22 Jul 2021 17:35:55 -0400 Subject: [PATCH 10/10] Add instructions for PGAdmin --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index e86817b..3e9523f 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,16 @@ After changes to the app's Dockerfile, rebuild with docker compose build ``` +## Using PGAdmin + +1. Go to [localhost:5050](localhost:5050) + +2. Login with the PGAdmin username and password in `.env` + +3. Add a new engine for mev_inspect with + - host: db + - user / password: see `.env` + ## Contributing Contributing requires installing the pre-commit hooks