diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..dacc6297 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +# localnet-setup +localnet-setup + +# build +build \ No newline at end of file diff --git a/.gitignore b/.gitignore index c9d37799..0949de2f 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,9 @@ keyring_test_cosmos secret.yml # vue/ +# Local docker volume mappings +localnet-setup + # Testing coverage.txt *.out diff --git a/Dockerfile b/Dockerfile index 3ef5f575..543769c8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,7 +21,7 @@ FROM alpine # Install ca-certificates RUN apk add --update ca-certificates jq -WORKDIR /root +WORKDIR / # Copy over binaries from the build-env COPY --from=build-env /go/src/github.com/tharsis/ethermint/build/ethermintd /usr/bin/ethermintd diff --git a/Makefile b/Makefile index 539592e8..d44d9393 100755 --- a/Makefile +++ b/Makefile @@ -131,9 +131,6 @@ docker-build: mkdir -p ./build/ docker cp ethermint:/usr/bin/ethermintd ./build/ -docker-localnet: - docker build -f ./networks/local/ethermintnode/Dockerfile . -t ethermintd/node - $(MOCKS_DIR): mkdir -p $(MOCKS_DIR) @@ -477,49 +474,54 @@ proto-update-deps: ### Localnet ### ############################################################################### -# Run a 4-node testnet locally -build-docker-local-ethermint: +# Build image for a local testnet +localnet-build: @$(MAKE) -C networks/local -# Run a 4-node testnet locally +# Start a 4-node testnet locally localnet-start: localnet-stop ifeq ($(OS),Windows_NT) - mkdir build & - @$(MAKE) docker-localnet + mkdir localnet-setup & + @$(MAKE) localnet-build - IF not exist "build/node0/$(ETHERMINT_BINARY)/config/genesis.json" docker run --rm -v $(CURDIR)/build\ethermint\Z ethermintd/node "ethermintd testnet --v 4 -o /ethermint --keyring-backend=test" + IF not exist "build/node0/$(ETHERMINT_BINARY)/config/genesis.json" docker run --rm -v $(CURDIR)/build\ethermint\Z ethermintd/node "./ethermintd testnet --v 4 -o /ethermint --keyring-backend=test --ip-addresses ethermintdnode0,ethermintdnode1,ethermintdnode2,ethermintdnode3" docker-compose up -d else - mkdir -p ./build/ - @$(MAKE) docker-localnet + mkdir -p localnet-setup + @$(MAKE) localnet-build - if ! [ -f build/node0/$(ETHERMINT_BINARY)/config/genesis.json ]; then docker run --rm -v $(CURDIR)/build:/ethermint:Z ethermintd/node "ethermintd testnet --v 4 -o /ethermint --keyring-backend=test"; fi + if ! [ -f localnet-setup/node0/$(ETHERMINT_BINARY)/config/genesis.json ]; then docker run --rm -v $(CURDIR)/localnet-setup:/ethermint:Z ethermintd/node "./ethermintd testnet --v 4 -o /ethermint --keyring-backend=test --ip-addresses ethermintdnode0,ethermintdnode1,ethermintdnode2,ethermintdnode3"; fi docker-compose up -d endif +# Stop testnet localnet-stop: docker-compose down -# clean testnet +# Clean testnet localnet-clean: docker-compose down - sudo rm -rf build/* + sudo rm -rf localnet-setup - # reset testnet + # Reset testnet localnet-unsafe-reset: docker-compose down ifeq ($(OS),Windows_NT) - @docker run --rm -v $(CURDIR)/build\ethermint\Z ethermintd/node "ethermintd unsafe-reset-all --home=/ethermint/node0/ethermintd" - @docker run --rm -v $(CURDIR)/build\ethermint\Z ethermintd/node "ethermintd unsafe-reset-all --home=/ethermint/node1/ethermintd" - @docker run --rm -v $(CURDIR)/build\ethermint\Z ethermintd/node "ethermintd unsafe-reset-all --home=/ethermint/node2/ethermintd" - @docker run --rm -v $(CURDIR)/build\ethermint\Z ethermintd/node "ethermintd unsafe-reset-all --home=/ethermint/node3/ethermintd" + @docker run --rm -v $(CURDIR)\localnet-setup\node0\ethermitd:ethermint\Z ethermintd/node "./ethermintd unsafe-reset-all --home=/ethermint" + @docker run --rm -v $(CURDIR)\localnet-setup\node1\ethermitd:ethermint\Z ethermintd/node "./ethermintd unsafe-reset-all --home=/ethermint" + @docker run --rm -v $(CURDIR)\localnet-setup\node2\ethermitd:ethermint\Z ethermintd/node "./ethermintd unsafe-reset-all --home=/ethermint" + @docker run --rm -v $(CURDIR)\localnet-setup\node3\ethermitd:ethermint\Z ethermintd/node "./ethermintd unsafe-reset-all --home=/ethermint" else - @docker run --rm -v $(CURDIR)/build:/ethermint:Z ethermintd/node "ethermintd unsafe-reset-all --home=/ethermint/node0/ethermintd" - @docker run --rm -v $(CURDIR)/build:/ethermint:Z ethermintd/node "ethermintd unsafe-reset-all --home=/ethermint/node1/ethermintd" - @docker run --rm -v $(CURDIR)/build:/ethermint:Z ethermintd/node "ethermintd unsafe-reset-all --home=/ethermint/node2/ethermintd" - @docker run --rm -v $(CURDIR)/build:/ethermint:Z ethermintd/node "ethermintd unsafe-reset-all --home=/ethermint/node3/ethermintd" + @docker run --rm -v $(CURDIR)/localnet-setup/node0/ethermitd:/ethermint:Z ethermintd/node "./ethermintd unsafe-reset-all --home=/ethermint" + @docker run --rm -v $(CURDIR)/localnet-setup/node1/ethermitd:/ethermint:Z ethermintd/node "./ethermintd unsafe-reset-all --home=/ethermint" + @docker run --rm -v $(CURDIR)/localnet-setup/node2/ethermitd:/ethermint:Z ethermintd/node "./ethermintd unsafe-reset-all --home=/ethermint" + @docker run --rm -v $(CURDIR)/localnet-setup/node3/ethermitd:/ethermint:Z ethermintd/node "./ethermintd unsafe-reset-all --home=/ethermint" endif +# Clean testnet +localnet-show-logstream: + docker-compose logs --tail=1000 -f + .PHONY: build-docker-local-ethermint localnet-start localnet-stop # release diff --git a/docker-compose.yml b/docker-compose.yml index 8622de39..81968f56 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,10 +13,9 @@ services: - ID=0 - LOG=${LOG:-ethermintd.log} volumes: - - ./build:/ethermint:Z + - ./localnet-setup/node0/ethermintd:/ethermint:Z networks: - localnet: - ipv4_address: 192.168.10.2 + - localnet entrypoint: "bash start-docker.sh" ethermintdnode1: @@ -31,10 +30,9 @@ services: - ID=1 - LOG=${LOG:-ethermintd.log} volumes: - - ./build:/ethermint:Z + - ./localnet-setup/node1/ethermintd:/ethermint:Z networks: - localnet: - ipv4_address: 192.168.10.3 + - localnet entrypoint: "bash start-docker.sh" ethermintdnode2: @@ -49,10 +47,9 @@ services: - "8566:8546" - "8127:8125" volumes: - - ./build:/ethermint:Z + - ./localnet-setup/node2/ethermintd:/ethermint:Z networks: - localnet: - ipv4_address: 192.168.10.4 + - localnet entrypoint: "bash start-docker.sh" ethermintdnode3: @@ -67,16 +64,10 @@ services: - "8576:8546" - "8128:8125" volumes: - - ./build:/ethermint:Z + - ./localnet-setup/node3/ethermintd:/ethermint:Z networks: - localnet: - ipv4_address: 192.168.10.5 + - localnet entrypoint: "bash start-docker.sh" networks: localnet: - driver: bridge - ipam: - driver: default - config: - - subnet: 192.168.10.0/16 diff --git a/networks/local/Makefile b/networks/local/Makefile index 0b117de9..1ddf1fdc 100644 --- a/networks/local/Makefile +++ b/networks/local/Makefile @@ -1,4 +1,4 @@ all: - docker build --tag ethermintd/node ethermintnode + docker build --no-cache --tag ethermintd/node ../.. -f ethermintnode/Dockerfile .PHONY: all diff --git a/networks/local/ethermintnode/Dockerfile b/networks/local/ethermintnode/Dockerfile index ced16b97..69d9d89b 100644 --- a/networks/local/ethermintnode/Dockerfile +++ b/networks/local/ethermintnode/Dockerfile @@ -12,7 +12,7 @@ WORKDIR /go/src/github.com/tharsis/ethermint COPY . . # build Ethermint -RUN make build-ethermint-linux +RUN make build-linux # Final image FROM golang:1.14 as final diff --git a/scripts/start-docker.sh b/scripts/start-docker.sh index d66d4feb..6ffa7484 100755 --- a/scripts/start-docker.sh +++ b/scripts/start-docker.sh @@ -1,29 +1,12 @@ #!/bin/bash -KEY="mykey" -CHAINID="ethermint-123" -MONIKER="mymoniker" -DATA_DIR=$(mktemp -d -t ethermint-datadir.XXXXX) - -echo "create and add new keys" -./ethermintd keys add $KEY --home $DATA_DIR --no-backup --chain-id $CHAINID --algo "eth_secp256k1" --keyring-backend test -echo "init Ethermint with moniker=$MONIKER and chain-id=$CHAINID" -./ethermintd init $MONIKER --chain-id $CHAINID --home $DATA_DIR -echo "prepare genesis: Allocate genesis accounts" -./ethermintd add-genesis-account \ -"$(./ethermintd keys show $KEY -a --home $DATA_DIR --keyring-backend test)" 1000000000000000000aphoton,1000000000000000000stake \ ---home $DATA_DIR --keyring-backend test -echo "prepare genesis: Sign genesis transaction" -./ethermintd gentx $KEY 1000000000000000000stake --keyring-backend test --home $DATA_DIR --keyring-backend test --chain-id $CHAINID -echo "prepare genesis: Collect genesis tx" -./ethermintd collect-gentxs --home $DATA_DIR echo "prepare genesis: Run validate-genesis to ensure everything worked and that the genesis file is setup correctly" -./ethermintd validate-genesis --home $DATA_DIR +./ethermintd validate-genesis --home /ethermint -echo "starting ethermint node $i in background ..." -./ethermintd start --pruning=nothing --rpc.unsafe \ ---keyring-backend test --home $DATA_DIR \ ->$DATA_DIR/node.log 2>&1 & disown +echo "starting ethermint node $ID in background ..." +./ethermintd start \ +--home /ethermint \ +--keyring-backend test echo "started ethermint node" tail -f /dev/null \ No newline at end of file