add compose setup for a bootnode

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2019-03-19 18:35:34 +01:00 committed by Jakub
parent a61c0368bc
commit 2766372eca
4 changed files with 151 additions and 0 deletions

1
.gitignore vendored
View File

@ -69,3 +69,4 @@ Session.vim
# created for running container # created for running container
_assets/compose/mailserver/config.json _assets/compose/mailserver/config.json
_assets/compose/bootnode/keys

View File

@ -0,0 +1,83 @@
GIT_ROOT = $(shell git rev-parse --show-toplevel)
RED := $(shell tput -Txterm setaf 1)
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
RESET := $(shell tput -Txterm sgr0)
BOLD := $(shell tput bold)
UID = $(shell id -u)
GID = $(shell id -g)
# Settings
export LOG_LEVEL ?= 3
export LISTEN_PORT ?= 30303
export RPC_PORT ?= 8545
export API_MODULES ?= eth,net,web3,admin
export CONTAINER_NAME ?= status-go-bootnode
export CONTAINER_IMAGE ?= statusteam/bootnode:latest
export TOOLS_IMAGE ?= ethereum/client-go:alltools-latest
export FLEET_NAME ?= eth.beta
# Necessary to make bootnode available publicly
export PUBLIC_IP ?= $(shell curl -s https://ipecho.net/plain)
all: checks start show info enode
checks:
ifeq (, $(shell which docker-compose))
$(error No $(BOLD)docker-compose$(RESET) in your $$PATH. Please install it)
endif
ifeq (, $(shell which jq))
$(error No $(BOLD)jq$(RESET) in your $$PATH. Please install it)
endif
ifndef PUBLIC_IP
$(error PUBLIC_IP not set! Export it as environment variable)
endif
ifndef CONTAINER_NAME
$(error CONTAINER_NAME not set! Export it as environment variable)
endif
start: keys/nodekey keys/nodeaddr
docker-compose up -d
stop:
docker-compose down
logs:
docker-compose logs -f -t --tail=100
enode: keys/nodeaddr
@echo "enode://$(shell cat keys/nodeaddr)@$(PUBLIC_IP):$(LISTEN_PORT)"
info:
@echo "$(GREEN)Your bootnode is listening on:$(RESET) $(BOLD)$(PUBLIC_IP):$(LISTEN_PORT)$(RESET)"
@echo "$(YELLOW)Make sure that address and port are available from the internet!$(RESET)"
@echo "$(GREEN)Your enode address is:$(RESET)"
keys:
@mkdir -p keys
keys/nodekey: keys ##@ Generate a node key
@docker run --rm \
-u $(UID):$(GID) \
--entrypoint=bootnode \
-v $(PWD)/keys:/keys:rw \
$(TOOLS_IMAGE) \
-genkey=/keys/nodekey
@echo "$(GREEN)Created key for Bootnode: keys/nodekey"
keys/nodeaddr: keys ##@ Save node address for given key
@docker run --rm \
-u $(UID):$(GID) \
--entrypoint=sh \
-v $(PWD)/keys:/keys:rw \
$(TOOLS_IMAGE) \
-c 'bootnode -writeaddress -nodekey=/keys/nodekey > /keys/nodeaddr'
show:
@docker ps --filter='name=$(CONTAINER_NAME)' --format="table {{.ID}}\t{{.Names}}\t{{.Status}}\t{{.Ports}}"
clean:
docker-compose rm -s -f

View File

@ -0,0 +1,52 @@
# Status Bootnode
This folder contains setup for running your own Bootnode.
It uses:
* [Docker Compose](https://docs.docker.com/compose/) for managing the bootnode container.
* [Makefile](https://www.gnu.org/software/make/) to simplify the process for the user.
# Requirements
This Makefile uses two tools: `jq` and `docker-compose`.
# Usage
To simply start a container run `make`, other commands include:
* `make start` - Starts the `status-go-bootnode` container.
* `make stop` - Stops the container.
* `make show` - Shows you current status of the container.
* `make logs` - Shows you logs of the container.
* `make enode` - Shows `enode` address of bootnode.
* `make keys/nodekey` - Creates unique identity for bootnode.
# Settings
All settings are passed through environment variables:
* `PUBLIC_IP` - Your IP visible from the internet and advertised by the Bootnode.
* `LISTEN_PORT` - Bootnode port, by default it's `30303` but you might want to use `443`.
* `RPC_PORT` - Control port making it possible to use the [JSON-RPC API](https://github.com/ethereum/wiki/wiki/JSON-RPC).
* `API_MODULES` - API modules to be made available via the `RPC_PORT`.
* `CONTAINER_NAME` - Name of the container that will be created.
* `LOG_LEVEL` - Set level of log messages to show. (__default:__ `1=ERROR`, `2=WARN`, `3=INFO`, `4=DEBUG`, `5=TRACE`)
# Known Issues
If the discovery of your Public IP does not work please simply export the `PUBLIC_IP` env variable.
You can also set `LISTEN_PORT` to something else to avoid firewall issues.
```bash
$ export PUBLIC_IP=1.2.3.4
$ export LISTEN_PORT=443
$ make
Created key for Bootnode: keys/nodekey
docker-compose up -d
Creating status-go-bootnode ... done
CONTAINER ID NAMES STATUS PORTS
036ca55423c2 status-go-bootnode Up Less than a second 0.0.0.0:30303->30303/tcp
Your bootnode is listening on: 1.2.3.4:30303
Make sure that address and port are available from the internet!
Your enode address is:
enode://2654f0ee4f021cecbfc84d56e7749daa01250f5fd3828989e482b36f9ca13981c83d4c28ad647e4cfec26efa6b8d230075d17fc9c0eb127a7210bd35d27a67a9@1.2.3.4:30303
```

View File

@ -0,0 +1,15 @@
version: "3"
services:
mailserver:
container_name: '${CONTAINER_NAME}'
image: ${CONTAINER_IMAGE}
entrypoint: bootnode
restart: always
command: |
-verbosity=${LOG_LEVEL}
-nodekey=/keys/nodekey
-addr=0.0.0.0:${LISTEN_PORT}
ports:
- '0.0.0.0:${LISTEN_PORT}:${LISTEN_PORT}'
volumes:
- '${PWD}/keys:/keys'