Skip to content

Commit

Permalink
add docker node deployment for old node. docker-compose up -d for sta…
Browse files Browse the repository at this point in the history
…rting 0.4.2 node
  • Loading branch information
nghuyenthevinh2000 committed Aug 2, 2022
1 parent a160ef2 commit 64e54da
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 39 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ genesis/pylonsd
artifacts

cmd/pylonsd/__debug_bin
proto/dart/*
proto/dart/*

debug
43 changes: 38 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
FROM starport/cli
COPY . /app
USER root
EXPOSE $PORT
ENTRYPOINT [ "starport", "chain", "serve", "-p", "/app" ]
FROM golang:1.18-alpine3.16 AS go-builder

RUN set -eux

RUN apk add --no-cache ca-certificates git build-base linux-headers

WORKDIR /code

# Install babyd binary
RUN echo "Installing pylonsd binary"
ADD https://github.com/Pylons-tech/pylons/archive/refs/tags/v0.4.2.tar.gz /code/
RUN tar -xf v0.4.2.tar.gz -C /code/ --strip-components=1
RUN go build -o bin/pylonsd -mod=readonly ./cmd/pylonsd

#-------------------------------------------
FROM golang:1.18-alpine3.16

RUN apk add --no-cache bash py3-pip jq curl
RUN pip install toml-cli

WORKDIR /

COPY --from=go-builder /code/bin/pylonsd /usr/bin/pylonsd
COPY --from=go-builder /code/bin/pylonsd /
COPY scripts/* /
RUN chmod +x /*.sh

# rest server
EXPOSE 1317
# tendermint rpc
EXPOSE 26657
# p2p address
EXPOSE 26656
# gRPC address
EXPOSE 9090

# wrong ENTRYPOINT can lead to executable not running
ENTRYPOINT ["/bin/bash", "test_node_deploy.sh"]
69 changes: 39 additions & 30 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,30 @@ export GO111MODULE = on

build_tags = netgo
ifeq ($(LEDGER_ENABLED),true)
ifeq ($(OS),Windows_NT)
GCCEXE = $(shell where gcc.exe 2> NUL)
ifeq ($(GCCEXE),)
$(error gcc.exe not installed for ledger support, please install or set LEDGER_ENABLED=false)
else
build_tags += ledger
endif
else
UNAME_S = $(shell uname -s)
ifeq ($(UNAME_S),OpenBSD)
$(warning OpenBSD detected, disabling ledger support (https://github.com/cosmos/cosmos-sdk/issues/1988))
else
GCC = $(shell command -v gcc 2> /dev/null)
ifeq ($(GCC),)
$(error gcc not installed for ledger support, please install or set LEDGER_ENABLED=false)
else
build_tags += ledger
endif
endif
endif
ifeq ($(OS),Windows_NT)
GCCEXE = $(shell where gcc.exe 2> NUL)
ifeq ($(GCCEXE),)
$(error gcc.exe not installed for ledger support, please install or set LEDGER_ENABLED=false)
else
build_tags += ledger
endif
else
UNAME_S = $(shell uname -s)
ifeq ($(UNAME_S),OpenBSD)
$(warning OpenBSD detected, disabling ledger support (https://github.com/cosmos/cosmos-sdk/issues/1988))
else
GCC = $(shell command -v gcc 2> /dev/null)
ifeq ($(GCC),)
$(error gcc not installed for ledger support, please install or set LEDGER_ENABLED=false)
else
build_tags += ledger
endif
endif
endif
endif

ifeq (cleveldb,$(findstring cleveldb,$(PYLONS_BUILD_OPTIONS)))
build_tags += gcc
build_tags += gcc
endif
build_tags += $(BUILD_TAGS)
build_tags := $(strip $(build_tags))
Expand All @@ -59,18 +59,18 @@ ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=pylons \


ifeq (cleveldb,$(findstring cleveldb,$(PYLONS_BUILD_OPTIONS)))
ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=cleveldb
ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=cleveldb
endif
ifeq (,$(findstring nostrip,$(PYLONS_BUILD_OPTIONS)))
ldflags += -w -s
ldflags += -w -s
endif
ldflags += $(LDFLAGS)
ldflags := $(strip $(ldflags))

BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)'
# check for nostrip option
ifeq (,$(findstring nostrip,$(PYLONS_BUILD_OPTIONS)))
BUILD_FLAGS += -trimpath
BUILD_FLAGS += -trimpath
endif

# The below include contains the tools target.
Expand All @@ -96,12 +96,12 @@ build-linux: go.sum
build-reproducible: go.sum
$(DOCKER) rm latest-build || true
$(DOCKER) run --volume=$(CURDIR):/sources:ro \
--env TARGET_PLATFORMS='linux/amd64 darwin/amd64 linux/arm6' \
--env APP=pylonsd \
--env VERSION=$(VERSION) \
--env COMMIT=$(COMMIT) \
--env LEDGER_ENABLED=$(LEDGER_ENABLED) \
--name latest-build cosmossdk/rbuilder:latest
--env TARGET_PLATFORMS='linux/amd64 darwin/amd64 linux/arm6' \
--env APP=pylonsd \
--env VERSION=$(VERSION) \
--env COMMIT=$(COMMIT) \
--env LEDGER_ENABLED=$(LEDGER_ENABLED) \
--name latest-build cosmossdk/rbuilder:latest
$(DOCKER) cp -a latest-build:/home/builder/artifacts/ $(CURDIR)/

clean:
Expand Down Expand Up @@ -249,3 +249,12 @@ proto-lint:


.PHONY: lint format proto-lint


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

# Build image for a local testnet
localnet-build:
docker build -f Dockerfile -t pylons-node .
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: '3'

services:
node0:
container_name: pylonsnode0
image: "pylons-node"
ports:
- "26657:26657"
- "1317:1317"
volumes:
- ./debug:/debug
24 changes: 21 additions & 3 deletions scripts/test_node_deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ LOGLEVEL="info"

rm -rf ~/.pylon*
# retrieve all args
WILL_START_FRESH=0
WILL_RECOVER=0
WILL_INSTALL=0
WILL_CONTINUE=0
Expand All @@ -18,6 +19,10 @@ then
# $@ is for getting list of arguments
for arg in "$@"; do
case $arg in
--fresh)
WILL_START_FRESH=1
shift
;;
--recover)
WILL_RECOVER=1
shift
Expand Down Expand Up @@ -48,6 +53,11 @@ fi
# validate dependencies are installed
command -v jq > /dev/null 2>&1 || { echo >&2 "jq not installed. More info: https://stedolan.github.io/jq/download/"; exit 1; }

if [ $WILL_START_FRESH -eq 1 ];
then
rm -rf $HOME/.pylons*
fi

# install pylonsd if not exist
if [ $WILL_INSTALL -eq 0 ];
then
Expand All @@ -62,11 +72,15 @@ pylonsd config keyring-backend $KEYRING
pylonsd config chain-id $CHAINID

# determine if user wants to recorver or create new
rm debug/keys.txt

if [ $WILL_RECOVER -eq 0 ];
then
pylonsd keys add $KEY --keyring-backend $KEYRING --algo $KEYALGO
KEY_INFO=$(pylonsd keys add $KEY --keyring-backend $KEYRING --algo $KEYALGO)
echo $KEY_INFO >> debug/keys.txt
else
pylonsd keys add $KEY --keyring-backend $KEYRING --algo $KEYALGO --recover
KEY_INFO=$(pylonsd keys add $KEY --keyring-backend $KEYRING --algo $KEYALGO --recover)
echo $KEY_INFO >> debug/keys.txt
fi

echo >&1 "\n"
Expand All @@ -83,6 +97,10 @@ cat $HOME/.pylons/config/genesis.json | jq '.app_state["mint"]["params"]["mint_d
# Set gas limit in genesis
# cat $HOME/.pylons/config/genesis.json | jq '.consensus_params["block"]["max_gas"]="10000000"' > $HOME/.pylons/config/tmp_genesis.json && mv $HOME/.pylons/config/tmp_genesis.json $HOME/.pylons/config/genesis.json

# enable rest server and swagger
toml set --toml-path $HOME/.pylons/config/app.toml api.swagger true
toml set --toml-path $HOME/.pylons/config/app.toml api.enable true

# Allocate genesis accounts (cosmos formatted addresses)
pylonsd add-genesis-account $KEY 1000000000000upylon --keyring-backend $KEYRING

Expand All @@ -96,4 +114,4 @@ pylonsd collect-gentxs
pylonsd validate-genesis

# Start the node (remove the --pruning=nothing flag if historical queries are not needed)
pylonsd start --pruning=nothing --log_level $LOGLEVEL --minimum-gas-prices=0.0001upylon
pylonsd start --pruning=nothing --log_level $LOGLEVEL --minimum-gas-prices=0.0001upylon --rpc.laddr tcp://0.0.0.0:26657

0 comments on commit 64e54da

Please sign in to comment.