Skip to content

Commit

Permalink
deploy: add earthfile to build docker container
Browse files Browse the repository at this point in the history
fix: remove warnings and unused imports
  • Loading branch information
saibatizoku committed Sep 12, 2023
1 parent 31afbd3 commit f657fe9
Show file tree
Hide file tree
Showing 3 changed files with 222 additions and 4 deletions.
105 changes: 105 additions & 0 deletions Earthfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Set the Earthly version to 0.7
VERSION 0.7
FROM debian:stable-slim

rust-toolchain:
FROM rust:1.70-slim-bullseye
RUN rustup component add rustfmt

# Installs Cargo chef
install-chef:
FROM +rust-toolchain
RUN cargo install --debug cargo-chef

# Prepares the local cache
prepare-cache:
FROM +install-chef
COPY --dir jormungandr jormungandr-lib jcli explorer modules testing .
COPY --dir Cargo.lock Cargo.toml .
RUN cargo chef prepare
SAVE ARTIFACT recipe.json
SAVE IMAGE --cache-hint

# Builds the local cache
build-cache:
FROM +install-chef
COPY +prepare-cache/recipe.json ./

# Install build dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends \
build-essential \
libssl-dev \
libpq-dev \
libsqlite3-dev \
pkg-config \
protobuf-compiler

RUN cargo chef cook --release
SAVE ARTIFACT target
SAVE ARTIFACT $CARGO_HOME cargo_home
SAVE IMAGE --cache-hint

# This is the default builder that all other builders should inherit from
builder:
FROM +rust-toolchain

WORKDIR /src

# Install build dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends \
build-essential \
libssl-dev \
libpq-dev \
libsqlite3-dev \
pkg-config \
protobuf-compiler
COPY --dir jormungandr jormungandr-lib jcli explorer modules testing .
COPY --dir Cargo.lock Cargo.toml .
COPY +build-cache/cargo_home $CARGO_HOME
COPY +build-cache/target target
SAVE ARTIFACT /src

build:
FROM +builder

COPY --dir jormungandr jormungandr-lib jcli explorer modules testing .
COPY Cargo.toml Cargo.lock ./

RUN cargo build --locked --release -p jormungandr -p jcli -p explorer

SAVE ARTIFACT /src/target/release/explorer explorer
SAVE ARTIFACT /src/target/release/jcli jcli
SAVE ARTIFACT /src/target/release/jormungandr jormungandr
SAVE IMAGE --cache-hint

docker:
FROM debian:stable-slim

WORKDIR /app
ARG tag="latest"
ARG registry

# Install voting-node system dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends \
libpq5 \
openssh-client \
build-essential \
libxml2-dev \
libxslt-dev \
zlib1g-dev

## apt cleanup
RUN apt-get clean && \
rm -rf /var/lib/apt/lists/*

COPY +build/jormungandr .
COPY +build/jcli .
COPY entry.sh .
RUN chmod +x entry.sh

ENV BIN_PATH=/app/jormungandr
ENTRYPOINT ["/app/entry.sh"]
SAVE IMAGE --push ${registry}jormungandr:$tag
114 changes: 114 additions & 0 deletions entry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#!/bin/bash

# Enable strict mode
set +x
set -o errexit
set -o pipefail
set -o nounset
set -o functrace
set -o errtrace
set -o monitor
set -o posix
shopt -s dotglob

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
if [[ ! -f "$BIN_PATH" ]]; then
echo "ERROR: path to jormungandr binary is absent at: $BIN_PATH"
echo ">>> Aborting..."
exit 1
fi
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

# Define the command to be executed
ARGS="${args[*]}"
EXTRA_ARGS=$*
CMD="$BIN_PATH $ARGS $EXTRA_ARGS"
echo ">>> Executing command: $CMD"

# Wait for DEBUG_SLEEP seconds if the DEBUG_SLEEP environment variable is set
if [ -n "${DEBUG_SLEEP:-}" ]; then
echo "DEBUG_SLEEP is set to $DEBUG_SLEEP. Sleeping..."
sleep "$DEBUG_SLEEP"
fi

echo "Starting node..."
# Expand the command with arguments and capture the exit code
set +e
eval "$CMD"
EXIT_CODE=$?
set -e

# If the exit code is 0, the executable returned successfully
if [ $EXIT_CODE -ne 0 ]; then
echo "Error: jormungandr returned with exit code $EXIT_CODE"
exit 1
fi
7 changes: 3 additions & 4 deletions jormungandr/src/fragment/pool.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
blockcfg::{ApplyBlockLedger, LedgerParameters},
blockchain::{Ref, Tip},
blockchain::Tip,
fragment::{
selection::{
FragmentSelectionAlgorithm, FragmentSelectionAlgorithmParams, FragmentSelectionResult,
Expand All @@ -13,9 +13,7 @@ use crate::{
utils::async_msg::MessageBox,
};
use chain_core::{packer::Codec, property::Serialize};
use chain_impl_mockchain::{
block::BlockDate, fragment::Contents, setting::Settings, transaction::Transaction,
};
use chain_impl_mockchain::{block::BlockDate, fragment::Contents, transaction::Transaction};
use futures::channel::mpsc::SendError;
use futures::sink::SinkExt;
use jormungandr_lib::{
Expand Down Expand Up @@ -44,6 +42,7 @@ pub struct Pool {
pool: internal::Pool,
network_msg_box: MessageBox<NetworkMsg>,
persistent_log: Option<BufWriter<File>>,
#[allow(dead_code)]
tip: Tip,
metrics: Metrics,
}
Expand Down

0 comments on commit f657fe9

Please sign in to comment.