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

Run Juno in docker #18

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
12 changes: 12 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
POSTGRES_DB_FOLDER=<where_create_postgres; exapmle ./postgres>
POSTGRES_DB_HOST=<db_host>
POSTGRES_DB_PORT=<db_port>
POSTGRES_DB_NAME=<db_name>
POSTGRES_USER_NAME=<db_user>
POSTGRES_DB_PASSWORD=<db_password>
HASURA_PORT=<hasura_port>
HASURA_ADMIN_SECRET=<hasura_password>
JUNO_SSL_MODE=<ssl_mode>
JUNO_WORKERS_NUMBER=<amount_of_workers>
RPC_URL=<gaia_node_http_rpc>
CLIENT_URL=<gaia_node_http_lcd>
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM golang:latest

ARG JUNO_WORKERS_NUMBER=1

ENV JUNO_WORKERS_NUMBER=${JUNO_WORKERS_NUMBER}

WORKDIR /app

COPY go.mod go.sum ./

RUN go mod download

COPY . .

RUN go build

CMD ./juno config.toml --workers $JUNO_WORKERS_NUMBER
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ install: go.sum
@echo "installing juno binary..."
@go install -mod=readonly $(BUILD_FLAGS) .

###############################################################################
# Build / Run in Docker
###############################################################################

docker:
@sh scripts/start-docker.sh

###############################################################################
# Tools
###############################################################################
Expand Down
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

## Table of Contents

- [Background](#background)
- [Install](#install)
- [Usage](#usage)
- [Schemas](#schemas)
- [Future Improvements](#future-improvements)
- [Contributing](#contributing)
- [License](#license)
- [Background](#background)
- [Install](#install)
- [Usage](#usage)
- [Schemas](#schemas)
- [Future Improvements](#future-improvements)
- [Contributing](#contributing)
- [License](#license)

## Background

Expand Down Expand Up @@ -54,6 +54,15 @@ To install the binary run `make install`.

**Note**: Requires [Go 1.13+](https://golang.org/dl/)

## Running in docker

- Open and fill `.env` file with all necessary data
- To install in docker run `make docker`.

Juno, Hasura and Postgres would be deployed in docker containers.

**Note** Not necessary to create `config.toml` for docker installation, it would be generated automatically from `.env` file.

## Usage

Juno internally runs a single worker that consumes from a single queue. The
Expand Down
44 changes: 44 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
version: '3'

services:
postgres:
image: postgres:latest
restart: always
container_name: juno_postgres
volumes:
- ./postgres:/var/lib/postgresql/data
- ./schema:/root/schema
environment:
- POSTGRES_DB=${POSTGRES_DB_NAME}
- POSTGRES_USER=${POSTGRES_USER_NAME}
- POSTGRES_PASSWORD=${POSTGRES_DB_PASSWORD}
networks:
juno-net:
ipv4_address: 172.28.1.2
ports:
- 127.0.0.1:${POSTGRES_DB_PORT}:5432
graphql-engine:
image: hasura/graphql-engine:latest
restart: always
container_name: juno_hasura
depends_on:
- "postgres"
environment:
HASURA_GRAPHQL_DATABASE_URL: postgres://${POSTGRES_USER_NAME}:${POSTGRES_DB_PASSWORD}@172.28.1.2:5432/${POSTGRES_DB_NAME}
HASURA_GRAPHQL_ENABLE_CONSOLE: "true" # set to "false" to disable console
HASURA_GRAPHQL_ENABLED_LOG_TYPES: startup, http-log, webhook-log, websocket-log, query-log
HASURA_GRAPHQL_ADMIN_SECRET: $HASURA_ADMIN_SECRET
networks:
juno-net:
ipv4_address: 172.28.1.3
ports:
- 127.0.0.1:${HASURA_PORT}:8080


networks:
juno-net:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.28.1.0/24
33 changes: 33 additions & 0 deletions scripts/start-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#! /bin/bash

# temporeraly import variables
export $(cat .env)

# run postgres and hasura in containers, wait 2 seconds to start postgres
docker-compose up -d
sleep 2

# init database with basic tables
docker exec -ti juno_postgres psql -f /root/schema/validator.sql -d $POSTGRES_DB_NAME -U $POSTGRES_USER_NAME
docker exec -ti juno_postgres psql -f /root/schema/pre_commit.sql -d $POSTGRES_DB_NAME -U $POSTGRES_USER_NAME
docker exec -ti juno_postgres psql -f /root/schema/block.sql -d $POSTGRES_DB_NAME -U $POSTGRES_USER_NAME
docker exec -ti juno_postgres psql -f /root/schema/transaction.sql -d $POSTGRES_DB_NAME -U $POSTGRES_USER_NAME

# create docker.config.toml, put values from .env file to config.toml
echo -n 'rpc_node="' >> config.toml && echo -n $RPC_URL >> config.toml && echo -n '"' >> config.toml
sed -i "/rpc/a client_node=\"$CLIENT_URL\"" config.toml
echo >> config.toml
echo '[database]' >> config.toml
sed -i "/database/a host=\"$POSTGRES_DB_HOST\"" config.toml
sed -i "/host=/a port=$POSTGRES_DB_PORT" config.toml
sed -i "/port/a name=\"$POSTGRES_DB_NAME\"" config.toml
sed -i "/name/a user=\"$POSTGRES_USER_NAME\"" config.toml
sed -i "/user/a password=\"$POSTGRES_DB_PASSWORD\"" config.toml
sed -i "/password/a ssl_mode=\"$JUNO_SSL_MODE\"" config.toml

# build juno and run it in container
docker build -t juno:latest --build-arg JUNO_WORKERS_NUMBER=$JUNO_WORKERS_NUMBER .
docker run -d --name juno --network="host" juno:latest

# remove config toml, as far as it copyed to container
rm config.toml