Skip to content

Commit

Permalink
fix: docker imports, clean up sh scripts, test all the things
Browse files Browse the repository at this point in the history
  • Loading branch information
gluax committed Nov 2, 2023
1 parent b31a699 commit 4f721f9
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 97 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ dist/
scripts/testnet/config.sh
scripts/testnet/nodes
scripts/testnet/artifacts

# Ignore local env files
seda.env
.env
45 changes: 21 additions & 24 deletions dockerfiles/Dockerfile.node-static
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# syntax=docker/dockerfile:1
ARG GO_VERSION="1.20"
ARG RUNNER_IMAGE="gcr.io/distroless/static-debian11"

# --------------------------------------------------------
# Builder
Expand All @@ -26,7 +25,7 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
# Cosmwasm - Download correct libwasmvm version
RUN ARCH=$(uname -m) && WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm | sed 's/.* //') && \
wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm_muslc.$ARCH.a \
-O /lib/libwasmvm_muslc.a && \
-O /lib/libwasmvm_muslc.a && \
# verify checksum
wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/checksums.txt -O /tmp/checksums.txt && \
sha256sum /lib/libwasmvm_muslc.a | grep $(cat /tmp/checksums.txt | grep libwasmvm_muslc.$ARCH | cut -d ' ' -f 1)
Expand All @@ -38,30 +37,28 @@ COPY . .
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/root/go/pkg/mod \
GOWORK=off go build -v \
-mod=readonly \
-tags "netgo,ledger,muslc" \
-ldflags \
"-X github.com/cosmos/cosmos-sdk/version.Name="seda-chain" \
-X github.com/cosmos/cosmos-sdk/version.AppName="seda-chaind" \
-X github.com/cosmos/cosmos-sdk/version.Version=${GIT_VERSION} \
-X github.com/cosmos/cosmos-sdk/version.Commit=${GIT_COMMIT} \
-X github.com/cosmos/cosmos-sdk/version.BuildTags=netgo,ledger,muslc \
-w -s -linkmode=external -extldflags '-Wl,-z,muldefs -static'" \
-trimpath \
-o /seda-chain/build/seda-chaind \
cmd/seda-chaind/main.go
# --------- To include chmod and shell for static image
FROM busybox:1.35.0-uclibc as busybox
-mod=readonly \
-tags "netgo,ledger,muslc" \
-ldflags \
"-X github.com/cosmos/cosmos-sdk/version.Name="seda-chain" \
-X github.com/cosmos/cosmos-sdk/version.AppName="seda-chaind" \
-X github.com/cosmos/cosmos-sdk/version.Version=${GIT_VERSION} \
-X github.com/cosmos/cosmos-sdk/version.Commit=${GIT_COMMIT} \
-X github.com/cosmos/cosmos-sdk/version.BuildTags=netgo,ledger,muslc \
-w -s -linkmode=external -extldflags '-Wl,-z,muldefs -static'" \
-trimpath \
-o /seda-chain/build/seda-chaind \
cmd/seda-chaind/main.go
# --------------------------------------------------------
# Runner
# --------------------------------------------------------
FROM ${RUNNER_IMAGE}
FROM alpine:latest

COPY --from=busybox ["/bin/sh", "/bin/chmod", "/bin/chown", "/bin/mkdir", "/bin/"]
RUN mkdir -p /seda-chain/.seda-chain && chown nonroot:nonroot -R /seda-chain/.seda-chain
RUN mkdir -p /seda-chain/.seda-chain

USER nonroot
COPY --from=builder --chown=nonroot:nonroot /seda-chain/build/seda-chaind /bin/seda-chaind
COPY --from=builder /seda-chain/build/seda-chaind /bin/seda-chaind

RUN apk add --no-cache bash expect jq

ENV HOME /seda-chain
WORKDIR $HOME
Expand All @@ -71,6 +68,6 @@ EXPOSE 26657
EXPOSE 1317
EXPOSE 9090

COPY --chown=nonroot:nonroot scripts/validator_setup/validator_setup.sh .
RUN chmod +x validator_setup.sh
ENTRYPOINT ["sh", "validator_setup.sh"]
COPY scripts/node_setup/* .
RUN find . -type f -name "*.sh" -exec chmod +x {} \;
ENTRYPOINT ["bash", "setup_run_node.sh"]
15 changes: 15 additions & 0 deletions scripts/node_setup/become_validator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
# Tell script to exit immediately if any cmd fails
set -e

BIN="seda-chaind"
KEY_NAME="${KEY_NAME:-default_key}"
STAKE_AMOUNT="$1aseda"

source common.sh

validator_pub_key=$($BIN tendermint show-validator --home=$HOME/.seda-chain)

chain_id=$(cat $HOME/.seda-chain/config/genesis.json | jq .chain_id | tr -d '"')
auth_seda_chaind_command tx staking create-validator --amount=$STAKE_AMOUNT --pubkey=$validator_pub_key --moniker=$MONIKER --commission-rate=0.10 --commission-max-rate=0.20 --commission-max-change-rate=0.01 --gas=auto --gas-adjustment=1.2 --gas-prices=0.0025aseda --from=$KEY_NAME --min-self-delegation=1 --yes --home=$HOME/.seda-chain --chain-id=$chain_id

13 changes: 13 additions & 0 deletions scripts/node_setup/check_validator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
# Tell script to exit immediately if any cmd fails
set -e

BIN="seda-chaind"
KEY_NAME="${KEY_NAME:-default_key}"

source common.sh

validator_address=$(auth_seda_chaind_command keys show $KEY_NAME --bech val | grep "address:" | awk '{print $3}')
output=$(seda-chaind query staking validator $validator_address 2>&1)
echo "$output" | grep "error:" || echo "$output"

18 changes: 18 additions & 0 deletions scripts/node_setup/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

function auth_seda_chaind_command {
local args=("$@")
output=$(expect -c "
spawn $BIN ${args[*]}
expect {
\"Enter keyring passphrase (attempt 1/3):\" {
send \"$KEYRING_PASSWORD\r\"
}
timeout {
send_user \"Timed out waiting for enter passphrase prompt\r\"
exit 1
}
}
expect eof
")
echo "$output"
}
133 changes: 133 additions & 0 deletions scripts/node_setup/setup_run_node.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#!/usr/bin/env bash
# Tell script to exit immediately if any cmd fails
set -e

# Basic Setup Configuration
# --------------------------
# This script is used to setup a node for the seda-chain network.


BIN=seda-chaind
KEY_NAME="${KEY_NAME:-default_key}"

# Check if a env variable exists
# returns true if it doesn't exist false otherwise
function check_env_var {
local var_name="$1"
if [[ -z "${!var_name}" ]]; then
echo "Error: no key $var_name provided"
return 1
fi
return 0
}

# Define an error boolean
# Then check if required env variables are set
error=0
check_env_var "MONIKER" || error=1
check_env_var "NODE_ADDRESS" || error=1
check_env_var "NETWORK" || error=1

# TODO
# check_env_var "VALIDATOR" || error=1
# if [[ "$VALIDATOR" == "true" ]]; then
# echo "Error: MNEMONIC is required for validator nodes since it requires funds"
# check_env_var "MNEMONIC" || error=1
# fi

# If any one of them was missing then exit
if (( error )); then
exit 1
fi

# Set the keyring backend to file
$BIN config keyring-backend file

function create_or_import_key {
local key_name="$1"
local mnemonic="$2"
local recover_flag="$3"

output=$(expect -c "
set key_name \"$key_name\"
set recover_flag \"$recover_flag\"
set mnemonic \"$mnemonic\"
spawn seda-chaind keys add \$key_name \$recover_flag
expect {
\"> Enter your bip39 mnemonic\" {
send \"$mnemonic\r\"
}
timeout {
send_user \"Timed out waiting for enter mnemonic prompt\r\"
exit 1
}
}
expect {
\"Enter keyring passphrase (attempt 1/3):\" {
send \"$KEYRING_PASSWORD\r\"
expect {
\"Re-enter keyring passphrase:\" {
send \"$KEYRING_PASSWORD\r\"
}
timeout {
# We're done if we timeout after sending the passphrase
}
}
}
timeout {
send_user \"Timed out waiting for enter passphrase prompt\r\"
exit 1
}
}
expect eof
")


echo "$output"
}

# If the MNEMONIC is provided we import it
if [[ ! -z "${MNEMONIC}" ]]; then
echo "Importing provided MNEMONIC..."
create_or_import_key "$KEY_NAME" "$MNEMONIC" "--recover"
# If the MNEMONIC is not provided we generate one
else
echo "Error no key MNEMONIC provided generating one..."
echo "NOTE: This is done in the file backend..."
echo "We recommend storing this somewhere secure..."
output=$(create_or_import_key "$KEY_NAME" "" "")
# We greb the mnemonic from the output.
mnemonic=$(echo "$output" | awk '/Important/,0' | tail -n 1)
# We check if the `env` file had a MNEMONIC variable in general...
awk -v mnemonic="$mnemonic" 'BEGIN{OFS=FS="="} $1=="MNEMONIC"{$2=mnemonic}1' .env > .env.tmp && cat .env.tmp > .env && rm .env.tmp
# Lastly set the env variable for this session.
export MNEMONIC="$mnemonic"
fi


# Initialize NODE config
echo "Initializing Node ..."

# # Give docker image permission to write to the seda-chain config directory
# chmod -R a+w /seda-chain/.seda-chain

# Check if configuration directory seda-chain config directory exist if it does not
# exist initialize the node with the given MNEMONIC, MONIKER and NETWORK
if ! [ -f /seda-chain/.seda-chain/config/genesis.json ]; then
echo "Setting Up seda configuration"
echo $MNEMONIC | $BIN init join ${MONIKER} --network ${NETWORK} --recover
else
echo "seda configuration already exists"
fi

echo "Node Initialized !"


# It creates a Client to the seda-chain network
echo "Connecting to Network `$NETWORK`..."
$BIN config node $NODE_ADDRESS
echo "Connected to network !"

# Run node
echo "Running Node ..."
$BIN start
73 changes: 0 additions & 73 deletions scripts/validator_setup/validator_setup.sh

This file was deleted.

0 comments on commit 4f721f9

Please sign in to comment.