From 6e03b38fe5f61b831bbd6e86482deff5c7bb776b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joonas=20Lehtim=C3=A4ki?= Date: Fri, 1 Sep 2023 20:53:00 +0300 Subject: [PATCH] feat: add containerized localnet (#439) * chore: remove deprecated localnet script this script is no longer working and has been deprecated by scripts/localnet.sh * feat: update localnet.sh to support container deployments - change to use bash script instead of sh to allow more refined syntax - set archwayd process to listen all addresses instead of localhost - set BINARY path dependent on whether using containers or local * fix: docker-compose update - use image based on TAG env variable, make file will set the tag automatically - enable 26656 also - change to use the new scripts path * feat: update Dockerfile for devs - Update image version to alpine 3.18 - rename the debug image to dev - add bash and jq for dev purposes * feat: update makefile to enable containerized localnet deployment * feat: rename debug image to dev image * chore: update changelog * fix: untag the correct compose command * chore: moving localnet CHANGELOGS to correct place, waiting a release * feat: readme part how to run containerized localnet * feat: add comments to makefile to clarify how localnet commands work * fix: add build to run step in the makefile to fix missing binary' --- .goreleaser.yaml | 14 +++++------ CHANGELOG.md | 14 +++++------ Dockerfile.debug => Dockerfile.dev | 5 +++- Makefile | 17 ++++++++++---- README.md | 35 ++++++++++++++++++++++------ contrib/localnet/localnet.sh | 37 ------------------------------ docker-compose.yaml | 9 ++++---- scripts/localnet.sh | 31 +++++++++++++++---------- 8 files changed, 82 insertions(+), 80 deletions(-) rename Dockerfile.debug => Dockerfile.dev (73%) delete mode 100755 contrib/localnet/localnet.sh diff --git a/.goreleaser.yaml b/.goreleaser.yaml index b1e67f98..732ea963 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -194,9 +194,9 @@ dockers: - use: buildx goos: linux goarch: amd64 - dockerfile: Dockerfile.debug + dockerfile: Dockerfile.dev image_templates: - - 'ghcr.io/archway-network/{{ .ProjectName }}d-debug:{{if eq .Env.RELEASE "true"}}v{{ .Version }}{{else}}{{ .ShortCommit }}{{end}}-amd64' + - 'ghcr.io/archway-network/{{ .ProjectName }}d-dev{{if eq .Env.RELEASE "true"}}v{{ .Version }}{{else}}{{ .ShortCommit }}{{end}}-amd64' build_flag_templates: - "--pull" - "--platform=linux/amd64" @@ -211,9 +211,9 @@ dockers: - use: buildx goos: linux goarch: arm64 - dockerfile: Dockerfile.debug + dockerfile: Dockerfile.dev image_templates: - - 'ghcr.io/archway-network/{{ .ProjectName }}d-debug:{{if eq .Env.RELEASE "true"}}v{{ .Version }}{{else}}{{ .ShortCommit }}{{end}}-arm64v8' + - 'ghcr.io/archway-network/{{ .ProjectName }}d-dev{{if eq .Env.RELEASE "true"}}v{{ .Version }}{{else}}{{ .ShortCommit }}{{end}}-arm64v8' build_flag_templates: - "--pull" - "--platform=linux/arm64" @@ -230,7 +230,7 @@ docker_manifests: image_templates: - 'ghcr.io/archway-network/{{ .ProjectName }}d:{{if eq .Env.RELEASE "true"}}v{{ .Version }}-amd64{{else}}{{ .ShortCommit }}-amd64{{end}}' - 'ghcr.io/archway-network/{{ .ProjectName }}d:{{if eq .Env.RELEASE "true"}}v{{ .Version }}-arm64v8{{else}}{{ .ShortCommit }}-arm64v8{{end}}' - - name_template: 'ghcr.io/archway-network/{{ .ProjectName }}d-debug:{{if eq .Env.RELEASE "true" }}v{{ .Version }}{{else}}{{ .ShortCommit }}{{end}}' + - name_template: 'ghcr.io/archway-network/{{ .ProjectName }}d-dev{{if eq .Env.RELEASE "true" }}v{{ .Version }}{{else}}{{ .ShortCommit }}{{end}}' image_templates: - - 'ghcr.io/archway-network/{{ .ProjectName }}d-debug:{{if eq .Env.RELEASE "true"}}v{{ .Version }}{{else}}{{ .ShortCommit }}{{end}}-amd64' - - 'ghcr.io/archway-network/{{ .ProjectName }}d-debug:{{if eq .Env.RELEASE "true"}}v{{ .Version }}{{else}}{{ .ShortCommit }}{{end}}-arm64v8' + - 'ghcr.io/archway-network/{{ .ProjectName }}d-dev:{{if eq .Env.RELEASE "true"}}v{{ .Version }}{{else}}{{ .ShortCommit }}{{end}}-amd64' + - 'ghcr.io/archway-network/{{ .ProjectName }}d-dev:{{if eq .Env.RELEASE "true"}}v{{ .Version }}{{else}}{{ .ShortCommit }}{{end}}-arm64v8' diff --git a/CHANGELOG.md b/CHANGELOG.md index a315f960..3695cc69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,19 +32,21 @@ Contains all the PRs that improved the code without changing the behaviours. ### Added +- [#439](https://github.com/archway-network/archway/pull/439) - adding containerized localnet - [#445](https://github.com/archway-network/archway/pull/445) - Adding Archway logo and version number to upgrade logs ### Changed ### Deprecated +- [#439](https://github.com/archway-network/archway/pull/439) - renaming `debug` image to `dev` + ### Removed ### Fixed ### Improvements - ## [v4.0.2](https://github.com/archway-network/archway/releases/tag/v4.0.2) ### Changed @@ -66,7 +68,7 @@ Contains all the PRs that improved the code without changing the behaviours. ### Added - [#429](https://github.com/archway-network/archway/pull/429) - Adding `cosmwasm_1_3` capabilities by bumping wasmd to v0.33.0 -- [#430](https://github.com/archway-network/archway/pull/430) - Added gh workflow to run chain upgarde test on PRs +- [#430](https://github.com/archway-network/archway/pull/430) - Added gh workflow to run chain upgrade test on PRs ### Changed @@ -106,14 +108,12 @@ Contains all the PRs that improved the code without changing the behaviours. Archway Network - Capture the value you create! - ## [v1.0.0-rc.4](https://github.com/archway-network/archway/releases/tag/v1.0.0-rc.4) ### Added - [#409](https://github.com/archway-network/archway/pull/409) - Add cosmwasm_1_1,cosmwasm_1_2 Cosmwasm capabilities - ## [v1.0.0-rc.3](https://github.com/archway-network/archway/releases/tag/v1.0.0-rc.3) ### Removed @@ -128,7 +128,7 @@ Archway Network - Capture the value you create! - [#402](https://github.com/archway-network/archway/pull/402) - Bump wasmvm version to 1.2.4 - [#403](https://github.com/archway-network/archway/pull/403) - Update libwasmvm version to correct one for wasmvm 1.2.4 - [#404](https://github.com/archway-network/archway/pull/403) - Fix typo in rewards query cli -- [#406](https://github.com/archway-network/archway/pull/406) - Add upgrade hanlder for v0.6.0 back to prevent downgrade check from panic / consensus failure; +- [#406](https://github.com/archway-network/archway/pull/406) - Add upgrade handler for v0.6.0 back to prevent downgrade check from panic / consensus failure; ## [v1.0.0-rc.1](https://github.com/archway-network/archway/releases/tag/v1.0.0-rc.1) @@ -227,7 +227,7 @@ Archway Network - Capture the value you create! ### Fixed -- [#338](https://github.com/archway-network/archway/pull/338) - fixed issue where contract premium was not completly being sent to the rewards address +- [#338](https://github.com/archway-network/archway/pull/338) - fixed issue where contract premium was not completely being sent to the rewards address ## [v0.3.1](https://github.com/archway-network/archway/releases/tag/v0.3.1) @@ -278,7 +278,7 @@ Archway Network - Capture the value you create! ### Fixed -- [#191](https://github.com/archway-network/archway/pull/191) - make localnet ovveride entrypoint +- [#191](https://github.com/archway-network/archway/pull/191) - make localnet override entrypoint - [#205](https://github.com/archway-network/archway/pull/205) - fix go.mod - [#216](https://github.com/archway-network/archway/pull/216) - fix dry-run cmd and bump cosmos-sdk do v0.45.8 - [#218](https://github.com/archway-network/archway/pull/218) - x/rewards unique ID genesis export/import diff --git a/Dockerfile.debug b/Dockerfile.dev similarity index 73% rename from Dockerfile.debug rename to Dockerfile.dev index 18e408f8..8e2c8a43 100644 --- a/Dockerfile.debug +++ b/Dockerfile.dev @@ -1,9 +1,12 @@ -FROM alpine:3.17 +FROM alpine:3.18 COPY ./archwayd /usr/bin/archwayd WORKDIR /root/.archway +# Install dev packages +RUN apk add --no-cache bash jq + # rest server EXPOSE 1317 # tendermint p2p diff --git a/Makefile b/Makefile index 359beb27..f146f183 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,8 @@ BUF_IMAGE=bufbuild/buf@sha256:9dc5d6645f8f8a2d5aaafc8957fbbb5ea64eada98a84cb0965 DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(BUF_IMAGE) HTTPS_GIT := https://github.com/archway-network/archway.git CURRENT_DIR := $(shell pwd) +SHORT_SHA := $(shell git rev-parse --short HEAD) +LATEST_TAG := $(shell git describe --tags --abbrev=0) # library versions LIBWASM_VERSION = $(shell go list -m -f '{{ .Version }}' github.com/CosmWasm/wasmvm) @@ -207,9 +209,6 @@ proto-lint: proto-check-breaking: @$(DOCKER_BUF) breaking --against-input $(HTTPS_GIT)#branch=master -localnet: - docker-compose up - docker-build: $(DOCKER) run \ --rm \ @@ -261,9 +260,17 @@ check-vuln-deps: ### Run Localnet ### ############################################################################### +# Run localnet in a containerized environment, starts new localnet +localnet: + TAG=$(LATEST_TAG) docker-compose up + +# Continue the stopped containerized localnet, starts the stopped containers +localnet-continue: + TAG=$(LATEST_TAG) CONTINUE="continue" docker-compose up + # Run a new localnet -run: - ./scripts/localnet.sh +run: build + ./scripts/localnet.sh # Continue the existing localnet run-continue: diff --git a/README.md b/README.md index c0eaf023..8b2a2df2 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ ![](https://github.com/archway-network/archway/blob/main/banner.png) + # Archway [![Version](https://img.shields.io/github/v/tag/archway-network/archway.svg?sort=semver&style=flat-square)](https://github.com/archway-network/archway/releases/latest) @@ -7,7 +8,6 @@ [![codecov](https://codecov.io/gh/archway-network/archway/branch/master/graph/badge.svg)](https://codecov.io/gh/archway-network/archway) [![License:Apache-2.0](https://img.shields.io/github/license/archway-network/archway.svg?style=flat-square)](https://github.com/archway-network/archway/LICENSE) - The core implementation of the Archway protocol leverages the [Cosmos SDK](https://cosmos.network) and [CosmWasm](https://cosmwasm.com) to reward validators and creators for their contributions to the network. ## System Requirements @@ -15,7 +15,7 @@ The core implementation of the Archway protocol leverages the [Cosmos SDK](https The following specifications have been found to work well: - An x86-64 (amd64) multi-core CPU (AMD / Intel); - - Higher clock speeds are preferred as Tendermint is mostly single-threaded; + - Higher clock speeds are preferred as Tendermint is mostly single-threaded; - 64GB RAM; - 1TB NVMe SSD Storage (disk i/o is crucial); - 100Mbps bi-directional Internet connection; @@ -24,10 +24,10 @@ The following specifications have been found to work well: The following software should be installed on the target system: -- The Go Programming Language (https://go.dev) -- Git Distributed Version Control (https://git-scm.com) -- Docker (https://www.docker.com) -- GNU Make (https://www.gnu.org/software/make) +- The Go Programming Language () +- Git Distributed Version Control () +- Docker () +- GNU Make () ## Build from Source @@ -49,7 +49,28 @@ A docker image for production purposes (no shell access): A docker image is also provided for test setups (shell access): -[Packages: archwayd-debug](https://github.com/orgs/archway-network/packages/container/package/archwayd-debug) +[Packages: archwayd-debug](https://github.com/orgs/archway-network/packages/container/package/archwayd-dev) + +## Running localnet + +There are two ways to run a localnet, local and containerized + +### Containerized + +This solution uses docker-compose and docker on the backend. +To setup new localnet use: + +``` +make localnet +``` + +To continue last localnet used: + +``` +make localnet-continue +``` + +### Local ## Documentation diff --git a/contrib/localnet/localnet.sh b/contrib/localnet/localnet.sh deleted file mode 100755 index 290d7f20..00000000 --- a/contrib/localnet/localnet.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/sh - -# this script instantiates localnet required genesis files - -set -e - -echo clearing $HOME/.archway -rm -rf $HOME/.archway -echo initting new chain -# init config files -archwayd init archwayd-id --chain-id localnet - -# create accounts -archwayd keys add fd --keyring-backend=test - -addr=$(archwayd keys show fd -a --keyring-backend=test) -val_addr=$(archwayd keys show fd --keyring-backend=test --bech val -a) - -# give the accounts some money -archwayd add-genesis-account "$addr" 1000000000000stake --keyring-backend=test - -# save configs for the daemon -archwayd gentx fd 10000000stake --chain-id localnet --keyring-backend=test - -# input genTx to the genesis file -archwayd collect-gentxs -# verify genesis file is fine -archwayd validate-genesis -echo changing network settings -sed -i 's/127.0.0.1/0.0.0.0/g' $HOME/.archway/config/config.toml - -echo test account address: "$addr" -echo test account private key: "$(yes | archwayd keys export fd --unsafe --unarmored-hex --keyring-backend=test)" -echo account for --from flag "fd" - -echo starting network... -archwayd start diff --git a/docker-compose.yaml b/docker-compose.yaml index 17c78877..ab781eef 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,17 +1,18 @@ +--- version: "3" services: node: - image: archwaynetwork/archwayd:latest - build: - context: . + image: ghcr.io/archway-network/archwayd-dev:${TAG} entrypoint: - sh - /opt/localnet.sh + - ${CONTINUE} ports: - 9090:9090 - 26657:26657 + - 26656:26656 volumes: - - ./contrib/localnet:/opt:z + - ./scripts:/opt:z - ./contracts:/contracts:z working_dir: /opt diff --git a/scripts/localnet.sh b/scripts/localnet.sh index 78161414..abb27559 100644 --- a/scripts/localnet.sh +++ b/scripts/localnet.sh @@ -1,10 +1,6 @@ -#!/bin/sh +#!/bin/bash + -# Console log text colour -red=`tput setaf 9` -green=`tput setaf 10` -blue=`tput setaf 12` -reset=`tput sgr0` echo_info () { echo "${blue}" @@ -25,7 +21,16 @@ echo_success () { } # Set localnet settings -BINARY=./build/archwayd +if [[ -f "build/archwayd" ]] ;then + BINARY=build/archwayd + # Console log text colour + red=`tput setaf 9` + green=`tput setaf 10` + blue=`tput setaf 12` + reset=`tput sgr0` +else + BINARY=archwayd +fi CHAIN_ID=localnet-1 CHAIN_DIR=./data VALIDATOR_MNEMONIC="guard cream sadness conduct invite crumble clock pudding hole grit liar hotel maid produce squeeze return argue turtle know drive eight casino maze host" @@ -56,8 +61,10 @@ setup_chain () { # Modify config for development config="$CHAIN_DIR/$CHAIN_ID/config/config.toml" if [ "$(uname)" = "Linux" ]; then - sed -i "s/cors_allowed_origins = \[\]/cors_allowed_origins = [\"*\"]/g" $config + sed -i "s/127.0.0.1/0.0.0.0/g" $config + sed -i "s/cors_allowed_origins = \[\]/cors_allowed_origins = [\"*\"]/g" $config else + sed -i '' "s/127.0.0.1/0.0.0.0/g" $config sed -i '' "s/cors_allowed_origins = \[\]/cors_allowed_origins = [\"*\"]/g" $config fi # modify genesis params for localnet ease of use @@ -69,7 +76,7 @@ setup_chain () { # reduce minimum deposit amount to 10stake contents="$(jq '.app_state.gov.deposit_params.min_deposit[0].amount = "10"' $genesis)" && echo "${contents}" > $genesis echo_info "Set x/gov proposal min deposit amount to 10 stake" - # reduce deposit period to 20seconds + # reduce deposit period to 20seconds contents="$(jq '.app_state.gov.deposit_params.max_deposit_period = "20s"' $genesis)" && echo "${contents}" > $genesis echo_info "Set x/gov proposal max deposit period to 20 seconds" @@ -109,11 +116,11 @@ setup_chain () { echo_error "Failed to validate genesis" fi } - + if [ "$1" != "continue" ] ;then - setup_chain + setup_chain fi # Starting chain echo_info "Starting chain..." -$BINARY --home $CHAIN_DIR/$CHAIN_ID start \ No newline at end of file +$BINARY --home $CHAIN_DIR/$CHAIN_ID start