From 56eda11f339260fed3f65788f01451358fe3308d Mon Sep 17 00:00:00 2001 From: inon-man <121477599+inon-man@users.noreply.github.com> Date: Tue, 14 Feb 2023 22:38:11 +0900 Subject: [PATCH] build: localnet for Apple Silicon (#118) --- .github/workflows/test.yml | 2 +- CHANGELOG.md | 2 ++ Makefile | 18 +++++++++--------- app/sim_test.go | 6 +++--- contrib/images/Makefile | 6 ------ contrib/localnet/Makefile | 6 ++++++ contrib/{ => localnet}/localnet_liveness.sh | 2 +- .../{images => localnet}/terrad-env/Dockerfile | 4 ++-- .../terrad-env/entrypoint.sh} | 0 docker-compose.yml | 12 ++++++++---- sims.mk | 4 ++-- 11 files changed, 34 insertions(+), 28 deletions(-) delete mode 100644 contrib/images/Makefile create mode 100644 contrib/localnet/Makefile rename contrib/{ => localnet}/localnet_liveness.sh (94%) rename contrib/{images => localnet}/terrad-env/Dockerfile (76%) rename contrib/{images/terrad-env/wrapper.sh => localnet/terrad-env/entrypoint.sh} (100%) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a699d2e66..939e318da 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -50,5 +50,5 @@ jobs: if: env.GIT_DIFF - name: test liveness run: | - ./contrib/localnet_liveness.sh 100 5 50 localhost + ./contrib/localnet/localnet_liveness.sh 100 3 30 localhost if: env.GIT_DIFF diff --git a/CHANGELOG.md b/CHANGELOG.md index 10752f9a8..13b86578a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ # Changelog ## [Unreleased] +### Features +* (build) [#118](https://github.com/classic-terra/core/pull/118) localnet for Apple Silicon ### Features * (ante) [#103](https://github.com/classic-terra/core/pull/103) Add burn tax split logic diff --git a/Makefile b/Makefile index bc7b67ab3..382653ac9 100755 --- a/Makefile +++ b/Makefile @@ -115,15 +115,15 @@ endif build-linux: mkdir -p $(BUILDDIR) - docker build --no-cache --tag classic-terra/core ./ - docker create --name temp classic-terra/core:latest + docker build --platform linux/amd64 --no-cache --tag classic-terra/core ./ + docker create --platform linux/amd64 --name temp classic-terra/core:latest docker cp temp:/usr/local/bin/terrad $(BUILDDIR)/ docker rm temp build-linux-with-shared-library: mkdir -p $(BUILDDIR) - docker build --tag classic-terra/core-shared ./ -f ./shared.Dockerfile - docker create --name temp classic-terra/core-shared:latest + docker build --platform linux/amd64 --no-cache --tag classic-terra/core-shared ./ -f ./shared.Dockerfile + docker create --platform linux/amd64 --name temp classic-terra/core-shared:latest docker cp temp:/usr/local/bin/terrad $(BUILDDIR)/ docker cp temp:/lib/libwasmvm.so $(BUILDDIR)/ docker rm temp @@ -241,18 +241,18 @@ proto-check-breaking: ############################################################################### # Run a 4-node testnet locally -localnet-start: build-linux localnet-stop - $(if $(shell $(DOCKER) inspect -f '{{ .Id }}' terramoney/terrad-env 2>/dev/null),$(info found image terramoney/terrad-env),$(MAKE) -C contrib/images terrad-env) - if ! [ -f build/node0/terrad/config/genesis.json ]; then $(DOCKER) run --rm \ +localnet-start: localnet-stop build-linux + $(if $(shell $(DOCKER) inspect -f '{{ .Id }}' classic-terra/terrad-env 2>/dev/null),$(info found image classic-terra/terrad-env),$(MAKE) -C contrib/localnet terrad-env) + if ! [ -f build/node0/terrad/config/genesis.json ]; then $(DOCKER) run --platform linux/amd64 --rm \ --user $(shell id -u):$(shell id -g) \ -v $(BUILDDIR):/terrad:Z \ -v /etc/group:/etc/group:ro \ -v /etc/passwd:/etc/passwd:ro \ -v /etc/shadow:/etc/shadow:ro \ - terramoney/terrad-env testnet --v 4 -o . --starting-ip-address 192.168.10.2 --keyring-backend=test ; fi + classic-terra/terrad-env 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: localnet-start localnet-stop \ No newline at end of file +.PHONY: localnet-start localnet-stop diff --git a/app/sim_test.go b/app/sim_test.go index 21b81541b..d75aee755 100644 --- a/app/sim_test.go +++ b/app/sim_test.go @@ -80,8 +80,8 @@ func interBlockCacheOpt() func(*baseapp.BaseApp) { return baseapp.SetInterBlockCache(store.NewCommitKVStoreCacheManager()) } -//// TODO: Make another test for the fuzzer itself, which just has noOp txs -//// and doesn't depend on the application. +// TODO: Make another test for the fuzzer itself, which just has noOp txs +// and doesn't depend on the application. func TestAppStateDeterminism(t *testing.T) { if !simapp.FlagEnabledValue { t.Skip("skipping application simulation") @@ -95,7 +95,7 @@ func TestAppStateDeterminism(t *testing.T) { config.ChainID = helpers.SimAppChainID numSeeds := 3 - numTimesToRunPerSeed := 5 + numTimesToRunPerSeed := 3 appHashList := make([]json.RawMessage, numTimesToRunPerSeed) for i := 0; i < numSeeds; i++ { diff --git a/contrib/images/Makefile b/contrib/images/Makefile deleted file mode 100644 index 98db172c4..000000000 --- a/contrib/images/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -all: terrad-env - -terrad-env: - docker build --build-arg UID=$(shell id -u) --build-arg GID=$(shell id -g) --tag terramoney/terrad-env terrad-env - -.PHONY: all terrad-env diff --git a/contrib/localnet/Makefile b/contrib/localnet/Makefile new file mode 100644 index 000000000..31319c0f5 --- /dev/null +++ b/contrib/localnet/Makefile @@ -0,0 +1,6 @@ +all: terrad-env + +terrad-env: + docker build --platform linux/amd64 --no-cache --build-arg UID=$(shell id -u) --build-arg GID=$(shell id -g) --tag classic-terra/terrad-env terrad-env + +.PHONY: all terrad-env diff --git a/contrib/localnet_liveness.sh b/contrib/localnet/localnet_liveness.sh similarity index 94% rename from contrib/localnet_liveness.sh rename to contrib/localnet/localnet_liveness.sh index 16c45c784..b41b13469 100755 --- a/contrib/localnet_liveness.sh +++ b/contrib/localnet/localnet_liveness.sh @@ -42,7 +42,7 @@ while [ ${CNT} -lt $ITER ]; do # Emulate network chaos: # - # Every 10 blocks, pick a random container and restart it. + # Every 10th iteration, pick a random container and restart it. if ! ((${CNT} % 10)); then rand_container=${docker_containers["$[RANDOM % ${#docker_containers[@]}]"]}; echo "Restarting random docker container ${rand_container}" diff --git a/contrib/images/terrad-env/Dockerfile b/contrib/localnet/terrad-env/Dockerfile similarity index 76% rename from contrib/images/terrad-env/Dockerfile rename to contrib/localnet/terrad-env/Dockerfile index bf70b265f..716363c66 100644 --- a/contrib/images/terrad-env/Dockerfile +++ b/contrib/localnet/terrad-env/Dockerfile @@ -11,8 +11,8 @@ USER ${UID}:${GID} VOLUME /terrad WORKDIR /terrad EXPOSE 26656 26657 -ENTRYPOINT ["/usr/bin/wrapper.sh"] +ENTRYPOINT ["/usr/bin/entrypoint.sh"] CMD ["start", "--log_format", "plain"] STOPSIGNAL SIGTERM -COPY wrapper.sh /usr/bin/wrapper.sh +COPY entrypoint.sh /usr/bin/entrypoint.sh diff --git a/contrib/images/terrad-env/wrapper.sh b/contrib/localnet/terrad-env/entrypoint.sh similarity index 100% rename from contrib/images/terrad-env/wrapper.sh rename to contrib/localnet/terrad-env/entrypoint.sh diff --git a/docker-compose.yml b/docker-compose.yml index b34790803..013e1e8e1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,8 +2,9 @@ version: '3.8' services: terradnode0: + platform: linux/amd64 container_name: terradnode0 - image: "terramoney/terrad-env" + image: classic-terra/terrad-env ports: - "9090:9090" - "26656-26657:26656-26657" @@ -17,8 +18,9 @@ services: ipv4_address: 192.168.10.2 terradnode1: + platform: linux/amd64 container_name: terradnode1 - image: "terramoney/terrad-env" + image: classic-terra/terrad-env ports: - "9091:9090" - "26659-26660:26656-26657" @@ -32,8 +34,9 @@ services: ipv4_address: 192.168.10.3 terradnode2: + platform: linux/amd64 container_name: terradnode2 - image: "terramoney/terrad-env" + image: classic-terra/terrad-env environment: - ID=2 - LOG=$${LOG:-terrad.log} @@ -47,8 +50,9 @@ services: ipv4_address: 192.168.10.4 terradnode3: + platform: linux/amd64 container_name: terradnode3 - image: "terramoney/terrad-env" + image: classic-terra/terrad-env environment: - ID=3 - LOG=$${LOG:-terrad.log} diff --git a/sims.mk b/sims.mk index b38afdef9..b8bc9aa4c 100644 --- a/sims.mk +++ b/sims.mk @@ -8,13 +8,13 @@ SIMAPP = ./app test-sim-nondeterminism: @echo "Running non-determinism test..." @go test -mod=readonly $(SIMAPP) -run TestAppStateDeterminism -Enabled=true \ - -NumBlocks=100 -BlockSize=200 -Commit=true -Period=0 -v -timeout 24h + -NumBlocks=50 -BlockSize=200 -Commit=true -Period=0 -v -timeout 24h test-sim-custom-genesis-fast: @echo "Running custom genesis simulation..." @echo "By default, ${HOME}/.terra/config/genesis.json will be used." @go test -mod=readonly $(SIMAPP) -run TestFullAppSimulation -Genesis=${HOME}/.terra/config/genesis.json \ - -Enabled=true -NumBlocks=100 -BlockSize=200 -Commit=true -Seed=99 -Period=5 -v -timeout 24h + -Enabled=true -NumBlocks=50 -BlockSize=200 -Commit=true -Seed=99 -Period=5 -v -timeout 24h test-sim-import-export: runsim @echo "Running application import/export simulation. This may take several minutes..."