Skip to content

Commit

Permalink
Simapp Localnet (#6421)
Browse files Browse the repository at this point in the history
* Setup localnet

* Fix compose

* Fix file perms

* Fix build

* Codec + lint updates

* lint++
  • Loading branch information
alexanderbez authored Jun 12, 2020
1 parent 14e3aa1 commit 7871910
Show file tree
Hide file tree
Showing 15 changed files with 546 additions and 22 deletions.
24 changes: 21 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ build-sim: go.sum
go build -mod=readonly $(BUILD_FLAGS) -o $(BUILDDIR) ./simapp/cmd/simd
go build -mod=readonly $(BUILD_FLAGS) -o $(BUILDDIR) ./simapp/cmd/simcli

.PHONY: \
build \
build-sim
build-sim-linux: go.sum
LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 $(MAKE) build-sim

.PHONY: build build-sim build-sim-linux

mocks: $(MOCKS_DIR)
mockgen -source=client/account_retriever.go -package mocks -destination tests/mocks/account_retriever.go
Expand Down Expand Up @@ -308,3 +309,20 @@ proto-update-deps:


.PHONY: proto-all proto-gen proto-lint proto-check-breaking proto-update-deps

###############################################################################
### Localnet ###
###############################################################################

build-docker-local-simapp:
@$(MAKE) -C networks/local

# Run a 4-node testnet locally
localnet-start: build-sim-linux localnet-stop
@if ! [ -f build/node0/simd/config/genesis.json ]; then docker run --rm -v $(CURDIR)/build:/simd:Z cosmos-sdk/simappnode testnet --v 4 -o . --starting-ip-address 192.168.10.2 --keyring-backend=test ; fi
docker-compose up -d

localnet-stop:
docker-compose down

.PHONY: build-docker-local-simapp localnet-start localnet-stop
5 changes: 2 additions & 3 deletions codec/legacy/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import (
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
)

//nolint:stylecheck // ignore linting of comment
// Deprecated: Cdc defines a global generic sealed Amino codec to be used throughout sdk. It
// Cdc defines a global generic sealed Amino codec to be used throughout sdk. It
// has all Tendermint crypto and evidence types registered.
//
// TODO: remove this global.
// TODO: Deprecated - remove this global.
var Cdc *codec.Codec

func init() {
Expand Down
67 changes: 67 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
version: '3'

services:
simdnode0:
container_name: simdnode0
image: "cosmos-sdk/simappnode"
ports:
- "26656-26657:26656-26657"
environment:
- ID=0
- LOG=${LOG:-simd.log}
volumes:
- ./build:/simd:Z
networks:
localnet:
ipv4_address: 192.168.10.2

simdnode1:
container_name: simdnode1
image: "cosmos-sdk/simappnode"
ports:
- "26659-26660:26656-26657"
environment:
- ID=1
- LOG=${LOG:-simd.log}
volumes:
- ./build:/simd:Z
networks:
localnet:
ipv4_address: 192.168.10.3

simdnode2:
container_name: simdnode2
image: "cosmos-sdk/simappnode"
environment:
- ID=2
- LOG=${LOG:-simd.log}
ports:
- "26661-26662:26656-26657"
volumes:
- ./build:/simd:Z
networks:
localnet:
ipv4_address: 192.168.10.4

simdnode3:
container_name: simdnode3
image: "cosmos-sdk/simappnode"
environment:
- ID=3
- LOG=${LOG:-simd.log}
ports:
- "26663-26664:26656-26657"
volumes:
- ./build:/simd:Z
networks:
localnet:
ipv4_address: 192.168.10.5

networks:
localnet:
driver: bridge
ipam:
driver: default
config:
-
subnet: 192.168.10.0/16
4 changes: 4 additions & 0 deletions networks/local/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
all:
docker build --tag cosmos-sdk/simappnode simappnode

.PHONY: all
23 changes: 23 additions & 0 deletions networks/local/simappnode/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#FROM alpine:3.10.2
#
#RUN apk update && \
# apk upgrade && \
# apk --no-cache add curl jq file

# Changed from Alpine to Ubuntu because the keyring PR is linking to libc
# Alpine uses muslc instead of libc

FROM ubuntu:18.04

RUN apt-get update && \
apt-get -y upgrade && \
apt-get -y install curl jq file

VOLUME [ /simd ]
WORKDIR /simd
EXPOSE 26656 26657
ENTRYPOINT ["/usr/bin/wrapper.sh"]
CMD ["start"]
STOPSIGNAL SIGTERM

COPY wrapper.sh /usr/bin/wrapper.sh
25 changes: 25 additions & 0 deletions networks/local/simappnode/wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env sh

BINARY=/simd/${BINARY:-simd}
ID=${ID:-0}
LOG=${LOG:-simd.log}

if ! [ -f "${BINARY}" ]; then
echo "The binary $(basename "${BINARY}") cannot be found. Please add the binary to the shared folder. Please use the BINARY environment variable if the name of the binary is not 'simd'"
exit 1
fi

BINARY_CHECK="$(file "$BINARY" | grep 'ELF 64-bit LSB executable, x86-64')"

if [ -z "${BINARY_CHECK}" ]; then
echo "Binary needs to be OS linux, ARCH amd64"
exit 1
fi

export SIMDHOME="/simd/node${ID}/simd"

if [ -d "$(dirname "${SIMDHOME}"/"${LOG}")" ]; then
"${BINARY}" --home "${SIMDHOME}" "$@" | tee "${SIMDHOME}/${LOG}"
else
"${BINARY}" --home "${SIMDHOME}" "$@"
fi
2 changes: 1 addition & 1 deletion simapp/cmd/simd/genaccounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const (

// AddGenesisAccountCmd returns add-genesis-account cobra Command.
func AddGenesisAccountCmd(
ctx *server.Context, depCdc *codec.Codec, cdc *std.Codec, defaultNodeHome, defaultClientHome string,
ctx *server.Context, depCdc codec.JSONMarshaler, cdc *std.Codec, defaultNodeHome, defaultClientHome string,
) *cobra.Command {

cmd := &cobra.Command{
Expand Down
1 change: 1 addition & 0 deletions simapp/cmd/simd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func main() {
genutilcli.ValidateGenesisCmd(ctx, cdc, simapp.ModuleBasics),
AddGenesisAccountCmd(ctx, cdc, appCodec, simapp.DefaultNodeHome, simapp.DefaultCLIHome),
flags.NewCompletionCmd(rootCmd, true),
testnetCmd(ctx, cdc, simapp.ModuleBasics, bank.GenesisBalancesIterator{}),
debug.Cmd(cdc))

server.AddCommands(ctx, cdc, rootCmd, newApp, exportAppStateAndTMValidators)
Expand Down
Loading

0 comments on commit 7871910

Please sign in to comment.