build: fix docker setup (#337)

* fix: issue #310

- add ip-addresses for localnet-setup generation
- add localnet-setup folder to keep localnet-setup-artifacts
- map localnet-setup-artifacts to containers
- change start-docker.sh to pick up generated testnet artifacts

* feat: get rid of explicit ip-address-assignments for containers

* feat: get rid of docker-localnet, introduce localnet-build and localnet-show-logstream, fix localnet-unsafe-reset and localnet-clean, add comments

* fix: add --no-cache on docker build, exclude build-directory
This commit is contained in:
Simon Pfeifhofer 2021-08-04 11:30:13 +02:00 committed by GitHub
parent 396db9f20a
commit 300af0df0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 49 additions and 65 deletions

5
.dockerignore Normal file
View File

@ -0,0 +1,5 @@
# localnet-setup
localnet-setup
# build
build

3
.gitignore vendored
View File

@ -36,6 +36,9 @@ keyring_test_cosmos
secret.yml secret.yml
# vue/ # vue/
# Local docker volume mappings
localnet-setup
# Testing # Testing
coverage.txt coverage.txt
*.out *.out

View File

@ -21,7 +21,7 @@ FROM alpine
# Install ca-certificates # Install ca-certificates
RUN apk add --update ca-certificates jq RUN apk add --update ca-certificates jq
WORKDIR /root WORKDIR /
# Copy over binaries from the build-env # Copy over binaries from the build-env
COPY --from=build-env /go/src/github.com/tharsis/ethermint/build/ethermintd /usr/bin/ethermintd COPY --from=build-env /go/src/github.com/tharsis/ethermint/build/ethermintd /usr/bin/ethermintd

View File

@ -131,9 +131,6 @@ docker-build:
mkdir -p ./build/ mkdir -p ./build/
docker cp ethermint:/usr/bin/ethermintd ./build/ docker cp ethermint:/usr/bin/ethermintd ./build/
docker-localnet:
docker build -f ./networks/local/ethermintnode/Dockerfile . -t ethermintd/node
$(MOCKS_DIR): $(MOCKS_DIR):
mkdir -p $(MOCKS_DIR) mkdir -p $(MOCKS_DIR)
@ -477,49 +474,54 @@ proto-update-deps:
### Localnet ### ### Localnet ###
############################################################################### ###############################################################################
# Run a 4-node testnet locally # Build image for a local testnet
build-docker-local-ethermint: localnet-build:
@$(MAKE) -C networks/local @$(MAKE) -C networks/local
# Run a 4-node testnet locally # Start a 4-node testnet locally
localnet-start: localnet-stop localnet-start: localnet-stop
ifeq ($(OS),Windows_NT) ifeq ($(OS),Windows_NT)
mkdir build & mkdir localnet-setup &
@$(MAKE) docker-localnet @$(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 docker-compose up -d
else else
mkdir -p ./build/ mkdir -p localnet-setup
@$(MAKE) docker-localnet @$(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 docker-compose up -d
endif endif
# Stop testnet
localnet-stop: localnet-stop:
docker-compose down docker-compose down
# clean testnet # Clean testnet
localnet-clean: localnet-clean:
docker-compose down docker-compose down
sudo rm -rf build/* sudo rm -rf localnet-setup
# reset testnet # Reset testnet
localnet-unsafe-reset: localnet-unsafe-reset:
docker-compose down docker-compose down
ifeq ($(OS),Windows_NT) 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)\localnet-setup\node0\ethermitd:ethermint\Z ethermintd/node "./ethermintd unsafe-reset-all --home=/ethermint"
@docker run --rm -v $(CURDIR)/build\ethermint\Z ethermintd/node "ethermintd unsafe-reset-all --home=/ethermint/node1/ethermintd" @docker run --rm -v $(CURDIR)\localnet-setup\node1\ethermitd:ethermint\Z ethermintd/node "./ethermintd unsafe-reset-all --home=/ethermint"
@docker run --rm -v $(CURDIR)/build\ethermint\Z ethermintd/node "ethermintd unsafe-reset-all --home=/ethermint/node2/ethermintd" @docker run --rm -v $(CURDIR)\localnet-setup\node2\ethermitd:ethermint\Z ethermintd/node "./ethermintd unsafe-reset-all --home=/ethermint"
@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\node3\ethermitd:ethermint\Z ethermintd/node "./ethermintd unsafe-reset-all --home=/ethermint"
else else
@docker run --rm -v $(CURDIR)/build:/ethermint:Z ethermintd/node "ethermintd unsafe-reset-all --home=/ethermint/node0/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)/build:/ethermint:Z ethermintd/node "ethermintd unsafe-reset-all --home=/ethermint/node1/ethermintd" @docker run --rm -v $(CURDIR)/localnet-setup/node1/ethermitd:/ethermint:Z ethermintd/node "./ethermintd unsafe-reset-all --home=/ethermint"
@docker run --rm -v $(CURDIR)/build:/ethermint:Z ethermintd/node "ethermintd unsafe-reset-all --home=/ethermint/node2/ethermintd" @docker run --rm -v $(CURDIR)/localnet-setup/node2/ethermitd:/ethermint:Z ethermintd/node "./ethermintd unsafe-reset-all --home=/ethermint"
@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/node3/ethermitd:/ethermint:Z ethermintd/node "./ethermintd unsafe-reset-all --home=/ethermint"
endif endif
# Clean testnet
localnet-show-logstream:
docker-compose logs --tail=1000 -f
.PHONY: build-docker-local-ethermint localnet-start localnet-stop .PHONY: build-docker-local-ethermint localnet-start localnet-stop
# release # release

View File

@ -13,10 +13,9 @@ services:
- ID=0 - ID=0
- LOG=${LOG:-ethermintd.log} - LOG=${LOG:-ethermintd.log}
volumes: volumes:
- ./build:/ethermint:Z - ./localnet-setup/node0/ethermintd:/ethermint:Z
networks: networks:
localnet: - localnet
ipv4_address: 192.168.10.2
entrypoint: "bash start-docker.sh" entrypoint: "bash start-docker.sh"
ethermintdnode1: ethermintdnode1:
@ -31,10 +30,9 @@ services:
- ID=1 - ID=1
- LOG=${LOG:-ethermintd.log} - LOG=${LOG:-ethermintd.log}
volumes: volumes:
- ./build:/ethermint:Z - ./localnet-setup/node1/ethermintd:/ethermint:Z
networks: networks:
localnet: - localnet
ipv4_address: 192.168.10.3
entrypoint: "bash start-docker.sh" entrypoint: "bash start-docker.sh"
ethermintdnode2: ethermintdnode2:
@ -49,10 +47,9 @@ services:
- "8566:8546" - "8566:8546"
- "8127:8125" - "8127:8125"
volumes: volumes:
- ./build:/ethermint:Z - ./localnet-setup/node2/ethermintd:/ethermint:Z
networks: networks:
localnet: - localnet
ipv4_address: 192.168.10.4
entrypoint: "bash start-docker.sh" entrypoint: "bash start-docker.sh"
ethermintdnode3: ethermintdnode3:
@ -67,16 +64,10 @@ services:
- "8576:8546" - "8576:8546"
- "8128:8125" - "8128:8125"
volumes: volumes:
- ./build:/ethermint:Z - ./localnet-setup/node3/ethermintd:/ethermint:Z
networks: networks:
localnet: - localnet
ipv4_address: 192.168.10.5
entrypoint: "bash start-docker.sh" entrypoint: "bash start-docker.sh"
networks: networks:
localnet: localnet:
driver: bridge
ipam:
driver: default
config:
- subnet: 192.168.10.0/16

View File

@ -1,4 +1,4 @@
all: all:
docker build --tag ethermintd/node ethermintnode docker build --no-cache --tag ethermintd/node ../.. -f ethermintnode/Dockerfile
.PHONY: all .PHONY: all

View File

@ -12,7 +12,7 @@ WORKDIR /go/src/github.com/tharsis/ethermint
COPY . . COPY . .
# build Ethermint # build Ethermint
RUN make build-ethermint-linux RUN make build-linux
# Final image # Final image
FROM golang:1.14 as final FROM golang:1.14 as final

View File

@ -1,29 +1,12 @@
#!/bin/bash #!/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" 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 ..." echo "starting ethermint node $ID in background ..."
./ethermintd start --pruning=nothing --rpc.unsafe \ ./ethermintd start \
--keyring-backend test --home $DATA_DIR \ --home /ethermint \
>$DATA_DIR/node.log 2>&1 & disown --keyring-backend test
echo "started ethermint node" echo "started ethermint node"
tail -f /dev/null tail -f /dev/null