Skip to content

Commit

Permalink
Add helpers for CI setup and document
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanfrey committed Jan 22, 2020
1 parent b5618cd commit 0380ead
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 43 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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
```
10 changes: 8 additions & 2 deletions docker/run.sh
Original file line number Diff line number Diff line change
@@ -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
8 changes: 7 additions & 1 deletion docker/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0380ead

Please sign in to comment.