Skip to content

Commit

Permalink
CNS-140: dockerize lavad setup
Browse files Browse the repository at this point in the history
Update the Dockerfile to generate docker image that can run lava node.
(Implemented using the artifacts in docker/ directory.)

To start a lava node in a container, run the command:
    docker-compose --profile node -f docker/docker-compose.yml up

It will execute the script `start_node.sh` (from docker/), which follows
the instructions for starting a node (with cosmovisor).
  • Loading branch information
orenl-lava committed Jan 17, 2023
1 parent 41ca04b commit e70ae4e
Show file tree
Hide file tree
Showing 4 changed files with 206 additions and 2 deletions.
35 changes: 33 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,42 @@ RUN --mount=type=cache,target=/root/.cache/go-build \

# Download debian packages for runner

FROM ${RUNNER_IMAGE}
FROM ${RUNNER_IMAGE} as runner-base

RUN apt-get update \
&& apt-get install -yqq --no-install-recommends \
git curl unzip ca-certificates \
&& apt-get -y purge \
&& apt-get -y clean \
&& apt-get -y autoremove \
&& rm -rf /var/lib/apt/lists/*

# --------------------------------------------------------
# Runner
# --------------------------------------------------------

FROM runner-base

COPY --from=cosmovisor /go/bin/cosmovisor /bin/cosmovisor
COPY --from=builder /lava/build/lavad /bin/lavad

ENV HOME /lava
WORKDIR $HOME

ENTRYPOINT ["/bin/lavad"]
COPY docker/entrypoint.sh /
COPY docker/start_node.sh start_node.sh

# lava api
EXPOSE 1317
# rosetta
EXPOSE 8080
# grpc
EXPOSE 9090
# grpc-web
EXPOSE 9090
# tendermint p2p
EXPOSE 26656
# tendermint rpc
EXPOSE 26657

ENTRYPOINT ["/entrypoint.sh"]
27 changes: 27 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: '3.9'

x-env: &env-common
environment:
- LAVA_EXTERNAL_IP=${LAVA_EXTERNAL_IP:-0.0.0.0}

services:

lava-node:
build: ..
image: lava:latest
command: "node"
<<: *env-common
ports:
- '${LAVA_EXTERNAL_IP:-0.0.0.0}:1317:1317'
- '${LAVA_EXTERNAL_IP:-0.0.0.0}:9090:9090'
- '${LAVA_EXTERNAL_IP:-0.0.0.0}:9091:9091'
- '${LAVA_EXTERNAL_IP:-0.0.0.0}:26656:26656'
- '${LAVA_EXTERNAL_IP:-0.0.0.0}:26657:26657'
deploy:
resources:
limits:
cpus: '4'
memory: '8gb'
restart: unless-stopped
profiles: ["node"]

47 changes: 47 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/sh
# vim:sw=4:ts=4:et

set -e

if [ -z "${LAVA_QUIET_LOGS:-}" ]; then
exec 3>&1
else
exec 3>/dev/null
fi

if /usr/bin/find "/entrypoint.d/" -mindepth 1 -maxdepth 1 -type f -print -quit 2>/dev/null | read v; then
echo >&3 "$0: Looking for shell scripts in /entrypoint.d/"
find "/entrypoint.d/" -follow -type f -print | sort -n | while read -r f; do
case "$f" in
*.sh)
if [ -x "$f" ]; then
echo >&3 "$0: Launching $f";
"$f"
else
# warn on shell scripts without exec bit
echo >&3 "$0: Ignoring $f, not executable";
fi
;;
*) echo >&3 "$0: Ignoring $f";;
esac
done
echo >&3 "$0: Configuration complete; ready for start up"
else
echo >&3 "$0: No files found in /entrypoint.d/, skipping configuration"
fi

if [ $# -lt 1 ]; then
echo >&3 "$0: No command given"
exit 1
fi

case _"$1" in
_node) cmd="/lava/start_node.sh" ;;
*) cmd="$1" ;;
esac

shift

echo >&3 "$0: Launching $cmd $@"

exec "$cmd" "$@"
99 changes: 99 additions & 0 deletions docker/start_node.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/bin/sh
# vim:sw=4:ts=4:et

set -e

SETUP_CONFIG_GIT_URL='https://github.com/K433QLtr6RA9ExEq/GHFkqmTzpdNLDd6T.git'
COSMOVISOR_ZIP_URL='https://lava-binary-upgrades.s3.amazonaws.com/testnet/cosmovisor-upgrades/cosmovisor-upgrades.zip'

debug() {
echo "DBG: $@"
}

error() {
echo "ERR: $@"
exit 1
}

setup_node() {
setup_config_dir=$(basename ${SETUP_CONFIG_GIT_URL})

# remove old data (if any)
rm -rf ${setup_config_dir}

# download setup configuration
git clone --depth 1 ${SETUP_CONFIG_GIT_URL} ${setup_config_dir} || \
error "setup: failed to clone setup configuration"

cd ${setup_config_dir}/testnet-1
. setup_config/setup_config.sh

# keep a copy handy for when we restart
cp setup_config/setup_config.sh ${HOME}

# remove old config (if any)
rm -rf ${lavad_home_folder}

# copy initial configuration and genesis data
mkdir -p ${lavad_home_folder}
mkdir -p ${lava_config_folder}
cp default_lavad_config_files/* ${lava_config_folder}
cp genesis_json/genesis.json ${lava_config_folder}/genesis.json
}

setup_env() {
# environment variables for cosmovisor
export DAEMON_NAME=lavad
export CHAIN_ID=lava-testnet-1
export DAEMON_HOME=$HOME/.lava
export DAEMON_ALLOW_DOWNLOAD_BINARIES=true
export DAEMON_LOG_BUFFER_SIZE=512
export DAEMON_RESTART_AFTER_UPGRADE=true
export UNSAFE_SKIP_BACKUP=true
}

# note: expected to run in the setup config directory - see setup_node())
setup_cosmovisor() {
# download latest cosmovisor-upgrades
curl -L --progress-bar -o cosmovisor-upgrades.zip "${COSMOVISOR_ZIP_URL}" || \
error "setup: failed to download cosmovisor upgrades"
unzip cosmovisor-upgrades.zip || \
error "setup: failed to unzip cosmovisor upgrades"

# copy cosmovisor configuration
mkdir -p ${lavad_home_folder}/cosmovisor
cp -r cosmovisor-upgrades/* ${lavad_home_folder}/cosmovisor

# initialize the chain
output=$( \
${lavad_home_folder}/cosmovisor/genesis/bin/lavad init \
my-node \
--chain-id lava-testnet-1 \
--home ${lavad_home_folder} \
--overwrite \
)

# an error message about missing upgrade-info.json is expected;
# anything else is unexpected and should abort.
if [ $? -ne 0 ]; then
case "$output" in
"*upgrade-info.json: no such file or directory*") ;;
"*") error "setup: failed to initialize the chain" ;;
esac
fi

# copy genesis data again
cp genesis_json/genesis.json ${lava_config_folder}/genesis.json
}

setup_env

if [ ! -e ${HOME}/.lava/cosmovisor/current ]; then
setup_node
setup_cosmovisor
else
. ${HOME}/setup_config.sh
fi

exec /bin/cosmovisor start --home=${lavad_home_folder} --p2p.seeds ${seed_node}

0 comments on commit e70ae4e

Please sign in to comment.