github.com/status-im/status-go@v1.1.0/_assets/compose/bootnode/Makefile (about)

     1  export GIT_ROOT = $(shell git rev-parse --show-toplevel)
     2  # Useful for showing enode address
     3  PUBLIC_IP ?= $(shell curl -s https://ipecho.net/plain)
     4  
     5  RED := $(shell tput -Txterm setaf 1)
     6  GRN := $(shell tput -Txterm setaf 2)
     7  YLW := $(shell tput -Txterm setaf 3)
     8  RST := $(shell tput -Txterm sgr0)
     9  BLD := $(shell tput bold)
    10  
    11  UID = $(shell id -u)
    12  GID = $(shell id -g)
    13  
    14  # Settings
    15  export CONTAINER_TAG  ?= v0.64.3
    16  export CONTAINER_IMG  ?= statusteam/bootnode
    17  export CONTAINER_NAME ?= status-go-bootnode
    18  export LOG_LEVEL      ?= 3
    19  export LISTEN_PORT    ?= 30301
    20  export API_MODULES    ?= eth,web3,admin
    21  
    22  NODE_ADDR  = $(shell cat keys/nodeaddr)
    23  ENODE_ADDR = enode://$(NODE_ADDR)@$(PUBLIC_IP):$(LISTEN_PORT)
    24  
    25  define INFO_MSG
    26   * $(GRN)Your bootnode is listening on:$(RST) $(BLD)$(PUBLIC_IP):$(LISTEN_PORT)$(RST)
    27   * $(GRN)Your enode address is:$(RST)
    28  $(ENODE_ADDR)
    29  
    30  $(YLW)Make sure that address and UDP port are available from the internet!$(RST)
    31  
    32  endef
    33  export INFO_MSG
    34  
    35  all: checks start show info enode-qr
    36  
    37  checks:
    38  ifeq (, $(shell which docker))
    39  	$(error $(RED)No 'docker' in your $$PATH. Please install it$(RST))
    40  endif
    41  ifeq (, $(shell docker version | grep Server))
    42  	$(error $(RED)No permissions to run 'docker'. Add yourself to docker group$(RST))
    43  endif
    44  ifeq (, $(shell which docker-compose))
    45  	$(error $(RED)No 'docker-compose' in your $$PATH. Please install it$(RST))
    46  endif
    47  ifeq (, $(shell which jq))
    48  	$(error $(RED)No 'jq' in your $$PATH. Please install it$(RST))
    49  endif
    50  ifndef PUBLIC_IP
    51  	$(error $(RED)$$PUBLIC_IP not set! Export it as environment variable$(RST))
    52  endif
    53  ifndef CONTAINER_NAME
    54  	$(error $(RED)$$CONTAINER_NAME not set! Export it as environment variable$(RST))
    55  endif
    56  
    57  enode: keys/nodeaddr
    58  	@echo $(ENODE_ADDR)
    59  
    60  enode-qr: keys/nodeaddr
    61  	@qrencode -t UTF8 $(ENODE_ADDR)
    62  
    63  logs: LOG_LINES ?= 100
    64  logs:
    65  	docker-compose logs -f -t --tail=$(LOG_LINES)
    66  
    67  info:
    68  	@echo "$$INFO_MSG"
    69  
    70  keys:
    71  	@mkdir -p keys
    72  
    73  start: keys/nodekey keys/nodeaddr
    74  	@echo " * $(GRN)Starting '$(CONTAINER_NAME)' container...$(RST)"
    75  	docker-compose $(COMPOSE_UP_FLAGS) up -d
    76  
    77  stop:
    78  	@echo " * $(YLW)Stopping '$(CONTAINER_NAME)' container...$(RST)"
    79  	docker-compose down
    80  
    81  keys/nodekey: keys ##@ Generate a node key
    82  	@echo " * $(GRN)Generating '$(CONTAINER_NAME)' keys...$(RST)"
    83  	@docker run --rm \
    84  		-u $(UID):$(GID) \
    85  		--entrypoint=bootnode \
    86  		-v $(PWD)/keys:/keys:rw \
    87  		$(CONTAINER_IMG) \
    88  		-genkey=/keys/nodekey
    89  	@echo " * $(GRN)Created key for Bootnode: keys/nodekey$(RST)"
    90  
    91  keys/nodeaddr: keys ##@ Save node address for given key
    92  	@echo " * $(GRN)Saving '$(CONTAINER_NAME)' enode address...$(RST)"
    93  	@docker run --rm \
    94  		-u $(UID):$(GID) \
    95  		--entrypoint=sh \
    96  		-v $(PWD)/keys:/keys:rw \
    97  		$(CONTAINER_IMG) \
    98  		-c 'bootnode -writeaddress -nodekey=/keys/nodekey > /keys/nodeaddr'
    99  
   100  show:
   101  	@docker ps --filter='name=$(CONTAINER_NAME)' --format="table {{.ID}}\t{{.Names}}\t{{.Status}}\t{{.Ports}}"
   102  
   103  clean:
   104  	docker-compose rm -s -f