Skip to content

Commit

Permalink
feat: introduce docker localnet again
Browse files Browse the repository at this point in the history
  • Loading branch information
emidev98 committed Mar 20, 2024
1 parent cedcccb commit 3d09eda
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
build/
integration-tests
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# OS
.testnets
.DS_Store
*.swp
*.swo
Expand Down
26 changes: 25 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -299,4 +299,28 @@ format: format-tools
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "*statik*" -not -name '*.pb.go' | xargs misspell -w
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "*statik*" -not -name '*.pb.go' | xargs goimports -w -local github.com/cosmos/cosmos-sdk

.PHONY: lint lint-fix lint-docker format-tools format
.PHONY: lint lint-fix lint-docker format-tools format


###############################################################################
### Local Testnet (docker) ###
###############################################################################

localnet-rmi:
$(DOCKER) rmi terra-money/localnet-core 2>/dev/null; true

localnet-build-env: localnet-rmi
$(DOCKER) build --tag terra-money/localnet-core -f scripts/containers/Dockerfile \
$(shell git rev-parse --show-toplevel)

localnet-build-nodes:
$(DOCKER) run --rm -v $(CURDIR)/.testnets:/terra terra-money/localnet-core \
testnet init-files --v 3 -o /terra --starting-ip-address 192.168.15.20 --keyring-backend=test --chain-id=core-testnet-1
$(DOCKER) compose up -d

localnet-stop:
$(DOCKER) compose down

localnet-start: localnet-stop localnet-build-env localnet-build-nodes

.PHONY: localnet-stop localnet-start localnet-build-env localnet-build-nodes localnet-rmi
5 changes: 4 additions & 1 deletion cmd/terrad/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

"github.com/cosmos/cosmos-sdk/client"

sdkcmd "cosmossdk.io/simapp/simd/cmd"
"github.com/cosmos/cosmos-sdk/client/config"
"github.com/cosmos/cosmos-sdk/client/debug"
"github.com/cosmos/cosmos-sdk/client/flags"
Expand All @@ -34,6 +35,7 @@ import (
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"

wasm "github.com/CosmWasm/wasmd/x/wasm"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
terraapp "github.com/terra-money/core/v2/app"
"github.com/terra-money/core/v2/app/params"
)
Expand Down Expand Up @@ -112,12 +114,13 @@ func initRootCmd(rootCmd *cobra.Command, moduleBasics module.BasicManager, encod
a := appCreator{encodingConfig}

rootCmd.AddCommand(
InitCmd(terraapp.ModuleBasics, terraapp.DefaultNodeHome),
InitCmd(moduleBasics, terraapp.DefaultNodeHome),
config.Cmd(),
tmcli.NewCompletionCmd(rootCmd, true),
debug.Cmd(),
pruning.Cmd(a.newApp, terraapp.DefaultNodeHome),
snapshot.Cmd(a.newApp),
sdkcmd.NewTestnetCmd(moduleBasics, banktypes.GenesisBalancesIterator{}),
)

server.AddCommands(rootCmd, terraapp.DefaultNodeHome, a.newApp, a.appExport, addModuleInitFlags)
Expand Down
76 changes: 76 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
version: "3"

services:
node:
container_name: node
image: "terra-money/localnet-core"
environment:
- DEBUG=1
- ID=0
- LOG=${LOG:-core.log}
cap_add:
- SYS_PTRACE
security_opt:
- seccomp:unconfined
ports:
- "26656-26657:26656-26657"
- "1317:1317"
- "9090:9090"
- "2345:2345"
volumes:
- ./.testnets:/terrad/data:Z
networks:
localnet:
ipv4_address: 192.168.15.20

node_1:
container_name: node_1
image: "terra-money/localnet-core"
environment:
- DEBUG=0
- ID=1
- LOG=${LOG:-core.log}
cap_add:
- SYS_PTRACE
security_opt:
- seccomp:unconfined
ports:
- "26666-26667:26656-26657"
- "1318:1317"
- "9091:9090"
- "2346:2345"
volumes:
- ./.testnets:/terrad/data:Z
networks:
localnet:
ipv4_address: 192.168.15.21

node_2:
container_name: node_2
image: "terra-money/localnet-core"
environment:
- DEBUG=0
- ID=2
- LOG=${LOG:-core.log}
cap_add:
- SYS_PTRACE
security_opt:
- seccomp:unconfined
ports:
- "26676-26677:26656-26657"
- "1319:1317"
- "9092:9090"
- "2347:2345"
volumes:
- ./.testnets:/terrad/data:Z
networks:
localnet:
ipv4_address: 192.168.15.22

networks:
localnet:
driver: bridge
ipam:
driver: default
config:
- subnet: 192.168.15.0/25
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.20
require (
cosmossdk.io/errors v1.0.0
cosmossdk.io/math v1.2.0
cosmossdk.io/simapp v0.0.0-20230608160436-666c345ad23d
cosmossdk.io/tools/rosetta v0.2.1
github.com/CosmWasm/wasmd v0.45.0
github.com/CosmWasm/wasmvm v1.5.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ cosmossdk.io/log v1.2.1 h1:Xc1GgTCicniwmMiKwDxUjO4eLhPxoVdI9vtMW8Ti/uk=
cosmossdk.io/log v1.2.1/go.mod h1:GNSCc/6+DhFIj1aLn/j7Id7PaO8DzNylUZoOYBL9+I4=
cosmossdk.io/math v1.2.0 h1:8gudhTkkD3NxOP2YyyJIYYmt6dQ55ZfJkDOaxXpy7Ig=
cosmossdk.io/math v1.2.0/go.mod h1:l2Gnda87F0su8a/7FEKJfFdJrM0JZRXQaohlgJeyQh0=
cosmossdk.io/simapp v0.0.0-20230608160436-666c345ad23d h1:E/8y0oG3u9hBR8l4F9MtC0LdZIamPCUwUoLlrHrX86I=
cosmossdk.io/simapp v0.0.0-20230608160436-666c345ad23d/go.mod h1:xbjky3L3DJEylaho6gXplkrMvJ5sFgv+qNX+Nn47bzY=
cosmossdk.io/tools/rosetta v0.2.1 h1:ddOMatOH+pbxWbrGJKRAawdBkPYLfKXutK9IETnjYxw=
cosmossdk.io/tools/rosetta v0.2.1/go.mod h1:Pqdc1FdvkNV3LcNIkYWt2RQY6IP1ge6YWZk8MhhO9Hw=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
Expand Down
22 changes: 22 additions & 0 deletions scripts/containers/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM golang:1.20-bullseye AS build

RUN apt update && apt install build-essential -y

WORKDIR /terrad
COPY . /terrad

RUN make build

FROM golang:1.20-bullseye AS run
COPY ./scripts/containers/build-wrapper.sh /terrad/build-wrapper.sh
RUN chmod +x /terrad/build-wrapper.sh
RUN wget https://github.com/CosmWasm/wasmvm/releases/download/v1.5.2/libwasmvm.x86_64.so -P /usr/lib/

VOLUME /terrad
COPY --from=build /terrad/ /terrad/
WORKDIR /terrad

EXPOSE 26656 26657
ENTRYPOINT ["/terrad/build-wrapper.sh"]
CMD ["start", "--log_format", "plain"]
STOPSIGNAL SIGTERM
20 changes: 20 additions & 0 deletions scripts/containers/build-wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env sh
set -x

export PATH=$PATH:/terrad/build/terrad
BINARY=/terrad/build/terrad
ID=${ID:-0}
LOG=${LOG:-terrad.log}

if ! [ -f "${BINARY}" ]; then
echo "The binary $(basename "${BINARY}") cannot be found."
exit 1
fi

export TERRAD_HOME="/terrad/data/node${ID}/simd"

if [ -d "$(dirname "${TERRAD_HOME}"/"${LOG}")" ]; then
"${BINARY}" --home "${TERRAD_HOME}" "$@" | tee "${TERRAD_HOME}/${LOG}"
else
"${BINARY}" --home "${TERRAD_HOME}" "$@"
fi

0 comments on commit 3d09eda

Please sign in to comment.