Skip to content

Commit

Permalink
Dockernet Re-org (#431)
Browse files Browse the repository at this point in the history
  • Loading branch information
sampocs authored Dec 3, 2022
1 parent 2d70bf6 commit b903866
Show file tree
Hide file tree
Showing 56 changed files with 359 additions and 346 deletions.
4 changes: 3 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
.vscode
build
deps
dockernet
scripts
scripts-local
genesis
testutil/localstride
2 changes: 1 addition & 1 deletion .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
- Makefile
- Dockerfile
- scripts/*
- scripts-local/*
- dockernet/*
"T:CI":
- .github/**/*.yml
- .golangci.yml
Expand Down
26 changes: 7 additions & 19 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*.so
*.dylib

scripts/testnet/state/keys.txt
**state.json
**test.py
**test.sh
Expand All @@ -14,25 +13,14 @@ scripts/testnet/state/keys.txt
launch.sh
build/*
state/*
.state.backup
scripts/state/*
scripts/testnet/*/state/keys.txt
scripts/testnet/state/*
scripts/testnet/certs/**.pem

scripts/logs/*.log
scripts/logs/*/*.log
scripts-local/state
scripts-local/logs
scripts-local/test-utils/state/
scripts/state
scripts/logs
dockernet/state
dockernet/logs
dockernet/upgrades/binaries
dockernet/upgrades/cosmovisor
dockernet/temp.sh
scripts/temp.sh
scripts/testnet/*/state/keys.txt
scripts/tests/validator_selection
scripts/tests/local_tests.bats
scripts-local/upgrades/binaries
scripts-local/upgrades/cosmovisor
scripts/upgrades/binaries
scripts/upgrades/cosmovisor
vue/*
# Test binary, built with `go test -c`
*.test
Expand Down
15 changes: 9 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@
# Commit: b0bea28fc695a2a5c567e56a37b289a5b75830cc
path = deps/stargaze
url = https://github.com/public-awesome/stargaze.git
[submodule "scripts/tests/bats/bats-support"]
path = scripts/tests/bats/bats-support
url = https://github.com/ztombol/bats-support
[submodule "scripts/tests/bats/bats-assert"]
path = scripts/tests/bats/bats-assert
url = https://github.com/ztombol/bats-assert
[submodule "dockernet/tests/bats/bats-core"]
path = dockernet/tests/bats/bats-core
url = https://github.com/bats-core/bats-core.git
[submodule "dockernet/tests/bats/bats-assert"]
path = dockernet/tests/bats/bats-assert
url = https://github.com/bats-core/bats-assert.git
[submodule "dockernet/tests/bats/bats-support"]
path = dockernet/tests/bats/bats-support
url = https://github.com/bats-core/bats-support.git
42 changes: 42 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# syntax = docker/dockerfile:1

ARG GO_VERSION="1.19"
ARG RUNNER_IMAGE="alpine:3.16"

FROM golang:${GO_VERSION}-alpine as builder

WORKDIR /opt
RUN apk add --no-cache make git gcc musl-dev openssl-dev linux-headers

COPY go.mod .
COPY go.sum .

RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/root/go/pkg/mod \
go mod download

# Copy the remaining files
COPY . .

RUN LINK_STATICALLY=true make build

# Add to a distroless container
FROM ${RUNNER_IMAGE}

COPY --from=builder /opt/build/strided /usr/local/bin/strided
RUN apk add bash vim sudo dasel \
&& addgroup -g 1000 stride \
&& adduser -S -h /home/stride -D stride -u 1000 -G stride

RUN mkdir -p /etc/sudoers.d \
&& echo '%wheel ALL=(ALL) ALL' > /etc/sudoers.d/wheel \
&& echo "%wheel ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers \
&& adduser stride wheel

USER 1000
ENV HOME /home/stride
WORKDIR $HOME

EXPOSE 26657 26656 1317 9090

CMD ["strided", "start"]
36 changes: 0 additions & 36 deletions Dockerfile.localstride

This file was deleted.

34 changes: 0 additions & 34 deletions Dockerfile.stride

This file was deleted.

48 changes: 24 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ cache=false
COMMIT := $(shell git log -1 --format='%H')
DOCKER := $(shell which docker)
DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf:1.7.0
DOCKERNET_HOME=./dockernet
DOCKERNET_COMPOSE_FILE=$(DOCKERNET_HOME)/docker-compose.yml
LOCALSTRIDE_HOME=./testutil/localstride
LOCALNET_COMPOSE_FILE=$(LOCALSTRIDE_HOME)/localnet/docker-compose.yml
STATE_EXPORT_COMPOSE_FILE=$(LOCALSTRIDE_HOME)/state-export/docker-compose.yml

# process build tags

Expand Down Expand Up @@ -79,9 +84,6 @@ install: go.sum
clean:
rm -rf $(BUILDDIR)/*

clean-state:
rm -rf scripts-local/state

###############################################################################
### CI ###
###############################################################################
Expand All @@ -104,32 +106,30 @@ test-unit:
test-cover:
@go test -mod=readonly -race -coverprofile=coverage.out -covermode=atomic ./x/$(module)/...

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

test-integration-docker:
bash scripts/tests/run_all_tests.sh
bash $(DOCKERNET_HOME)/tests/run_all_tests.sh

###############################################################################
### DockerNet ###
###############################################################################

build-docker:
@bash scripts/build.sh -${build} ${BUILDDIR}
@bash $(DOCKERNET_HOME)/build.sh -${build} ${BUILDDIR}

start-docker: build-docker
@bash scripts/start_network.sh
@bash $(DOCKERNET_HOME)/start_network.sh

clean-docker:
@docker-compose stop
@docker-compose down
rm -rf scripts/state
@docker-compose -f $(DOCKERNET_COMPOSE_FILE) stop
@docker-compose -f $(DOCKERNET_COMPOSE_FILE) down
rm -rf $(DOCKERNET_HOME)/state
docker image prune -a

stop-docker:
@-pkill -f "docker-compose logs"
@-pkill -f "/bin/bash.*create_logs.sh"
docker-compose down
@pkill -f "docker-compose .*stride.* logs" | true
@pkill -f "/bin/bash.*create_logs.sh" | true
@pkill -f "tail .*.log" | true
docker-compose -f $(DOCKERNET_COMPOSE_FILE) down

###############################################################################
### Protobuf ###
Expand Down Expand Up @@ -163,37 +163,37 @@ proto-lint:
###############################################################################

localnet-keys:
. testutil/localstride/scripts/add_keys.sh
. $(LOCALSTRIDE_HOME)/localnet/add_keys.sh

localnet-init: localnet-clean localnet-build

localnet-clean:
@rm -rfI $(HOME)/.stride/

localnet-build:
@docker-compose -f testutil/localstride/docker-compose.yml build
@docker-compose -f $(LOCALNET_COMPOSE_FILE) build

localnet-start:
@docker-compose -f testutil/localstride/docker-compose.yml up
@docker-compose -f $(LOCALNET_COMPOSE_FILE) up

localnet-startd:
@docker-compose -f testutil/localstride/docker-compose.yml up -d
@docker-compose -f $(LOCALNET_COMPOSE_FILE) up -d

localnet-stop:
@docker-compose -f testutil/localstride/docker-compose.yml down
@docker-compose -f $(LOCALNET_COMPOSE_FILE) down

localnet-state-export-init: localnet-state-export-clean localnet-state-export-build

localnet-state-export-build:
@DOCKER_BUILDKIT=1 COMPOSE_DOCKER_CLI_BUILD=1 docker-compose -f testutil/localstride/state_export/docker-compose.yml build
@DOCKER_BUILDKIT=1 COMPOSE_DOCKER_CLI_BUILD=1 docker-compose -f $(STATE_EXPORT_COMPOSE_FILE) build

localnet-state-export-start:
@docker-compose -f testutil/localstride/state_export/docker-compose.yml up
@docker-compose -f $(STATE_EXPORT_COMPOSE_FILE) up

localnet-state-export-startd:
@docker-compose -f testutil/localstride/state_export/docker-compose.yml up -d
@docker-compose -f $(STATE_EXPORT_COMPOSE_FILE) up -d

localnet-state-export-stop:
@docker-compose -f testutil/localstride/docker-compose.yml down
@docker-compose -f $(STATE_EXPORT_COMPOSE_FILE) down

localnet-state-export-clean: localnet-clean
22 changes: 11 additions & 11 deletions scripts/README.md → dockernet/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
`/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` 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}`). Use one of the other host zone's dockerfile's as a starting port to provide the certain boilerplate such as the package installs, adding user, exposing ports, etc.
* Create a new dockerfile to `dockernet/dockerfiles` (named `Dockerfile.{new-host-zone}`). Use one of the other host zone's dockerfile's as a starting port to provide the certain boilerplate such as the package installs, adding user, exposing ports, etc.
* Add the repo as a submodule
```
git submodule add {repo-url} deps/{new-host-zone}
Expand All @@ -14,19 +14,19 @@ git checkout {commit-hash}
cd ..
```
* Add a comment to `.gitmodules` with the commit hash
* Add the build command for that host zone in `scripts/build.sh` (`n` is used as an example below - use the first letter of the host zone)
* Add the build command for that host zone in `dockernet/build.sh` (`n` is used as an example below - use the first letter of the host zone)
```
while getopts sgojhir{n} flag; do
case "${flag}" in
...
n) build_local_and_docker {new-host-zone} deps/{new-host-zone} ;;
```
* Add the host zone to the docker compose filein the root level of the stride directory. Add 5 nodes and add the port forwarding to the first node only. Drop the RPC port number by 100, and the API/gRPC port by 10, relative to the last host zone that was added.
* Add the host zone to the docker compose file. Add 5 nodes and add the port forwarding to the first node only. Drop the RPC port number by 100, and the API/gRPC port by 10, relative to the last host zone that was added.
```
{new-host-zone}1:
image: stridezone:{new-host-zone}
volumes:
- ./scripts/state/{new-host-zone}1:/home/{new-host-zone}/.{new-host-zone}
- ./dockernet/state/{new-host-zone}1:/home/{new-host-zone}/.{new-host-zone}
ports:
- "{rpc-port}:26657"
- "{api-port}:1317"
Expand All @@ -35,16 +35,16 @@ while getopts sgojhir{n} flag; do
{new-host-zone}2:
image: stridezone:{new-host-zone}
volumes:
- ./scripts/state/{new-host-zone}2:/home/{new-host-zone}/.{new-host-zone}
- ./dockernet/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}
- ./dockernet/state/{new-host-zone}5:/home/{new-host-zone}/.{new-host-zone}
```
* Add the following parameters to `scripts/vars.sh`, where `CHAIN` is the ID of the new host zone
* Add the following parameters to `dockernet/config.sh`, where `CHAIN` is the ID of the new host zone
```
{CHAIN}_CHAIN_ID={NEW-HOST-ZONE}
{CHAIN}_NODE_PREFIX={new-host-zone}
Expand All @@ -65,7 +65,7 @@ RELAYER_{CHAIN}_MNEMONIC=""
RELAYER_MNEMONICS=(...,"$RELAYER_{CHAIN}_MNEMONIC")
```
* Add the IBC denom's for the host zone across each channel to `vars.sh` (e.g. `IBC_{HOST}_CHANNEL_{N}_DENOM)`). You can use the following code block to generate the variables (just temporarily throw it in any of the test files, run it, and copy the output to `vars.sh`)
* Add the IBC denom's for the host zone across each channel to `config.sh` (e.g. `IBC_{HOST}_CHANNEL_{N}_DENOM)`). You can use the following code block to generate the variables (just temporarily throw it in any of the test files, run it, and copy the output to `config.sh`)
```
import transfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types"
Expand All @@ -80,7 +80,7 @@ func (s *KeeperTestSuite) TestIBCDenom() {
}
}
```
* Add a section to the `scripts/config/relayer_config.yaml`
* Add a section to the `dockernet/config/relayer_config.yaml`
```
chains:
...
Expand Down Expand Up @@ -110,7 +110,7 @@ paths:
rule: ""
channel-list: []
```
* To enable the the new host zone, include it in the `HOST_CHAINS` array in `scripts/vars.sh`. **Note: You can only run up to 4 host zones at once.**
* To enable the the new host zone, include it in the `HOST_CHAINS` array in `dockernet/config.sh`. **Note: You can only run up to 4 host zones at once.**
```
HOST_CHAINS=(GAIA {NEW-HOST-ZONE})
```
Expand Down
Loading

0 comments on commit b903866

Please sign in to comment.