Skip to content

Commit

Permalink
Docker net multiple host (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
sampocs authored Sep 15, 2022
1 parent e951388 commit f5c0b2c
Show file tree
Hide file tree
Showing 39 changed files with 1,532 additions and 776 deletions.
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
path = deps/hermes
url = git@github.com:informalsystems/ibc-rs.git
[submodule "deps/relayer"]
# Commit: f56b9b6e5c9b8eaf6d4f93ee6497a3b1e13a9faf
# Tag: v2.0.0
# Commit: 65d6065e8016e420c0ddaf9141b5c834e01804c0
# Branch: andrew/client_icq
path = deps/relayer
url = git@github.com:cosmos/relayer.git
[submodule "deps/gaia"]
Expand All @@ -23,4 +23,4 @@
[submodule "deps/osmosis"]
# Commit: 08669da8509059980dc964976ee1ca60c84f5c8a
path = deps/osmosis
url = https://github.com/osmosis-labs/osmosis.git
url = https://github.com/osmosis-labs/osmosis.git
13 changes: 8 additions & 5 deletions Dockerfile.gaia
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
FROM golang:1.17-alpine3.15 AS gaiad-builder
FROM golang:1.17-alpine3.15 AS builder

WORKDIR /src/app/
WORKDIR /opt

RUN apk add --update curl make git libc-dev bash gcc linux-headers eudev-dev python3

RUN git clone https://github.com/Stride-Labs/gaia --branch v7.0.2-pin-ibc-cosmos-sdk \
&& cd gaia \
ENV COMMIT_HASH=5b47714dd5607993a1a91f2b06a6d92cbb504721

RUN git clone https://github.com/Stride-Labs/gaia gaia-install \
&& cd gaia-install \
&& git checkout $COMMIT_HASH \
&& CGO_ENABLED=0 make install

FROM alpine:3.15
COPY --from=gaiad-builder /go/bin/gaiad /usr/local/bin/
COPY --from=builder /go/bin/gaiad /usr/local/bin/
RUN adduser -S -h /home/gaia -D gaia -u 1000

USER gaia
Expand Down
8 changes: 5 additions & 3 deletions Dockerfile.hermes
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
FROM rust:1.58-slim as rust
FROM rust:1.58-slim as builder

WORKDIR /opt

RUN apt update && apt install git -y

RUN git clone https://github.com/informalsystems/ibc-rs --branch v1.0.0 \
ENV COMMIT_HASH=ed4dd8c8b4ebd695730de2a1c69f3011cb179352
RUN git clone https://github.com/informalsystems/ibc-rs \
&& cd ibc-rs \
&& git checkout $COMMIT_HASH \
&& cargo build --release

FROM debian:bullseye-slim

COPY --from=rust /opt/ibc-rs/target/release/hermes /usr/local/bin/hermes
COPY --from=builder /opt/ibc-rs/target/release/hermes /usr/local/bin/hermes
RUN apt-get update \
&& adduser --system --home /home/hermes --disabled-password --disabled-login hermes -u 1000

Expand Down
5 changes: 4 additions & 1 deletion Dockerfile.icq
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ USER icq

WORKDIR /home/icq

CMD ["interchain-queries", "run"]
RUN echo "while true; do interchain-queries run; done" > /home/icq/start.sh

CMD ["sh", "/home/icq/start.sh"]

30 changes: 30 additions & 0 deletions Dockerfile.juno
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM golang:1.19-alpine3.15 AS builder

WORKDIR /src/app/

RUN set -eux; apk add --no-cache ca-certificates build-base git;

RUN git clone https://github.com/CosmosContracts/juno.git \
&& cd juno \
&& git checkout 9558920

WORKDIR /src/app/juno

ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.0.0/libwasmvm_muslc.aarch64.a /lib/libwasmvm_muslc.aarch64.a
ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.0.0/libwasmvm_muslc.x86_64.a /lib/libwasmvm_muslc.x86_64.a
RUN sha256sum /lib/libwasmvm_muslc.aarch64.a | grep 7d2239e9f25e96d0d4daba982ce92367aacf0cbd95d2facb8442268f2b1cc1fc
RUN sha256sum /lib/libwasmvm_muslc.x86_64.a | grep f6282df732a13dec836cda1f399dd874b1e3163504dbd9607c6af915b2740479
RUN cp /lib/libwasmvm_muslc.$(uname -m).a /lib/libwasmvm_muslc.a

RUN LEDGER_ENABLED=false BUILD_TAGS=muslc LINK_STATICALLY=true make build

FROM alpine:3.15
COPY --from=builder /src/app/juno/bin/junod /usr/local/bin/
RUN adduser -S -h /home/juno -D juno -u 1000

USER juno
WORKDIR /home/juno

EXPOSE 26657 26656 1317 9090

CMD ["junod", "start"]
31 changes: 31 additions & 0 deletions Dockerfile.osmo
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM golang:1.18-alpine3.15 AS builder

WORKDIR /src/app/

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

RUN git clone https://github.com/osmosis-labs/osmosis.git \
&& cd osmosis \
&& git checkout 08669da8509059980dc964976ee1ca60c84f5c8a

WORKDIR /src/app/osmosis

# Cosmwasm - download correct libwasmvm version and verify checksum
RUN WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm | cut -d ' ' -f 2) \
&& wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm_muslc.$(uname -m).a \
-O /lib/libwasmvm_muslc.a \
&& wget https://github.com/CosmWasm/wasmvm/releases/download/v1.0.0/checksums.txt -O /tmp/checksums.txt \
&& sha256sum /lib/libwasmvm_muslc.a | grep $(cat /tmp/checksums.txt | grep $(uname -m) | cut -d ' ' -f 1)

RUN BUILD_TAGS=muslc LINK_STATICALLY=true make build

FROM alpine:3.15
COPY --from=builder /src/app/osmosis/build/osmosisd /usr/local/bin/
RUN adduser -S -h /home/osmosis -D osmosis -u 1000

USER osmosis
WORKDIR /home/osmosis

EXPOSE 26657 26656 1317 9090

CMD ["osmosisd", "start"]
9 changes: 5 additions & 4 deletions Dockerfile.relayer
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
FROM golang:1.18-alpine3.15 AS relayer-builder
FROM golang:1.18-alpine3.15 AS builder

WORKDIR /src/

ENV COMMIT_HASH=65d6065e8016e420c0ddaf9141b5c834e01804c0

RUN apk add --update git make gcc linux-headers libc-dev eudev-dev
RUN git clone https://github.com/cosmos/relayer.git \
&& cd relayer \
&& git checkout v2.0.0 \
&& git checkout $COMMIT_HASH \
&& make install

FROM alpine:3.15
COPY --from=relayer-builder /go/bin/rly /usr/local/bin/
COPY --from=builder /go/bin/rly /usr/local/bin/
RUN adduser -S -h /home/relayer -D relayer -u 1000

USER relayer
WORKDIR /home/relayer

CMD ["rly", "start", "stride-gaia"]
4 changes: 2 additions & 2 deletions Dockerfile.stride
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# syntax = docker/dockerfile:1
FROM golang:1.18-alpine3.15 AS golang
FROM golang:1.18-alpine3.15 AS builder

WORKDIR /src/

Expand All @@ -21,7 +21,7 @@ RUN --mount=type=cache,target=/root/.cache/go-build make build

# Add to a distroless container
FROM alpine:3.15
COPY --from=golang /src/build/strided /usr/local/bin/strided
COPY --from=builder /src/build/strided /usr/local/bin/strided
RUN addgroup -g 1000 stride \
&& adduser -S -h /home/stride -D stride -u 1000 -G stride

Expand Down
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ test-unit:
test-cover:
@go test -mod=readonly -race -coverprofile=coverage.out -covermode=atomic ./x/$(module)/...

test-integration:
test-integration-local:
sh scripts-local/tests/run_all_tests.sh

test-integration-docker:
Expand Down Expand Up @@ -143,6 +143,7 @@ start-local: build-local
@sh scripts-local/start_network.sh ${cache}

stop-local:
@killall gaiad strided junod osmosisd rly hermes interchain-queries || true
@killall gaiad strided junod osmosisd rly hermes interchain-queries icq-startup.sh || true
@pkill -f "/bin/bash.*create_logs.sh" || true
@pkill -f "sh.*start_network.sh" || true

2 changes: 1 addition & 1 deletion deps/relayer
Submodule relayer updated 235 files
69 changes: 60 additions & 9 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ version: "3.8"
services:
stride1:
image: stridezone:stride
hostname: stride
volumes:
- ./scripts/state/stride1:/home/stride/.stride
ports:
Expand All @@ -12,49 +11,101 @@ services:

stride2:
image: stridezone:stride
hostname: stride
volumes:
- ./scripts/state/stride2:/home/stride/.stride

stride3:
image: stridezone:stride
hostname: stride
volumes:
- ./scripts/state/stride3:/home/stride/.stride

gaia1:
image: stridezone:gaia
hostname: stride
volumes:
- ./scripts/state/gaia1:/home/gaia/.gaia
ports:
- "26557:26657"
- "1307:1317"
- "9080:9090"

gaia2:
image: stridezone:gaia
hostname: stride
volumes:
- ./scripts/state/gaia2:/home/gaia/.gaia

gaia3:
image: stridezone:gaia
hostname: stride
volumes:
- ./scripts/state/gaia3:/home/gaia/.gaia

gaia4:
image: stridezone:gaia
hostname: stride
volumes:
- ./scripts/state/gaia4:/home/gaia/.gaia

gaia5:
image: stridezone:gaia
hostname: stride
volumes:
- ./scripts/state/gaia5:/home/gaia/.gaia

juno1:
image: stridezone:juno
volumes:
- ./scripts/state/juno1:/home/juno/.juno
ports:
- "26457:26657"
- "1297:1317"
- "9070:9090"

juno2:
image: stridezone:juno
volumes:
- ./scripts/state/juno2:/home/juno/.juno

juno3:
image: stridezone:juno
volumes:
- ./scripts/state/juno3:/home/juno/.juno

juno4:
image: stridezone:juno
volumes:
- ./scripts/state/juno4:/home/juno/.juno

juno5:
image: stridezone:juno
volumes:
- ./scripts/state/juno5:/home/juno/.juno

osmo1:
image: stridezone:osmo
volumes:
- ./scripts/state/osmo1:/home/osmosis/.osmosisd
ports:
- "26357:26657"
- "1287:1317"
- "9060:9090"

osmo2:
image: stridezone:osmo
volumes:
- ./scripts/state/osmo2:/home/osmosis/.osmosisd

osmo3:
image: stridezone:osmo
volumes:
- ./scripts/state/osmo3:/home/osmosis/.osmosisd

osmo4:
image: stridezone:osmo
volumes:
- ./scripts/state/osmo4:/home/osmosis/.osmosisd

osmo5:
image: stridezone:osmo
volumes:
- ./scripts/state/osmo5:/home/osmosis/.osmosisd

hermes:
image: stridezone:hermes
volumes:
Expand All @@ -69,7 +120,7 @@ services:
restart: always

icq:
image: stridezone:interchain-queries
image: stridezone:icq
volumes:
- ./scripts/state/icq:/home/icq/.icq
restart: always
69 changes: 69 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,70 @@
`/scripts` contains (unmaintained) infrastructure that was used for early testing and development of the Stride protocol. The scripts here support docker-image based testing, some of which are heavily inspired by those used by Osmosis and Quicksilver (although there have been deviations from the original implementations since). The relevant licenses are included here.

## Dockernet
### Adding a new host zone
* Create a new dockerfile at the root level (`Dockerfile.{new-host-zone})
* Add the host zone to the docker compose file at the root level. Add the port forwarding to the first node. Add 5 nodes here. Drop the RPC port number by 100, and the API/gRPC port by 10 since the last host zone.
```
{new-host-zone}1:
image: stridezone:{new-host-zone}
volumes:
- ./scripts/state/{new-host-zone}1:/home/{new-host-zone}/.{new-host-zone}
ports:
- "26257:26657"
- "1277:1317"
- "9050:9090"
{new-host-zone}2:
image: stridezone:{new-host-zone}
volumes:
- ./scripts/state/{new-host-zone}2:/home/{new-host-zone}/.{new-host-zone}
...
{new-host-zone}5:
image: stridezone:{new-host-zone}
volumes:
- ./scripts/state/{new-host-zone}5:/home/{new-host-zone}/.{new-host-zone}
```
* Add the host zone as a submodule in `deps`
* Add the build command for that host zone in `scripts/build.sh`
```
while getopts sgojhir{n} flag; do
case "${flag}" in
...
n) build_local_and_docker {new-host-zone} deps/{new-host-zone} ;;
```
* Add the following parameters to `scripts/vars.sh`, where `CHAIN_ID` is the ID of the new host zone
```
{CHAIN_ID}_CHAIN_ID={NEW-HOST-ZONE}
{CHAIN_ID}_NODE_PREFIX={new-host-zone}
{CHAIN_ID}_NUM_NODES=3
{CHAIN_ID}_CMD="$SCRIPT_DIR/../build/{new-host-zone}d"
{CHAIN_ID}_VAL_PREFIX={n}val
{CHAIN_ID}_REV_ACCT={n}rev1
{CHAIN_ID}_DENOM=
{CHAIN_ID}_IBC_DENOM=
{CHAIN_ID}_RPC_PORT={the one included in the docker-compose above}
{CHAIN_ID}_MAIN_CMD="${CHAIN_ID}_CMD --home $SCRIPT_DIR/state/${${CHAIN_ID}_NODE_PREFIX}1"
{CHAIN_ID}_REV_MNEMONIC=""
{CHAIN_ID}_VAL_MNEMONIC_1=""
{CHAIN_ID}_VAL_MNEMONIC_2=""
{CHAIN_ID}_VAL_MNEMONIC_3=""
{CHAIN_ID}_VAL_MNEMONIC_4=""
{CHAIN_ID}_VAL_MNEMONIC_5=""
{CHAIN_ID}_VAL_MNEMONICS=("${CHAIN_ID}_VAL_MNEMONIC_1","${CHAIN_ID}_VAL_MNEMONIC_2","${CHAIN_ID}_VAL_MNEMONIC_3","${CHAIN_ID}_VAL_MNEMONIC_4","${CHAIN_ID}_VAL_MNEMONIC_5")
HERMES_${CHAIN_ID}_ACCT=rly{add one since the account from the last host zone}
HERMES_${CHAIN_ID}_MNEMONIC=""
ICQ_${CHAIN_ID}_ACCT=rly{add one since the account from the last host zone}
ICQ_${CHAIN_ID}_MNEMONIC=""
```
* Finally add the execution of the `init_chain` script for this host zone in `scripts/start_network.sh`, and add it to the array of `HOST_CHAINS`
```
sh ${SCRIPT_DIR}/init_chain.sh {NEW-HOST-ZONE}
HOST_CHAINS=(GAIA JUNO OSMO ... {NEW-HOST-ZONE})
```
* And that's it! Just start the network as normal, and make sure to rebuild the new host zone when running for the first time.
Loading

0 comments on commit f5c0b2c

Please sign in to comment.