diff --git a/Makefile b/Makefile index a8c061e15e..19378e89c5 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,8 @@ VERSION := $(shell echo $(shell git describe --tags) | sed 's/^v//') COMMIT := $(shell git log -1 --format='%H') +export PROJECT_HOME=$(shell git rev-parse --show-toplevel) +export GO_PKG_PATH=$(HOME)/go/pkg export GO111MODULE = on # process build tags @@ -87,3 +89,41 @@ build: clean: rm -rf ./build + +############################################################################### +### Local testing using docker container ### +############################################################################### +# To start a 4-node cluster from scratch: +# make clean && make build-linux && make localnet-start +############################################################################### + + +# Build linux binary on other platforms +# TODO: Support cross compile from Mac OS to Linux platforms +build-linux: + GOOS=linux GOARCH=amd64 CGO_ENABLED=1 make build +.PHONY: build-linux + +# Build docker image +build-docker-localnode: + @cd docker && docker build --tag sei-chain/localnode localnode +.PHONY: build-docker-localnode + +# Run a single docker container +run-docker-localnode: + docker run --rm \ + -v $(PROJECT_HOME)/build:/sei-protocol/sei-chain/build:Z \ + -v $(PROJECT_HOME)/x/nitro:$(PROJECT_HOME)/x/nitro:Z \ + -v $(GO_PKG_PATH)/mod:$(GO_PKG_PATH)/mod:Z \ + sei-chain/localnode +.PHONY: run-docker-localnode + +# Run a 4-node docker containers +localnet-start: localnet-stop build-docker-localnode + @cd docker && docker-compose up +.PHONY: localnet-start + +# Stop 4-node docker containers +localnet-stop: + @cd docker && docker-compose down +.PHONY: localnet-stop \ No newline at end of file diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 0000000000..b7c862fbec --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,71 @@ +version: '3.3' + +services: + node0: + container_name: sei-node0 + image: "sei-chain/localnode" + ports: + - "26656-26657:26656-26657" + environment: + - ID=0 + volumes: + - "${PROJECT_HOME}/build:/sei-protocol/sei-chain/build:Z" + - "${PROJECT_HOME}/x/nitro:${PROJECT_HOME}/x/nitro:Z" + - "${GO_PKG_PATH}/mod:${GO_PKG_PATH}/mod:Z" + networks: + localnet: + ipv4_address: 192.168.10.2 + + node1: + container_name: sei-node1 + image: "sei-chain/localnode" + ports: + - "26659-26660:26656-26657" + environment: + - ID=1 + volumes: + - "${PROJECT_HOME}/build:/sei-protocol/sei-chain/build:Z" + - "${PROJECT_HOME}/x/nitro:${PROJECT_HOME}/x/nitro:Z" + - "${GO_PKG_PATH}/mod:${GO_PKG_PATH}/mod:Z" + networks: + localnet: + ipv4_address: 192.168.10.3 + + node2: + container_name: sei-node2 + image: "sei-chain/localnode" + environment: + - ID=2 + ports: + - "26661-26662:26656-26657" + volumes: + - "${PROJECT_HOME}/build:/sei-protocol/sei-chain/build:Z" + - "${PROJECT_HOME}/x/nitro:${PROJECT_HOME}/x/nitro:Z" + - "${GO_PKG_PATH}/mod:${GO_PKG_PATH}/mod:Z" + networks: + localnet: + ipv4_address: 192.168.10.4 + + node3: + container_name: sei-node3 + image: "sei-chain/localnode" + environment: + - ID=3 + ports: + - "26663-26664:26656-26657" + volumes: + - "${PROJECT_HOME}/build:/sei-protocol/sei-chain/build:Z" + - "${PROJECT_HOME}/x/nitro:${PROJECT_HOME}/x/nitro:Z" + - "${GO_PKG_PATH}/mod:${GO_PKG_PATH}/mod:Z" + networks: + localnet: + ipv4_address: 192.168.10.5 + +networks: + localnet: + driver: bridge + ipam: + driver: default + config: + - + subnet: 192.168.10.0/16 \ No newline at end of file diff --git a/docker/localnode/Dockerfile b/docker/localnode/Dockerfile new file mode 100644 index 0000000000..22be98a939 --- /dev/null +++ b/docker/localnode/Dockerfile @@ -0,0 +1,14 @@ +FROM ubuntu:latest +RUN apt-get update && \ + apt-get install -y make + +VOLUME [ /sei-protocol ] +WORKDIR /sei-protocol/sei-chain + +EXPOSE 26656 26657 + +CMD ["/usr/bin/init.sh"] + +STOPSIGNAL SIGTERM + +COPY init.sh /usr/bin/init.sh \ No newline at end of file diff --git a/docker/localnode/init.sh b/docker/localnode/init.sh new file mode 100755 index 0000000000..5f778417b8 --- /dev/null +++ b/docker/localnode/init.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env sh + +# Input parameters +NODE_ID=${ID:-0} + +# Greeting output +echo "hello-sei" + +# Uncomment the below line if there are any dependency issues +# ldd build/seid + +# Testing whether seid works or not +./build/seid version + +# TODO: Add sei-chain initialization logic \ No newline at end of file