Merge pull request #29 from lukevs/docker-compose-with-db
Move to Docker Compose. Add a postgres DB + PGAdmin
This commit is contained in:
commit
0679592216
10
.env
Normal file
10
.env
Normal file
@ -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
|
10
Dockerfile
Normal file
10
Dockerfile
Normal file
@ -0,0 +1,10 @@
|
||||
FROM python:3.9
|
||||
|
||||
COPY ./requirements.txt /app/requirements.txt
|
||||
RUN pip install -r /app/requirements.txt
|
||||
|
||||
COPY . /app
|
||||
WORKDIR /app/
|
||||
|
||||
ENTRYPOINT ["./run.sh"]
|
||||
CMD []
|
113
README.md
113
README.md
@ -1,29 +1,96 @@
|
||||
# mev-inspect
|
||||
A [WIP] Ethereum MEV Inspector in Python
|
||||
|
||||
### Local setup
|
||||
## Containers
|
||||
mev-inspect's local setup is built on [Docker Compose](https://docs.docker.com/compose/)
|
||||
|
||||
Requirements:
|
||||
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)
|
||||
|
||||
* python3 and pip3
|
||||
## Running locally
|
||||
Setup [Docker](https://www.docker.com/products/docker-desktop)
|
||||
|
||||
Instructions to run:
|
||||
Start the services with Docker Compose
|
||||
```
|
||||
docker compose up
|
||||
```
|
||||
or to run in the background
|
||||
```
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
* 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`
|
||||
To stop the services (if running in the background, otherwise just ctrl+c)
|
||||
```
|
||||
docker compose down
|
||||
```
|
||||
|
||||
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
|
||||
Check `docker compose help` for more tools available
|
||||
|
||||
## Executing scripts
|
||||
To run a command, prefix it with
|
||||
```
|
||||
docker compose exec mev-inspect <YOUR COMMAND>
|
||||
```
|
||||
|
||||
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'
|
||||
```
|
||||
|
||||
Or to run the tests:
|
||||
```
|
||||
docker compose exec mev-inspect python -m unittest tests/*py
|
||||
```
|
||||
|
||||
## Rebuilding containers
|
||||
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
|
||||
|
||||
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
|
||||
```
|
||||
|
2
build.sh
2
build.sh
@ -1,2 +0,0 @@
|
||||
#!/bin/bash
|
||||
docker build -t flashbots/mev-inspector-py:0.1 docker/.
|
32
docker-compose.yml
Normal file
32
docker-compose.yml
Normal file
@ -0,0 +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:
|
@ -1,19 +0,0 @@
|
||||
FROM python:3.9
|
||||
LABEL maintainer "Nicola Bernini <nicola.bernini@gmail.com>"
|
||||
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
|
@ -1,2 +0,0 @@
|
||||
web3
|
||||
pyyaml
|
2
enter.sh
2
enter.sh
@ -1,2 +0,0 @@
|
||||
#!/bin/bash
|
||||
docker run -it --rm -v $(pwd):/project flashbots/mev-inspector-py:0.1 /bin/bash
|
Loading…
x
Reference in New Issue
Block a user