Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/docker improvements #702

Merged
merged 4 commits into from
Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
version: '3.7'
x-bech32-prefix: &BECH32_PREFIX
punk
x-wasmd-version: &WASMD_VERSION
v0.17.0

services:
genesis_validator:
build: docker/validator
build:
context: docker/validator
args:
BECH32_PREFIX: *BECH32_PREFIX
WASMD_VERSION: *WASMD_VERSION
image: validator:latest
ports:
- "26657:26657"
- "1317:1317"
container_name: genesis_validator
volumes:
- "genesis_volume:/genesis_volume"
environment:
BECH32_PREFIX: *BECH32_PREFIX
WASMD_VERSION: *WASMD_VERSION
command: ["genesis"]
secondary_validator:
build: docker/validator
build:
context: docker/validator
args:
BECH32_PREFIX: *BECH32_PREFIX
WASMD_VERSION: *WASMD_VERSION
image: validator:latest
volumes:
- "genesis_volume:/genesis_volume:ro"
environment:
BECH32_PREFIX: *BECH32_PREFIX
WASMD_VERSION: *WASMD_VERSION
depends_on:
- "genesis_validator"
command: ["secondary"]
Expand All @@ -34,6 +53,8 @@ services:
- "genesis_validator"
- "secondary_validator"
- "mixnet_contract"
environment:
BECH32_PREFIX: *BECH32_PREFIX
wallet:
build: docker/wallet-web
image: wallet:latest
Expand Down
4 changes: 2 additions & 2 deletions docker/typescript_client/upload_contract/upload-wasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as fs from 'fs';
async function newClient(): Promise<ValidatorClient> {
let contract = "fakeContractAddress"; // we don't have one yet
let mnemonic = fs.readFileSync("/genesis_volume/genesis_mnemonic", "utf8").slice(0, -1);
let admin = ValidatorClient.connect(contract, mnemonic, "http://genesis_validator:26657", "punk");
let admin = ValidatorClient.connect(contract, mnemonic, "http://genesis_validator:26657", process.env["BECH32_PREFIX"]);
return admin;
}

Expand All @@ -28,7 +28,7 @@ async function main() {
const { codeId } = uploadResult;
console.log("code id is", codeId)
const initMsg = {};
const options = { memo: "v0.1.0", transferAmount: [{ denom: "upunk", amount: "1000000" }], admin: admin.address }
const options = { memo: "v0.1.0", transferAmount: [{ denom: "u" + process.env["BECH32_PREFIX"], amount: "1000000" }], admin: admin.address }
let instantiateResult = await admin.instantiate(admin.address, codeId, initMsg, "mixnet contract", options);
let contractAddress = instantiateResult.contractAddress;
console.log(`mixnet contract ${contractAddress} instantiated successfully`)
Expand Down
2 changes: 2 additions & 0 deletions docker/validator/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM golang:buster as go_builder
ARG BECH32_PREFIX
ARG WASMD_VERSION
RUN apt update && apt install -y git build-essential
COPY setup.sh .
RUN ./setup.sh
Expand Down
67 changes: 38 additions & 29 deletions docker/validator/init_and_start.sh
Original file line number Diff line number Diff line change
@@ -1,44 +1,53 @@
#!/bin/sh

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/root
BECH32_PREFIX=punk
PASSPHRASE=passphrase

cd /root

if [ "$1" = "genesis" ]; then
./nymd init nymnet --chain-id nymnet 2> /dev/null
sed -i 's/minimum-gas-prices = ""/minimum-gas-prices = "0.025u'"${BECH32_PREFIX}"'"/' /root/.nymd/config/app.toml
sed -i '0,/enable = false/s//enable = true/g' /root/.nymd/config/app.toml
sed -i 's/cors_allowed_origins = \[\]/cors_allowed_origins = \["*"\]/' /root/.nymd/config/config.toml
sed -i 's/create_empty_blocks = true/create_empty_blocks = false/' /root/.nymd/config/config.toml
sed -i 's/laddr = "tcp:\/\/127.0.0.1:26657"/laddr = "tcp:\/\/0.0.0.0:26657"/' /root/.nymd/config/config.toml
yes "${PASSPHRASE}" | ./nymd keys add node_admin 2>&1 >/dev/null | tail -n 1 > /genesis_volume/genesis_mnemonic
ADDRESS=$(yes "${PASSPHRASE}" | ./nymd keys show node_admin -a)
yes "${PASSPHRASE}" | ./nymd add-genesis-account "${ADDRESS}" 1000000000000000u${BECH32_PREFIX},1000000000000000stake
yes "${PASSPHRASE}" | ./nymd gentx node_admin 1000000000stake --chain-id nymnet 2> /dev/null
./nymd collect-gentxs 2> /dev/null
./nymd validate-genesis > /dev/null
cp /root/.nymd/config/genesis.json /genesis_volume/genesis.json
if [ ! -d "/root/.nymd" ]; then
jstuczyn marked this conversation as resolved.
Show resolved Hide resolved
./nymd init nymnet --chain-id nymnet 2> /dev/null
sed -i 's/minimum-gas-prices = ""/minimum-gas-prices = "0.025u'"${BECH32_PREFIX}"'"/' /root/.nymd/config/app.toml
sed -i '0,/enable = false/s//enable = true/g' /root/.nymd/config/app.toml
sed -i 's/cors_allowed_origins = \[\]/cors_allowed_origins = \["*"\]/' /root/.nymd/config/config.toml
sed -i 's/create_empty_blocks = true/create_empty_blocks = false/' /root/.nymd/config/config.toml
sed -i 's/laddr = "tcp:\/\/127.0.0.1:26657"/laddr = "tcp:\/\/0.0.0.0:26657"/' /root/.nymd/config/config.toml
yes "${PASSPHRASE}" | ./nymd keys add node_admin 2>&1 >/dev/null | tail -n 1 > /genesis_volume/genesis_mnemonic
ADDRESS=$(yes "${PASSPHRASE}" | ./nymd keys show node_admin -a)
yes "${PASSPHRASE}" | ./nymd add-genesis-account "${ADDRESS}" 1000000000000000u${BECH32_PREFIX},1000000000000000stake
yes "${PASSPHRASE}" | ./nymd gentx node_admin 1000000000stake --chain-id nymnet 2> /dev/null
./nymd collect-gentxs 2> /dev/null
./nymd validate-genesis > /dev/null
cp /root/.nymd/config/genesis.json /genesis_volume/genesis.json
else
echo "Validator already initialized, starting with the existing configuration."
echo "If you want to re-init the validator, destroy the existing container"
fi
./nymd start
elif [ "$1" = "secondary" ]; then
./nymd init nymnet --chain-id nym-secondary 2> /dev/null
if [ ! -d "/root/.nymd" ]; then
./nymd init nymnet --chain-id nym-secondary 2> /dev/null

# Wait until the genesis node writes the genesis.json to the shared volume
while ! [ -s /genesis_volume/genesis.json ]; do
sleep 1
done
# Wait until the genesis node writes the genesis.json to the shared volume
while ! [ -s /genesis_volume/genesis.json ]; do
sleep 1
done

cp /genesis_volume/genesis.json /root/.nymd/config/genesis.json
GENESIS_PEER=$(cat /root/.nymd/config/genesis.json | grep '"memo"' | cut -d'"' -f 4)
sed -i 's/persistent_peers = ""/persistent_peers = "'"${GENESIS_PEER}"'"/' /root/.nymd/config/config.toml
sed -i 's/minimum-gas-prices = ""/minimum-gas-prices = "0.025u'"${BECH32_PREFIX}"'"/' /root/.nymd/config/app.toml
sed -i '0,/enable = false/s//enable = true/g' /root/.nymd/config/app.toml
sed -i 's/cors_allowed_origins = \[\]/cors_allowed_origins = \["*"\]/' /root/.nymd/config/config.toml
sed -i 's/create_empty_blocks = true/create_empty_blocks = false/' /root/.nymd/config/config.toml
sed -i 's/laddr = "tcp:\/\/127.0.0.1:26657"/laddr = "tcp:\/\/0.0.0.0:26657"/' /root/.nymd/config/config.toml
yes "${PASSPHRASE}" | ./nymd keys add node_admin 2> mnemonic > /dev/null
./nymd validate-genesis > /dev/null
cp /genesis_volume/genesis.json /root/.nymd/config/genesis.json
GENESIS_PEER=$(cat /root/.nymd/config/genesis.json | grep '"memo"' | cut -d'"' -f 4)
sed -i 's/persistent_peers = ""/persistent_peers = "'"${GENESIS_PEER}"'"/' /root/.nymd/config/config.toml
sed -i 's/minimum-gas-prices = ""/minimum-gas-prices = "0.025u'"${BECH32_PREFIX}"'"/' /root/.nymd/config/app.toml
sed -i '0,/enable = false/s//enable = true/g' /root/.nymd/config/app.toml
sed -i 's/cors_allowed_origins = \[\]/cors_allowed_origins = \["*"\]/' /root/.nymd/config/config.toml
sed -i 's/create_empty_blocks = true/create_empty_blocks = false/' /root/.nymd/config/config.toml
sed -i 's/laddr = "tcp:\/\/127.0.0.1:26657"/laddr = "tcp:\/\/0.0.0.0:26657"/' /root/.nymd/config/config.toml
yes "${PASSPHRASE}" | ./nymd keys add node_admin 2> mnemonic > /dev/null
./nymd validate-genesis > /dev/null
else
echo "Validator already initialized, starting with the existing configuration."
echo "If you want to re-init the validator, destroy the existing container"
fi
./nymd start
else
echo "Wrong command. Usage: ./$0 [genesis/secondary]"
Expand Down
3 changes: 0 additions & 3 deletions docker/validator/setup.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#!/bin/sh

WASMD_VERSION=v0.17.0
BECH32_PREFIX=punk

git clone https://github.com/CosmWasm/wasmd.git
cd wasmd
git checkout "${WASMD_VERSION}"
Expand Down