Skip to content
Open
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
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ RUN --mount=type=cache,target=/go/pkg/mod \
CGO_ENABLED=${CGO_ENABLED} GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
make build

# Install Cosmovisor (pinned) for automated, governance-driven binary upgrades.
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
go install cosmossdk.io/tools/cosmovisor/cmd/cosmovisor@v1.7.0

# Stage 2: Create a minimal image to run the layerd binary
# Ignore hadolint rule because hadolint can't parse the variable.
# See https://github.com/hadolint/hadolint/issues/339
Expand All @@ -63,6 +68,17 @@ RUN apk update && apk add --no-cache \
-u ${UID}
# Copy the layerd binary from the builder into the final image.
COPY --from=builder /layer/build/layerd /bin/layerd
# Copy Cosmovisor (swaps the layerd binary at the on-chain upgrade height).
COPY --from=builder /go/bin/cosmovisor /bin/cosmovisor
# Cosmovisor settings. DAEMON_HOME is derived from --home at runtime (entrypoint.sh).
# Auto-download is OFF for safety: upgrade binaries are pre-staged per release.
# UNSAFE_SKIP_BACKUP is ON: backing up the full data dir before an upgrade is
# impractical on a live node (large data dir -> slow / can fill the disk and stall
# the upgrade). We rely on external snapshots instead. Matches the install script.
ENV DAEMON_NAME=layerd \
DAEMON_RESTART_AFTER_UPGRADE=true \
DAEMON_ALLOW_DOWNLOAD_BINARIES=false \
UNSAFE_SKIP_BACKUP=true
# Copy the entrypoint script into the final image.
COPY --chown=${USER_NAME}:${USER_NAME} docker/entrypoint.sh /opt/entrypoint.sh
# Set the user to layerdevnet.
Expand Down
45 changes: 36 additions & 9 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
#!/bin/bash
# Entrypoint: prepares files and launches layerd under Cosmovisor for automated,
# governance-driven binary upgrades. Non-"start" subcommands run layerd directly.
set -e

# This script creates the necessary files before starting layerd
# Derive the node home from --home (Cosmovisor needs DAEMON_HOME as an env var;
# it does not read the --home flag). Falls back to LAYER_HOME.
HOME_DIR="${LAYER_HOME}"
args=("$@")
for ((i = 0; i < ${#args[@]}; i++)); do
if [[ "${args[$i]}" == "--home" ]]; then
HOME_DIR="${args[$((i + 1))]}"
elif [[ "${args[$i]}" == --home=* ]]; then
HOME_DIR="${args[$i]#--home=}"
fi
done

export DAEMON_NAME="${DAEMON_NAME:-layerd}"
export DAEMON_HOME="${HOME_DIR}"
export DAEMON_RESTART_AFTER_UPGRADE="${DAEMON_RESTART_AFTER_UPGRADE:-true}"
export DAEMON_ALLOW_DOWNLOAD_BINARIES="${DAEMON_ALLOW_DOWNLOAD_BINARIES:-false}"

# only create the priv_validator_state.json if it doesn't exist and the command is start
if [[ $1 == "start" && ! -f ${LAYER_HOME}/data/priv_validator_state.json ]]
then
mkdir -p ${LAYER_HOME}/data
cat <<EOF > ${LAYER_HOME}/data/priv_validator_state.json
if [[ $1 == "start" && ! -f ${HOME_DIR}/data/priv_validator_state.json ]]; then
mkdir -p ${HOME_DIR}/data
cat <<EOF > ${HOME_DIR}/data/priv_validator_state.json
{
"height": "0",
"round": 0,
Expand All @@ -15,8 +32,18 @@ then
EOF
fi

echo "Starting layerd with command:"
echo "/bin/layerd $@"
echo ""
if [[ $1 == "start" ]]; then
# Seed the Cosmovisor layout once: cosmovisor/genesis/bin/layerd + current symlink.
if [[ ! -d "${DAEMON_HOME}/cosmovisor/genesis/bin" ]]; then
echo "Initializing cosmovisor at ${DAEMON_HOME}/cosmovisor"
cosmovisor init /bin/layerd
fi
echo "Starting layerd via cosmovisor with command:"
echo "cosmovisor run $@"
echo ""
exec cosmovisor run "$@"
fi

exec /bin/layerd $@
# Non-start subcommands (keys, genesis, version, ...) run layerd directly.
echo "Running layerd directly: /bin/layerd $@"
exec /bin/layerd "$@"