Skip to content

Commit

Permalink
Merge pull request #13 from migalabs/feat/docker-run-commands-from-sh
Browse files Browse the repository at this point in the history
Feat/docker run commands from sh
  • Loading branch information
santi1234567 committed Feb 23, 2024
2 parents a40372a + 446f321 commit 69e4edd
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 24 deletions.
8 changes: 5 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
LOG_LEVEL="info" # debug, info, warn, error
LOG_LEVEL="info" # debug, info, warn, error
WORKER_NUM=10 # Number of workers to run concurrent alchemy/EL node requests
WHALE_THRESHOLD=100 # Threshold for whale detection (min amount of validators)

# UPDATE THESE VALUES
DB_URL="postgres://user:password@localhost:5432/dbName" # URL to connect to the postgres database
WORKER_NUM=15 # Number of workers to run concurrent alchemy/EL node requests
ALCHEMY_URL="https://eth-mainnet.g.alchemy.com/v2/KEY" # Alchemy API URL
EL_ENDPOINT="http://localhost:8545" # Ethereum Layer 1 endpoint, can also be alchemy or infura
WHALE_THRESHOLD=100 # Threshold for whale detection (min amount of validators)

DATABASE_NAME=name # Your database name
DATABASE_USERNAME=user # Your database username
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ ADD . .
RUN go get
RUN go build -o ./build/eth_pokhar


FROM alpine:latest
WORKDIR /
COPY --from=builder /app/build/eth_pokhar ./
COPY --from=builder /app/db/migrations ./db/migrations

ENTRYPOINT ["sh", "-c"]
COPY --from=builder /app/run.sh ./run.sh
RUN chmod +x ./run.sh
ENTRYPOINT [ "./eth_pokhar" ]
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ OPTIONS:
--help, -h show help
```

## Running with Docker (recommended)
## Running with docker-compose (recommended)

To run the tool with docker, you can use the following commands:

Expand All @@ -81,6 +81,14 @@ Finally, run the tool with the following command:
docker-compose up -d
```

In case that you don't want to update de depositor transactions (which can take up to 20 hours), you can set `ONLY_DEPOSITS=true` in the `.env` file and run the tool normally or use the following command:

```bash
ONLY_DEPOSITS=true docker-compose up -d
```

This will set the [`--only-deposits`](#beacon_depositors_transactions) flag to true.

## Output

The tool will create a database with the following tables:
Expand Down
26 changes: 9 additions & 17 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,14 @@ services:
context: ./
dockerfile: Dockerfile
init: true
command: >-
"
./eth_pokhar beacon_depositors_transactions
--log-level=${LOG_LEVEL}
--el-endpoint=${EL_ENDPOINT}
--db-url=${DB_URL}
--workers-num=${WORKER_NUM}
--alchemy-url=${ALCHEMY_URL}
&&
./eth_pokhar identify
--log-level=${LOG_LEVEL}
--el-endpoint=${EL_ENDPOINT}
--db-url=${DB_URL}
--workers-num=${WORKER_NUM}
--alchemy-url=${ALCHEMY_URL}
--recreate-table"
--whale-threshold=${WHALE_THRESHOLD}
environment:
- LOG_LEVEL=${LOG_LEVEL}
- EL_ENDPOINT=${EL_ENDPOINT}
- DB_URL=${DB_URL}
- WORKER_NUM=${WORKER_NUM}
- ALCHEMY_URL=${ALCHEMY_URL}
- WHALE_THRESHOLD=${WHALE_THRESHOLD}
- ONLY_DEPOSITS=${ONLY_DEPOSITS:-false}
network_mode: "host"
depends_on:
db:
Expand All @@ -31,6 +22,7 @@ services:
restart_policy:
condition: on-failure
max_attempts: 5
entrypoint: ["sh", "./run.sh"]

db:
image: postgres
Expand Down
10 changes: 10 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

# If ONLY_DEPOSITS is true then use --only-deposits flag, else use the default
if [ "${ONLY_DEPOSITS}" = "true" ]; then
./eth_pokhar beacon_depositors_transactions --log-level=${LOG_LEVEL} --el-endpoint=${EL_ENDPOINT} --db-url=${DB_URL} --workers-num=${WORKER_NUM} --alchemy-url=${ALCHEMY_URL} --only-deposits || exit 1
else
./eth_pokhar beacon_depositors_transactions --log-level=${LOG_LEVEL} --el-endpoint=${EL_ENDPOINT} --db-url=${DB_URL} --workers-num=${WORKER_NUM} --alchemy-url=${ALCHEMY_URL} || exit 1
fi

./eth_pokhar identify --log-level=${LOG_LEVEL} --el-endpoint=${EL_ENDPOINT} --db-url=${DB_URL} --workers-num=${WORKER_NUM} --alchemy-url=${ALCHEMY_URL} --recreate-table --whale-threshold=${WHALE_THRESHOLD} || exit 1

0 comments on commit 69e4edd

Please sign in to comment.