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

fix: docker composer to run BDJUNO with AGORIC node rpc and grpc #743

Closed
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
7 changes: 7 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Database credentials
POSTGRES_USER=user
POSTGRES_PASSWORD=password
POSTGRES_DB=bdjuno

# Base URL for actions (leave the same IP of bdjuno instance)
HASURA_ACTION_BASE_URL=http://172.20.0.6:3000
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ build/

# Configuration
*.toml
*.json
config.yaml

# Coverage
coverage.*
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Unreleased
- ([\#702](https://github.com/forbole/bdjuno/pull/702)) Add `message_type` module and store msg types inside `message_type` table, add `messages_by_type` function to allow to query messages by their types
- ([\#FETEAM-4](https://github.com/SimplyStaking/callisto/pull/1)) Fixed `docker-composer.yml` to run BDJUNO with AGORIC node rpc and grpc

### Changes

Expand Down Expand Up @@ -135,4 +136,4 @@ This version introduces breaking changes to certain address-specific data that i
- ([\#276](https://github.com/forbole/bdjuno/pull/276)) Added `fee_grant_allowance` table (v0.44.x)

#### Modules
- ([\#353](https://github.com/forbole/bdjuno/pull/353)) Removed the support for the `history` module
- ([\#353](https://github.com/forbole/bdjuno/pull/353)) Removed the support for the `history` module
37 changes: 37 additions & 0 deletions Dockerfile.bdjuno
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Use golang image as builder
FROM golang:1.20-alpine AS builder

# Install necessary dependencies
RUN apk update && apk add --no-cache make git

# Set the working directory
WORKDIR /go/src/github.com/forbole/callisto

# Copy the source code
COPY . .

# Download dependencies
RUN go mod download

# Build the application
RUN make build

# Start a new stage from alpine image
FROM alpine:latest

# Set the working directory
WORKDIR /bdjuno

# Copy the built binary from the builder stage
COPY --from=builder /go/src/github.com/forbole/callisto/build/bdjuno /usr/bin/bdjuno

# Run bdjuno init during the image build process
RUN bdjuno init

# Copy the config.yaml file
COPY ./configs /root/.bdjuno

RUN bdjuno parse genesis-file --genesis-file-path /root/.bdjuno/genesis.json

# Set the default command to output the contents of the config.yaml file
CMD ["bdjuno", "start"]
14 changes: 14 additions & 0 deletions Dockerfile.hasura
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Use an existing Hasura GraphQL Engine image as the base
FROM hasura/graphql-engine:latest

# Download and install Hasura CLI
RUN curl -L https://github.com/hasura/graphql-engine/raw/master/cli/get.sh | bash

# Update Hasura CLI
RUN hasura update-cli

# Copy Hasura metadata directory from local to container
COPY ./hasura/ /hasura/

# Set working directory to the Hasura metadata directory
WORKDIR /hasura
10 changes: 10 additions & 0 deletions Dockerfile.postgres
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM postgres:latest

# Copy the SQL scripts into a temporary directory
COPY ./database/schema/*.sql /docker-entrypoint-initdb.d/

# Grant permissions to the scripts
RUN chmod +x /docker-entrypoint-initdb.d/*.sql

# Run each SQL script individually during container startup
CMD ["postgres", "-c", "log_statement=all"]
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,35 @@ All the chains' data that are queried from the RPC and gRPC endpoints are stored
a [PostgreSQL](https://www.postgresql.org/) database on top of which [GraphQL](https://graphql.org/) APIs can then be
created using [Hasura](https://hasura.io/).

## Usage
## Localy usage
To know how to setup and run BDJuno, please refer to
the [docs website](https://docs.bigdipper.live/cosmos-based/parser/overview/).

## Docker usage
- docker compose up -d --build
- docker exec -it hasura hasura metadata apply

### Docker postgres service
If you want to access the database through pgAdmin or another DB tool, please ensure that the service port is exposed:

```docker
ports:
- xxxx:5432 # xxxx => 5432 | 5433 | any
```

### Binary tools
- ./bin/build.sh to build
- ./bin/build.sh --clean to fresh build

## Testing
If you want to test the code, you can do so by running

```shell
$ make test-unit
```

**Note**: Requires [Docker](https://docker.com).

This will:
1. Create a Docker container running a PostgreSQL database.
2. Run all the tests using that database as support.


25 changes: 25 additions & 0 deletions bin/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# Check if a folder path is provided as parameter
if [ "$1" == "--clean" ]; then
# Remove database
./bin/prune.sh -db
fi

# Bring up Hasura service
sudo docker compose up -d --build postgres
sudo docker compose up -d --build bdjuno
sudo docker compose up -d --build hasura

# Sleep for 30 seconds
sleep 30s

# Check if Hasura service is running
if sudo docker compose ps | grep -q "hasura"; then
echo "Hasura service is up. Applying metadata changes..."
# Apply metadata changes
sudo docker exec -it hasura hasura metadata apply
else
echo "Hasura service is not running. Metadata changes not applied."
exit 1
fi
14 changes: 14 additions & 0 deletions bin/prune.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

# Stop all services
sudo docker stop $(sudo docker ps -aq)

# Prune all
sudo docker system prune -a -f

# Check if a folder path is provided as parameter
if [ "$1" == "-db" ]; then
# Remove database
sudo rm -rf postgres-data/
echo "Database volume removed..."
fi
2 changes: 1 addition & 1 deletion cmd/bdjuno/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (
initcmd "github.com/forbole/juno/v5/cmd/init"
parsetypes "github.com/forbole/juno/v5/cmd/parse/types"
startcmd "github.com/forbole/juno/v5/cmd/start"
"github.com/forbole/juno/v5/modules/messages"

migratecmd "github.com/forbole/bdjuno/v4/cmd/migrate"
parsecmd "github.com/forbole/bdjuno/v4/cmd/parse"

"github.com/forbole/bdjuno/v4/modules/messages"
"github.com/forbole/bdjuno/v4/types/config"

agoricapp "github.com/Agoric/agoric-sdk/golang/cosmos/app"
Expand Down
63 changes: 63 additions & 0 deletions configs/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
chain:
bech32_prefix: agoric
modules:
- modules
- messages
- auth
- bank
- consensus
- feegrant
- gov
- mint
- pricefeed
- slashing
- staking
- distribution
- upgrade
- wasm
- actions
- daily refetch

node:
type: remote
config:
rpc:
client_name: agoric
address: https://agoric-rpc.polkachu.com:443
max_connections: 20
grpc:
address: agoric-grpc.polkachu.com:14490
insecure: true
parsing:
workers: 10
start_height: 14582058
average_block_time: 5s
listen_new_blocks: true
parse_old_blocks: true
parse_genesis: true
database:
url: postgresql://user:[email protected]:5432/bdjuno?sslmode=disable
max_open_connections: 1
max_idle_connections: 1
partition_size: 100000
partition_batch: 1000
ssl_mode_enable: "false"
ssl_root_cert: ""
ssl_cert: ""
ssl_key: ""
logging:
level: debug
format: text
average_block_time: 5s
pricefeed:
tokens:
- name: Agoric
units:
- denom: ubld
exponent: 0
- denom: bld
exponent: 6
price_id: agoric
actions:
host: 172.20.0.6
port: 3000
Loading