Skip to content

Commit

Permalink
update swagger and docker
Browse files Browse the repository at this point in the history
  • Loading branch information
dheerajkd30 committed Mar 2, 2023
1 parent 6de8ed8 commit 1156e57
Show file tree
Hide file tree
Showing 15 changed files with 316 additions and 1,117 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
53 changes: 53 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# docker build . -t cosmoscontracts/comdex:latest
# docker run --rm -it cosmoscontracts/comdex:latest /bin/sh
FROM golang:1.20-alpine AS go-builder

# this comes from standard alpine nightly file
# https://github.com/rust-lang/docker-rust-nightly/blob/master/alpine3.12/Dockerfile
# with some changes to support our toolchain, etc
SHELL ["/bin/sh", "-ecuxo", "pipefail"]
# we probably want to default to latest and error
# since this is predominantly for dev use
# hadolint ignore=DL3018
RUN apk add --no-cache ca-certificates build-base git
# NOTE: add these to run with LEDGER_ENABLED=true
# RUN apk add libusb-dev linux-headers

WORKDIR /code
COPY . /code/

# See https://github.com/CosmWasm/wasmvm/releases
ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.1.1/libwasmvm_muslc.aarch64.a /lib/libwasmvm_muslc.aarch64.a
ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.1.1/libwasmvm_muslc.x86_64.a /lib/libwasmvm_muslc.x86_64.a
RUN sha256sum /lib/libwasmvm_muslc.aarch64.a | grep 9ecb037336bd56076573dc18c26631a9d2099a7f2b40dc04b6cae31ffb4c8f9a
RUN sha256sum /lib/libwasmvm_muslc.x86_64.a | grep 6e4de7ba9bad4ae9679c7f9ecf7e283dd0160e71567c6a7be6ae47c81ebe7f32

# Copy the library you want to the final location that will be found by the linker flag `-lwasmvm_muslc`
RUN cp "/lib/libwasmvm_muslc.$(uname -m).a" /lib/libwasmvm_muslc.a

# force it to use static lib (from above) not standard libgo_cosmwasm.so file
# then log output of file /code/bin/comdex
# then ensure static linking
RUN LEDGER_ENABLED=false BUILD_TAGS=muslc LINK_STATICALLY=true make build \
&& file /code/bin/comdex \
&& echo "Ensuring binary is statically linked ..." \
&& (file /code/bin/comdex | grep "statically linked")

# --------------------------------------------------------
FROM alpine:3.16

COPY --from=go-builder /code/bin/comdex /usr/bin/comdex

COPY docker/* /opt/
RUN chmod +x /opt/*.sh

WORKDIR /opt

# rest server
EXPOSE 1317
# tendermint p2p
EXPOSE 26656
# tendermint rpc
EXPOSE 26657

CMD ["/usr/bin/comdex", "version"]
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ PACKAGES_SIMTEST=$(shell go list ./... | grep '/simulation')
LEDGER_ENABLED ?= true
SDK_PACK := $(shell go list -m github.com/cosmos/cosmos-sdk | sed 's/ /\@/g')
TM_VERSION := $(shell go list -m github.com/tendermint/tendermint | sed 's:.* ::') # grab everything after the space in "github.com/tendermint/tendermint v0.34.7"
DOCKER := $(shell which docker)
DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf:1.0.0-rc8
BUILDDIR ?= $(CURDIR)/build
GOBIN = $(shell go env GOPATH)/bin
GOARCH = $(shell go env GOARCH)
Expand Down Expand Up @@ -176,6 +178,14 @@ endif

.PHONY: run-tests test test-all $(TEST_TARGETS)

protoVer=v0.1
containerProtoGenSwagger=comdex-proto-gen-swagger-$(protoVer)

proto-swagger-gen:
@echo "Generating Protobuf Swagger"
@if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerProtoGenSwagger}$$"; then docker start -a $(containerProtoGenSwagger); else docker run --name $(containerProtoGenSwagger) -v $(CURDIR):/workspace --workdir /workspace $(protoImageName) \
sh ./scripts/protoc-swagger-gen.sh; fi

test-sim-nondeterminism:
@echo "Running non-determinism test..."
@go test -mod=readonly $(SIMAPP) -run TestAppStateDeterminism -Enabled=true \
Expand Down
17 changes: 17 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
version: "3"
services:
node:
build:
context: .
args:
- arch=${ARCH:-x86_64}
command: ./setup_and_run.sh comdex1pkkayn066msg6kn33wnl5srhdt3tnu2v9jjqu0
ports:
- 1317:1317 # rest
- 26656:26656 # p2p
- 26657:26657 # rpc
environment:
- GAS_LIMIT=${GAS_LIMIT:-10000000}
- STAKE_TOKEN=${STAKE_TOKEN:-ucmdx}
- TIMEOUT_COMMIT=${TIMEOUT_COMMIT:-5s}
9 changes: 9 additions & 0 deletions docker/run_comdex.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

if test -n "$1"; then
# need -R not -r to copy hidden files
cp -R "$1/.comdex" /root
fi

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

./setup_comdex.sh "$@"
./run_comdex.sh
70 changes: 70 additions & 0 deletions docker/setup_comdex.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/sh
#set -o errexit -o nounset -o pipefail

PASSWORD=${PASSWORD:-1234567890}
STAKE=${STAKE_TOKEN:-ustake}
FEE=${FEE_TOKEN:-ucosm}
CHAIN_ID=${CHAIN_ID:-testing}
MONIKER=${MONIKER:-node001}
KEYRING="--keyring-backend test"
TIMEOUT_COMMIT=${TIMEOUT_COMMIT:-5s}
BLOCK_GAS_LIMIT=${GAS_LIMIT:-10000000} # should mirror mainnet

echo "Configured Block Gas Limit: $BLOCK_GAS_LIMIT"

# check the genesis file
GENESIS_FILE="$HOME"/.comdex/config/genesis.json
GENESIS_FILE="$HOME"/.comdex/config/genesis.json
if [ -f "$GENESIS_FILE" ]; then
echo "$GENESIS_FILE exists..."
else
echo "$GENESIS_FILE does not exist. Generating..."

comdex init --chain-id "$CHAIN_ID" "$MONIKER"
comdex add-ica-config
# staking/governance token is hardcoded in config, change this
sed -i "s/\"stake\"/\"$STAKE\"/" "$GENESIS_FILE"
# this is essential for sub-1s block times (or header times go crazy)
sed -i 's/"time_iota_ms": "1000"/"time_iota_ms": "10"/' "$GENESIS_FILE"
# change gas limit to mainnet value
sed -i 's/"max_gas": "-1"/"max_gas": "'"$BLOCK_GAS_LIMIT"'"/' "$GENESIS_FILE"
# change default keyring-backend to test
sed -i 's/keyring-backend = "os"/keyring-backend = "test"/' "$HOME"/.comdex/config/client.toml
fi

APP_TOML_CONFIG="$HOME"/.comdex/config/app.toml
APP_TOML_CONFIG_NEW="$HOME"/.comdex/config/app_new.toml
CONFIG_TOML_CONFIG="$HOME"/.comdex/config/config.toml
if [ -n "$UNSAFE_CORS" ]; then
echo "Unsafe CORS set... updating app.toml and config.toml"
# sorry about this bit, but toml is rubbish for structural editing
sed -n '1h;1!H;${g;s/# Enable defines if the API server should be enabled.\nenable = false/enable = true/;p;}' "$APP_TOML_CONFIG" > "$APP_TOML_CONFIG_NEW"
mv "$APP_TOML_CONFIG_NEW" "$APP_TOML_CONFIG"
# ...and breathe
sed -i "s/enabled-unsafe-cors = false/enabled-unsafe-cors = true/" "$APP_TOML_CONFIG"
sed -i "s/cors_allowed_origins = \[\]/cors_allowed_origins = \[\"\*\"\]/" "$CONFIG_TOML_CONFIG"
fi

# speed up block times for testing environments
sed -i "s/timeout_commit = \"5s\"/timeout_commit = \"$TIMEOUT_COMMIT\"/" "$CONFIG_TOML_CONFIG"

# are we running for the first time?
if ! comdex keys show validator $KEYRING; then
(echo "$PASSWORD"; echo "$PASSWORD") | comdex keys add validator $KEYRING

# hardcode the validator account for this instance
echo "$PASSWORD" | comdex add-genesis-account validator "1000000000$STAKE,1000000000$FEE" $KEYRING

# (optionally) add a few more genesis accounts
for addr in "$@"; do
echo $addr
comdex add-genesis-account "$addr" "1000000000$STAKE,1000000000$FEE"
done

# submit a genesis validator tx
## Workraround for https://github.com/cosmos/cosmos-sdk/issues/8251
(echo "$PASSWORD"; echo "$PASSWORD"; echo "$PASSWORD") | comdex gentx validator "250000000$STAKE" --chain-id="$CHAIN_ID" --amount="250000000$STAKE" $KEYRING
## should be:
# (echo "$PASSWORD"; echo "$PASSWORD"; echo "$PASSWORD") | comdex gentx validator "250000000$STAKE" --chain-id="$CHAIN_ID"
comdex collect-gentxs
fi
2 changes: 2 additions & 0 deletions docker/test-user.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
TEST_ADDR=comdex1pkkayn066msg6kn33wnl5srhdt3tnu2v9jjqu0
TEST_MNEMONIC="wage thunder live sense resemble foil apple course spin horse glass mansion midnight laundry acoustic rhythm loan scale talent push green direct brick please"
66 changes: 0 additions & 66 deletions docs/docs.go

This file was deleted.

Loading

0 comments on commit 1156e57

Please sign in to comment.