Skip to content

Commit

Permalink
chore: adds container image for jormungandr
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgilman committed Nov 16, 2023
1 parent 55c798d commit 5784b68
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 1 deletion.
22 changes: 21 additions & 1 deletion Earthfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Set the Earthly version to 0.7
VERSION 0.7
FROM debian:stable-slim

rust-toolchain:
FROM rust:1.71-slim-bullseye
Expand Down Expand Up @@ -71,3 +70,24 @@ build:

SAVE ARTIFACT /src/target/release/jormungandr jormungandr
SAVE ARTIFACT /src/target/release/jcli jcli

publish:
FROM debian:stable-slim
WORKDIR /app

ARG tag=latest

# Install build dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends \
libssl-dev \
libpq-dev \
libsqlite3-dev

COPY +build/jormungandr .
COPY jormungandr/entrypoint.sh .
RUN chmod +x entrypoint.sh

ENTRYPOINT ["/app/entrypoint.sh"]

SAVE IMAGE jormungandr:${tag}
91 changes: 91 additions & 0 deletions jormungandr/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/usr/bin/bash

echo ">>> Entering entrypoint script..."

# Verify the storage path exists
if [[ ! -d "$STORAGE_PATH" ]]; then
echo "ERROR: storage path does not exist at: $STORAGE_PATH"
echo ">>> Aborting..."
exit 1
fi

# Verify config is present
if [[ ! -f "$NODE_CONFIG_PATH" ]]; then
echo "ERROR: node configuration is absent at: $NODE_CONFIG_PATH"
echo ">>> Aborting..."
exit 1
fi

# Verify genesis block is present
if [[ ! -f "$GENESIS_PATH" ]]; then
echo "ERROR: genesis block is absent at: $GENESIS_PATH"
echo ">>> Aborting..."
exit 1
fi

# Allow overriding jormungandr binary
BIN_PATH=''${BIN_PATH:=/app/jormungandr}

echo ">>> Using the following parameters:"
echo "Storage path: $STORAGE_PATH"
echo "Node config: $NODE_CONFIG_PATH"
echo "Genesis block: $GENESIS_PATH"
echo "Binary path: $BIN_PATH"

args+=()
args+=("--storage" "$STORAGE_PATH")
args+=("--config" "$NODE_CONFIG_PATH")
args+=("--genesis-block" "$GENESIS_PATH")

if [[ -n "${LEADER:=}" ]]; then
echo ">>> Configuring node as leader..."

# shellcheck disable=SC2153
if [[ ! -f "$BFT_PATH" ]]; then
echo "ERROR: BFT is absent at: $BFT_PATH"
echo ">>> Aborting..."
exit 1
fi

echo ">>> Using BFT at: $BFT_PATH"
args+=("--secret" "$BFT_PATH")
fi

# Nodes will fail to start if they cannot resolve the domain names of
# their respective peers. If domains are used for peers, it's necessary
# to wait for them to resolve first before starting the node.
if [[ -n "${DNS_PEERS:=}" ]]; then
for PEER in $DNS_PEERS; do
while ! nslookup "$PEER"; do
echo ">>> Waiting for $PEER to be resolvable..."
sleep 1
done
echo "Successfully resolved $PEER"
done
fi

# Allows resetting our footprint in persistent storage
if [[ -f "$STORAGE_PATH/reset" ]]; then
echo ">>> Reset file detected at $STORAGE_PATH/reset"
rm -rf "$STORAGE_PATH/reset"

if [[ -d "$STORAGE_PATH/fragments" ]]; then
echo ">>> Deleting $STORAGE_PATH/fragments"
rm -rf "$STORAGE_PATH/fragments"
fi

if [[ -d "$STORAGE_PATH/permanent" ]]; then
echo ">>> Deleting $STORAGE_PATH/permanent"
rm -rf "$STORAGE_PATH/permanent"
fi

if [[ -d "$STORAGE_PATH/volatile" ]]; then
echo ">>> Deleting $STORAGE_PATH/volatile"
rm -rf "$STORAGE_PATH/volatile"
fi

echo ">>> Reset complete"
fi

echo "Starting node..."
exec "$BIN_PATH" "${args[@]}"

0 comments on commit 5784b68

Please sign in to comment.