Skip to content

Commit

Permalink
Merge pull request CosmWasm#39 from cosmwasm/alex/docker_wip
Browse files Browse the repository at this point in the history
WIP: Dockerize
  • Loading branch information
ethanfrey authored Jan 22, 2020
2 parents 42f2c8f + d1989df commit 2347ae4
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 17 deletions.
35 changes: 18 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,33 @@
# > docker build -t gaia .
# > docker run -it -p 46657:46657 -p 46656:46656 -v ~/.wasmd:/root/.wasmd -v ~/.wasmcli:/root/.wasmcli gaia wasmd init
# > docker run -it -p 46657:46657 -p 46656:46656 -v ~/.wasmd:/root/.wasmd -v ~/.wasmcli:/root/.wasmcli gaia wasmd start
FROM golang:alpine AS build-env
FROM golang:1.13-buster AS build-env

# Set up dependencies
ENV PACKAGES curl make git libc-dev bash gcc linux-headers eudev-dev python
# 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

# Add source files
COPY . .
#
RUN make tools
RUN make install

# Install minimum necessary dependencies, build Cosmos SDK, remove packages
RUN apk add --no-cache $PACKAGES && \
make tools && \
make install

# Final image
FROM alpine:edge
COPY docker/* /opt/
RUN chmod +x /opt/*.sh

# Install ca-certificates
RUN apk add --update ca-certificates
WORKDIR /root
WORKDIR /opt

# Copy over binaries from the build-env
COPY --from=build-env /go/bin/wasmd /usr/bin/wasmd
COPY --from=build-env /go/bin/wasmcli /usr/bin/wasmcli
# rest server
EXPOSE 1317
# tendermint p2p
EXPOSE 26656
# tendermint rpc
EXPOSE 26657

# Run wasmd by default, omit entrypoint to ease using container with wasmcli
CMD ["wasmd"]
66 changes: 66 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,69 @@ To set up a single node testnet, [look at the deployment documentation](./docs/d

If you want to deploy a whole cluster, [look at the network scripts](./networks/README.md).

## Dockerized

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

### Dev server

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 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 \
--mount type=volume,source=wasmd_data,target=/root \
wasmd:manual ./run_all.sh

# view wasmd logs in another shell
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_all.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_all.sh

# view wasmd logs in another shell
docker run --rm -it \
--mount type=volume,source=wasmd_data,target=/root,readonly \
wasmd:manual ./logs.sh
```
3 changes: 3 additions & 0 deletions docker/logs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

tail -f /root/log/wasmd.log
8 changes: 8 additions & 0 deletions docker/run_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

./run_wasmd.sh >> /root/log/wasmd.log &

sleep 4
echo Starting Rest Server...

wasmcli rest-server --laddr tcp://0.0.0.0:1317 --trust-node
10 changes: 10 additions & 0 deletions docker/run_wasmd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/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

mkdir -p /root/log
wasmd start --rpc.laddr tcp://0.0.0.0:26657
15 changes: 15 additions & 0 deletions docker/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh

PASSWORD=${PASSWORD:-1234567890}

wasmd init --chain-id=testing testing
(echo $PASSWORD; echo $PASSWORD) | wasmcli keys add validator
# 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 2347ae4

Please # to comment.