Skip to content

Commit

Permalink
Merge pull request #6 from InjectiveLabs/f/docker
Browse files Browse the repository at this point in the history
Adds support for dockerized chain components
  • Loading branch information
nhannamsiu authored Nov 19, 2021
2 parents 368e81e + cebe3c5 commit bb99243
Show file tree
Hide file tree
Showing 11 changed files with 739 additions and 2 deletions.
105 changes: 105 additions & 0 deletions docker/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# File contains docker secific environment varialbes, users should edit only ones in
# User Configurable section.
# Each service contains required and optional varialbes, please make sure you populate all required.

#####################
### User Configurable ###

# Network Env #
MONIKER=injective
CHAIN_ID=injective-1
APP_ENV=prod
APP_VERSION=prod
NETWORK=mainnet
LOG_LEVEL="info"
PASSPHRASE=""

# Injective image tag, options are latest, local, prod
INJ_IMAGE_TAG=prod

# Injective Core env #
# Optional
# Resource limits works only with swarm mode
INJ_CORE_STACK_RESOURCE_RAM_LIMIT=8G
INJ_CORE_STACK_RESOURCE_RAM_RESEVATION=4G


# Injective Exchange Process #
# Optional
ALCHEMY_ENDPOINT=
INJ_EXHCHANGE_PROCESS_LOG_BUGSNAG_ENABLED="false"
INJ_EXHCHANGE_PROCESS_LOG_BUGSNAG_KEY=
INJ_EXCHANGE_PROCESS_STATSD_DISABLED="true"
INJ_EXCHANGE_PROCESS_STATSD_ADDR=""
# Resource limits works only with swarm mode
INJ_EXCHANGE_PROCESS_RESOURCE_RAM_LIMIT=4G
INJ_EXCHANGE_PROCESS_RESOURCE_RAM_RESERVATION=4G
INJ_EXCHANGE_PROCESS_CHRONOS_RPC_PORT=5500

# Injective Exchange API #

## Required #
INJ_EXCHANGE_API_FEE_PAYER_PK=""

# Optional #
INJ_EXCHANGE_API_STATSD_DISABLED="true"
INJ_EXCHANGE_API_STATSD_ADDR=""
# Resource limits works only with swarm mode
INJ_EXCHANGE_API_RESOURCE_RAM_LIMIT=4G
INJ_EXCHANGE_API_RESOURCE_RAM_RESERVED=4G

# Injevtive Exchange Gateway

# Optional #
INJ_EXCHANGE_GATEWAY_LOG_BUGSNAG_ENABLED="false"
INJ_EXCHANGE_GATEWAY_EXCHANGE_STATSD_DISABLE="true"
INJ_EXCHNAGE_GATEWAY_EXCHANGE_STATSD_ADDR=""

# INJ Peggo
# Required
INJ_PEGGO_PEGGY_ETH_PRIVATE_KEY=""
INJ_PEGGY_COSMOS_PRIVKEY=""
INJ_PEGGY_CONTRACT_ADDRESS=""
INJ_CONTRACT_ADDRESS=""

# Optional
INJ_ADDR=""
INJ_PEGGO_STATSD_DISABLED="true"
INJ_PEGGO_STATSD_ADDR=""


#############################
### DO NOT EDIT FROM HERE ####

### Injective Exchange Gateway ####
INJ_EXCHANGE_GATEWAY_IMAGE_REPO=public.ecr.aws/l9h3g6c6/injective-exchange
INJ_EXCHANGE_GATEWAY_COMMAND=injective-exchange web3-gateway
INJ_EXCHANGE_GATEWAY_CHRONOS_PORT=4444
INJ_EXCHANGE_GATEWAY_CHRONOS_PORT_EXPOSED=4445
INJ_EXCHANGE_GATEWAY_HTTP_GATEWAY_LISTEN_PORT=8810
INJ_EXCHANGE_GATEWAY_GRPC_PORT_EXPOSED=9911
INJ_EXCHANGE_GATEWAY_GRPC_PORT=9910

### Injective Exchange API ###
INJ_EXCHANGE_API_IMAGE_REPO=public.ecr.aws/l9h3g6c6/injective-exchange
INJ_EXCHANGE_API_COMMAND=injective-exchange api
INJ_EXCHANGE_API_CHRONOS_PORT=4444
INJ_EXCHANGE_GRPC_LISTEN_PORT=9910

### Injective Exchange Process ###
INJ_EXCHANGE_PROCESS_IMAGE_REPO=public.ecr.aws/l9h3g6c6/injective-exchange
INJ_EXCHANGE_PROCESS_COMMAND=injective-exchange process

### Injective Core env ###
INJ_CORE_IMAGE_REPO=public.ecr.aws/l9h3g6c6/injective-core

### Injective Mongo env ###
INJ_MONGO_DB_IMAGE_TAG=5.0.3
INJ_MONGO_DB_PORT=27017

### Ports ###
INJ_NETWORK_P2P_PORT=26656
INJ_NETWORK_GRPC_PORT=26657
INJ_NETWORK_COSMOS_GRPC_PORT=9900
INJ_NETWORK_COSMOS_GRPC_WEB_PORT=9091
INJ_NETWORK_COSMOS_API_PORT=10337
146 changes: 146 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# Injective Network

Following those instructions, you will run dockerized [Injective Chain Components on mainnet](#running-mainnet).

* Injective Chain Node
* Relayer
* Trading API components (Market makers)


# Prerequests

**Hardware Requirments**

| Minimum | Recommendation |
| -----------------| ---------------|
| Memory: 16Gb | Memory: 32Gb+ |
| Storage: 1Tb | Storage: 2Tb |
| Network: 5Gbps+ | Network: 5Gbps+|


**Software Requirments**

* [Docker Version 20.X.X][get-docker-link]
* [docker-compose version 1.29.X][get-compose-link]
* [Git][get-git-link]

# Getting Started

NOTE: All commands are executed from the current path level, a `docker` folder.


## Configure Environment

Network-related env variables are defined in `.env` file. There is a `.env.example` that you can copy and use as a starting point.

`cp .env.example .env`

Edit `.env` file.

The most important/required environment variables are

| NAME | OPTIONS | DEFAULT |
| -------------| ----------------------|---------|
| NETWORK | mainnet, tesnet | mainnet |
| APP_ENV | prod/staging | prod |
| APP_VERSION | prod/staging | prod |
| INJ_IMAGE_TAG| prod/local | prod |
| LOG_LEVEL | error/warn/info/debug | info |
| CHAIN_ID | injective-1, injective-888 | injective-1 |
|


*IMPORTANT:* Setup correct `NETWORK` env, options are `mainnet` or `testnet`.

# Running mainnet

## First Time Setup

Running an Injective stack for the first time requires provisioning, configuration, and data sync.
This process is seamless and fully automated, thanks to the injective provisioning container.


```
docker-compose -f docker-compose.yaml -f addons/docker-compose.provisioner.yaml up -d provisioner
```

From now on, the provisioning process in running in the background, you can follow with

`docker logs -f injective-provisioner`

It takes approximately one-two hours for full sync (depending on the internet connection also). After successful sync, the container will exit, and you will see the message.

`### Successful Provisioning ###`

From now on, you are ready to run Injective components.


## Running Components

### Injective Relayer Stack ###

This stack contains Relayer components. It will run

* Injective Core (injectived)
* Injective Trading API components (exchange API, exchange Gateway, exchange process)

```
docker-compose -f docker-compose.yaml -f docker-compose.prod.yaml up -d --remove-orphans mongo injective-core injective-exchange-process injective-exchange-api injective-exchange-gateway
```

### Injective Trading Stack ####

This stack contains additional trading components. It will run:

* Injective Core (injectived)
* Injective Trading API components (exchange API, exchange Gateway, exchange process, trading bot, liquidator bot, price oracle)

```
docker-compose -f docker-compose.yaml -f docker-compose.prod.yaml up -d --remove-orphans
```

## Check logs

```
docker-compose -f logs
```

## Restart the Network

```
docker-compose -f docker-compose.yaml -f docker-compose.prod.yaml restart
```

## Stop the Network

```
docker-compose -f docker-compose.yaml -f docker-compose.prod.yaml stop
```

## Remove all components and data

**NOTE** All data will be erased, and you will lose the whole setup, which will require running everything from scratch for the first time.
Use this command **ONLY** when you want to nuke the whole setup.

```
docker-compose -f docker-compose.yaml -f docker-compose.prod.yaml down
```

# Get Involved

Injective Protocol is a community-driven project; we welcome all contributions.

* Discuss with [Discord community][discord-community-link]
* Join Injective on [Telegram][telegram-community-link]
* [Github repositories][injective-github-repo]
* Follows us on [Twitter][injective-twitter-link]


[discord-community-link]: https://discord.com/invite/injective
[telegram-community-link]: https://t.me/joininjective
[injective-docs]: https://chain.injective.network/
[injective-twitter-link]: https://twitter.com/InjectiveLabs
[injective-github-repo]: https://github.com/InjectiveLabs
[get-docker-link]:https://docs.docker.com/get-docker/
[get-compose-link]: https://docs.docker.com/compose/install/
[get-git-link]: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
40 changes: 40 additions & 0 deletions docker/addons/docker-compose.provisioner.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
version: '3.8'

services:

provisioner:
container_name: injective-provisioner
image: ubuntu:latest
command: ["bash", "/home/ubuntu/scripts/provision-core.sh"]
environment:
TZ: America/New_York
DEBIAN_FRONTEND: noninteractive
GIT_TESTNET_TAG: "v0.4.17-1635998233"
GIT_MAINNET_TAG: "v1.1.1-1636733798"
GIT_INJ_ORG: "https://github.com/InjectiveLabs"
GIT_NETWORK_CONFIG: "mainnet-config"
GIT_RELEASE_REPO: "https://github.com/InjectiveLabs/injective-chain-releases/releases/download"
RELEASE_ARCH: "linux-amd64.zip"
GIT_API_LATEST_RELEASE: "https://api.github.com/repos/InjectiveLabs/injective-chain-releases/releases/latest"
MAINNET_CONFIG: "mainnet-config"
MAINNET_CONFIG_LATEST: "10001"
TEST_NET_CONFIG_LATEST: "staking/40017"
TESTNET_CONFIG: "testnet-config"
VOLUMES_PATH: "/home/ubuntu/volumes"
SYNC_CORE_SNAPSHOT: "true"
SYNC_EXCHANGE_SNAPSHOT: "true"
SYNC_CHRONOS_SNAPSHOT: "true"
INJ_HOME: /home/ubuntu/volumes/.injectived
NETWORK: ${NETWORK}
APP_VERSION: ${APP_VERSION}
CHAIN_ID: ${CHAIN_ID}
APP_ENV: ${APP_ENV}
MONIKER: ${MONIKER}
PASSPHRASE: ${PASSPHRASE}
networks:
- injective
volumes:
- ./volumes:/home/ubuntu/volumes
- ./scripts:/home/ubuntu/scripts
- ./env:/home/ubuntu/env

42 changes: 42 additions & 0 deletions docker/docker-compose.prod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
version: '3.9'

services:

mongo:
restart: always

#main containers
injective-core:
restart: always
logging:
driver: journald
ports:
- ${INJ_NETWORK_P2P_PORT}:${INJ_NETWORK_P2P_PORT}
- ${INJ_NETWORK_GRPC_PORT}:${INJ_NETWORK_GRPC_PORT}
- ${INJ_NETWORK_COSMOS_API_PORT}:${INJ_NETWORK_COSMOS_API_PORT}
- ${INJ_NETWORK_COSMOS_GRPC_PORT}:${INJ_NETWORK_COSMOS_GRPC_PORT}
- ${INJ_NETWORK_COSMOS_GRPC_WEB_PORT}:${INJ_NETWORK_COSMOS_GRPC_WEB_PORT}

injective-exchange-process:
restart: always
logging:
driver: journald
ports:
- ${INJ_EXCHANGE_PROCESS_CHRONOS_RPC_PORT}:${INJ_EXCHANGE_PROCESS_CHRONOS_RPC_PORT}

injective-exchange-api:
restart: always
logging:
driver: journald
ports:
- ${INJ_EXCHANGE_API_CHRONOS_PORT}:${INJ_EXCHANGE_API_CHRONOS_PORT}
- ${INJ_EXCHANGE_GRPC_LISTEN_PORT}:${INJ_EXCHANGE_GRPC_LISTEN_PORT}

injective-exchange-gateway:
restart: always
logging:
driver: journald
ports:
- ${INJ_EXCHANGE_GATEWAY_CHRONOS_PORT_EXPOSED}:${INJ_EXCHANGE_GATEWAY_CHRONOS_PORT}
- ${INJ_EXCHANGE_GATEWAY_HTTP_GATEWAY_LISTEN_PORT}:${INJ_EXCHANGE_GATEWAY_HTTP_GATEWAY_LISTEN_PORT}
- ${INJ_EXCHANGE_GATEWAY_GRPC_PORT_EXPOSED}:${INJ_EXCHANGE_GATEWAY_GRPC_PORT}
Loading

0 comments on commit bb99243

Please sign in to comment.