The simplest steps to run the application using docker-compose:
- Create an
.envfile, having the following variables defined:NODE_URL(required), Websocket RPC URL of Ethereum nodeRETENTION_BLOCKS(defaults to 50)API_PORT(defaults to 8080)
- Run
docker compose up - Browse
http://localhost:8080/(adjust the port according to the config) for GraphQL Playground.
Runing make gotest will execute all the unit tests in all the packages in the repository.
Both the API and Scanner binaries are containerized as a Dockerfile with 3 image targets:
builder: An intermediate image for building the binariesapi: API server executablescanner: Block scanner's executable
Two executable targets (api and scanner) are standalone images that can be run as containers.
To build the images:
make api.Dockerfilefor building the API server container, witheth-block-scanner/apiimage tag by default.make scanner.Dockerfilefor building the Block scanner container, witheth-block-scanner/scannerimage tag by default.
Alternative to the container distributions, the components (API and Scanner) can be built locally and run by the executable binaries.
make bin/apifor building the API server executable atbin/apimake bin/scannerfor building the Block Scanner executable atbin/scanner
The two Makefile targets implicitly downloads the necessary Go dependencies (see make godown) and
generates synthetic Go files (see make gogen).
The application (the both components, api and scanner) parses environment variables as
configuration parameters during boot. So the environment variables listed below need to be present
on runtime: (See example.env)
DATABASE_URL(forapiandscanner): Connection URL to the shared database instance with write access forscannerand read access forapiinstances.NODE_URL(forscanner): Websocket RPC URL of the ETH node for the scanner to fetch the blocks.RETENTION_BLOCKS(forscanner): Number of the recent blocks to be persisted in the db, older blocks will be pruned.API_URL(forapi): The TCP port to serve the HTTP (GraphQL API and Playground) requests.
The docker-compose.yml file provides the ready-to run setup for the whole application.
- Runs
postgrescontainer as the shared database instance.- The databaes schema is prepared using the
database/schema.sqlfile as an initialization script.
- The databaes schema is prepared using the
- Runs
scannercontainer as the Block Scanner instance. - Runs
apicontainer as the API server instance.
Note: The compose setup does NOT need the images being built as it is configured to build from the Dockerfile when needed.
To run the services up:
docker compose up
(or in the background: docker compose up -d)
To stop the services:
docker compose stop
To remove the containers:
docker compose down
Docker Compose supports .env files, so it is possible to create an .env file for
specifying the required config parameters for the services under the same directory of the compose file.
Note: The compose setup overrides
DATABASE_URLparameter accordingly to the preconfigured database instance.
To run the application independently without using the docker-compose, it is needed to run a Postgres instance
and apply the schema from the database/schema.sql script.
Then, depending on the preference wheter running as container or local binary, follow the instructions on sections Building As containers or As binaries.
Hint: Running the components with the config parameters from
.envfiles:env $(cat .env | xargs) ./bin/api(or... ./bin/scanner).