diff --git a/Dockerfile b/Dockerfile index 3c4c559378..3bc6a8b3ed 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,6 +7,8 @@ FROM golang:1.13-buster AS build-env # Install minimum necessary dependencies, build Cosmos SDK, remove packages RUN apt update RUN apt install -y curl git build-essential +# debug: for live editting in the image +RUN apt install -y vim # Set working directory for the build WORKDIR /go/src/github.com/cosmwasm/wasmd diff --git a/README.md b/README.md index 1a6fccea97..2b75ed786a 100644 --- a/README.md +++ b/README.md @@ -28,20 +28,25 @@ If you want to deploy a whole cluster, [look at the network scripts](./networks/ ## Dockerized -This is just designed for local testing/CI - DO NOT USE IN PRODUCTION +We provide a docker image to help with test setups. There are two modes to use it + +Build: `docker build -t wasmd:manual .` or pull from dockerhub -Build: `docker build -t wasmd:manual .` +### Dev server -Run: +Bring up a local node with a test account containing tokens + +This is just designed for local testing/CI - DO NOT USE IN PRODUCTION ```sh docker volume rm -f wasmd_data # pass password (one time) as env variable for setup, so we don't need to keep typing it +# add some addresses that you have private keys for (locally) to give them genesis funds docker run --rm -it \ -e PASSWORD=my-secret-password \ --mount type=volume,source=wasmd_data,target=/root \ - wasmd:manual ./setup.sh + wasmd:manual ./setup.sh cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6 # This will start both wasmd and wasmcli rest-server, only wasmcli output is shown on the screen docker run --rm -it -p 26657:26657 -p 26656:26656 -p 1317:1317 \ @@ -53,3 +58,37 @@ docker run --rm -it \ --mount type=volume,source=wasmd_data,target=/root,readonly \ wasmd:manual ./logs.sh ``` + +### CI + +For CI, we want to generate a template one time and save to disk/repo. Then we can start a chain copying the initial state, but not modifying it. This lets us get the same, fresh start every time. + +```sh +# Init chain and pass addresses so they are non-empty accounts +rm -rf ./template && mkdir ./template +docker run --rm -it \ + -e PASSWORD=my-secret-password \ + --mount type=bind,source=$(pwd)/template,target=/root \ + wasmd:manual ./setup.sh cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6 + +sudo chown -R $(id -u):$(id -g) ./template + +# FIRST TIME +# bind to non-/root and pass an argument to run.sh to copy the template into /root +# we need wasmd_data volume mount not just for restart, but also to view logs +docker volume rm -f wasmd_data +docker run --rm -it -p 26657:26657 -p 26656:26656 -p 1317:1317 \ + --mount type=bind,source=$(pwd)/template,target=/template \ + --mount type=volume,source=wasmd_data,target=/root \ + wasmd:manual ./run.sh /template + +# RESTART CHAIN with existing state +docker run --rm -it -p 26657:26657 -p 26656:26656 -p 1317:1317 \ + --mount type=volume,source=wasmd_data,target=/root \ + wasmd:manual ./run.sh + +# view wasmd logs in another shell +docker run --rm -it \ + --mount type=volume,source=wasmd_data,target=/root,readonly \ + wasmd:manual ./logs.sh +``` diff --git a/docker/run.sh b/docker/run.sh index f8dcd7e6d0..3e3b6680ff 100644 --- a/docker/run.sh +++ b/docker/run.sh @@ -1,11 +1,17 @@ #!/bin/bash +if test -n "$1"; then + # need -R not -r to copy hidden files + cp -R "$1/.wasmd" /root + cp -R "$1/.wasmcli" /root +fi + echo Starting Wasmd... mkdir -p /root/log -wasmd start --rpc.laddr tcp://0.0.0.0:26657 > /root/log/wasmd.log & +wasmd start --rpc.laddr tcp://0.0.0.0:26657 >> /root/log/wasmd.log & -sleep 10 +sleep 4 echo Starting Rest Server... wasmcli rest-server --laddr tcp://0.0.0.0:1317 --trust-node diff --git a/docker/setup.sh b/docker/setup.sh index 1904ac8fb8..bf65ed3eb6 100755 --- a/docker/setup.sh +++ b/docker/setup.sh @@ -4,6 +4,12 @@ PASSWORD=${PASSWORD:-1234567890} wasmd init --chain-id=testing testing (echo $PASSWORD; echo $PASSWORD) | wasmcli keys add validator -echo $PASSWORD | wasmd add-genesis-account validator 1000000000stake,1000000000validatortoken +# hardcode the validator account for this instance +echo $PASSWORD | wasmd add-genesis-account validator 1000000000stake,1000000000cosm +# (optionally) add a few more genesis accounts +for addr in "$@"; do + wasmd add-genesis-account $addr 1000000000stake,1000000000cosm +done +# submit a genesis validator tx (echo $PASSWORD; echo $PASSWORD; echo $PASSWORD) | wasmd gentx --name validator wasmd collect-gentxs \ No newline at end of file