Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add localnet docker support #70

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions localnet/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
FROM ubuntu:20.04

RUN apt-get update && apt-get install -y git build-essential wget
RUN wget https://github.com/mikefarah/yq/releases/download/v4.9.3/yq_linux_amd64 -O /usr/bin/yq && chmod +x /usr/bin/yq

COPY install-golang.sh install-golang.sh

RUN sh install-golang.sh

ENV GOROOT /usr/local/go
ENV GOPATH /go
ENV GOBIN /go/bin
ENV PATH $GOBIN:$GOROOT/bin:$PATH

RUN git clone https://github.com/bitsongofficial/go-bitsong

WORKDIR /go-bitsong

# Change the commit hash if you want.
RUN git fetch && git checkout testnet

# Build daemon.
RUN make build

WORKDIR /go-bitsong/build

RUN ./bitsongd init localnet --chain-id localnet-1

# configurations
RUN sed -i 's#tcp://127.0.0.1:26657#tcp://0.0.0.0:26657#g' ~/.bitsongd/config/config.toml
RUN sed -i 's/cors_allowed_origins = \[\]/cors_allowed_origins = \["*"\]/g' ~/.bitsongd/config/config.toml
RUN sed -i 's/timeout_commit = "5s"/timeout_commit = "1s"/g' ~/.bitsongd/config/config.toml
RUN sed -i 's/seeds = ".*"/seeds = ""/g' ~/.bitsongd/config/config.toml
RUN sed -i 's/"stake"/"ubtsg"/g' ~/.bitsongd/config/genesis.json
RUN sed -i 's/pruning = "default"/pruning = "nothing"/g' ~/.bitsongd/config/app.toml
RUN sed -i 's/enable = false/enable = true/g' ~/.bitsongd/config/app.toml
RUN sed -i 's/swagger = false/swagger = true/g' ~/.bitsongd/config/app.toml
RUN sed -i 's/enabled-unsafe-cors = false/enabled-unsafe-cors = true/g' ~/.bitsongd/config/app.toml
RUN sed -i 's/"voting_period": "172800s"/"voting_period": "300s"/g' ~/.bitsongd/config/genesis.json

RUN echo "memory fault antenna oppose warfare mutual clap fossil earth solution matrix feel alley tired mix oppose melt plug marriage fiber pride hint cheap hand" | ./bitsongd keys add validator --recover --keyring-backend test
RUN echo "silk cricket salt museum voice unable unaware piece excess blue crawl juice soda during learn arrange amused pony excess float grit manage notice dinner" | ./bitsongd keys add user1 --recover --keyring-backend test
RUN echo "expose drastic inhale gain match pause alter drift across cluster sorry oven capital river wolf used soccer slim twelve wheel notice focus put dad" | ./bitsongd keys add user2 --recover --keyring-backend test
RUN echo "gap wave quantum merge online sausage process grow upset fossil capital high alcohol cost mansion oak truck like ask cancel random bachelor odor rich" | ./bitsongd keys add user3 --recover --keyring-backend test

RUN ./bitsongd add-genesis-account $(./bitsongd keys show validator -a --keyring-backend test) 1000000000000ubtsg
RUN ./bitsongd add-genesis-account $(./bitsongd keys show user1 -a --keyring-backend test) 1000000000000ubtsg
RUN ./bitsongd add-genesis-account $(./bitsongd keys show user2 -a --keyring-backend test) 1000000000000ubtsg
RUN ./bitsongd add-genesis-account $(./bitsongd keys show user3 -a --keyring-backend test) 1000000000000ubtsg

RUN ./bitsongd gentx validator 10000000000ubtsg --chain-id localnet-1 --keyring-backend test
RUN ./bitsongd collect-gentxs

EXPOSE 26657
EXPOSE 1317
EXPOSE 9090
CMD ./bitsongd start --trace
14 changes: 14 additions & 0 deletions localnet/install-golang.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#! /bin/bash -x
set -e

GOLANG_URL=https://dl.google.com/go/go1.17.3.linux-amd64.tar.gz
GOLANG_FILENAME=go1.17.3.linux-amd64.tar.gz

if [ "aarch64" = $(uname -m) ]; then
GOLANG_URL=https://dl.google.com/go/go1.17.3.linux-arm64.tar.gz
GOLANG_FILENAME=go1.17.3.linux-arm64.tar.gz
fi

wget $GOLANG_URL
tar -xvf $GOLANG_FILENAME
mv go /usr/local
4 changes: 4 additions & 0 deletions localnet/mnemonics.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
memory fault antenna oppose warfare mutual clap fossil earth solution matrix feel alley tired mix oppose melt plug marriage fiber pride hint cheap hand
silk cricket salt museum voice unable unaware piece excess blue crawl juice soda during learn arrange amused pony excess float grit manage notice dinner
expose drastic inhale gain match pause alter drift across cluster sorry oven capital river wolf used soccer slim twelve wheel notice focus put dad
gap wave quantum merge online sausage process grow upset fossil capital high alcohol cost mansion oak truck like ask cancel random bachelor odor rich
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"private": true,
"scripts": {
"lint": "eslint --ext .js,.ts,.vue ./",
"test": "echo \"No test specified\" && exit 0"
"test": "echo \"No test specified\" && exit 0",
"localnet:start": "sh ./scripts/run-localnet.sh",
"localnet:stop": "docker rm --force bitsong_localnet"
},
"dependencies": {
"@bitsongjs/sdk": "1.0.0-dev-9",
Expand Down
22 changes: 22 additions & 0 deletions scripts/run-localnet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

#DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
DIR=$(pwd)

# Build the docker image first.
docker build --tag bitsong/localnet "$DIR"/localnet

# Make sure that previous container not exist.
docker rm --force bitsong_localnet

# Start container as daemon with some ports opening.
docker run -d -p 1317:1317 -p 26657:26657 -p 9090:9090 --name bitsong_localnet bitsong/localnet

echo "Validator mnemonic: memory fault antenna oppose warfare mutual clap fossil earth solution matrix feel alley tired mix oppose melt plug marriage fiber pride hint cheap hand"
echo "Account1 mnemonic: silk cricket salt museum voice unable unaware piece excess blue crawl juice soda during learn arrange amused pony excess float grit manage notice dinner"
echo "Account2 mnemonic: expose drastic inhale gain match pause alter drift across cluster sorry oven capital river wolf used soccer slim twelve wheel notice focus put dad"
echo "Account2 mnemonic: gap wave quantum merge online sausage process grow upset fossil capital high alcohol cost mansion oak truck like ask cancel random bachelor odor rich"
echo "Each account has the balances (1000000000000ubtsg)"

echo "Docker container is running on \"bitsong_localnet\""
echo "After testing, to remove existing container, run \"sudo docker rm --force bitsong_localnet\""