Skip to content

Commit f657fe9

Browse files
committed
deploy: add earthfile to build docker container
fix: remove warnings and unused imports
1 parent 31afbd3 commit f657fe9

File tree

3 files changed

+222
-4
lines changed

3 files changed

+222
-4
lines changed

Earthfile

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Set the Earthly version to 0.7
2+
VERSION 0.7
3+
FROM debian:stable-slim
4+
5+
rust-toolchain:
6+
FROM rust:1.70-slim-bullseye
7+
RUN rustup component add rustfmt
8+
9+
# Installs Cargo chef
10+
install-chef:
11+
FROM +rust-toolchain
12+
RUN cargo install --debug cargo-chef
13+
14+
# Prepares the local cache
15+
prepare-cache:
16+
FROM +install-chef
17+
COPY --dir jormungandr jormungandr-lib jcli explorer modules testing .
18+
COPY --dir Cargo.lock Cargo.toml .
19+
RUN cargo chef prepare
20+
SAVE ARTIFACT recipe.json
21+
SAVE IMAGE --cache-hint
22+
23+
# Builds the local cache
24+
build-cache:
25+
FROM +install-chef
26+
COPY +prepare-cache/recipe.json ./
27+
28+
# Install build dependencies
29+
RUN apt-get update && \
30+
apt-get install -y --no-install-recommends \
31+
build-essential \
32+
libssl-dev \
33+
libpq-dev \
34+
libsqlite3-dev \
35+
pkg-config \
36+
protobuf-compiler
37+
38+
RUN cargo chef cook --release
39+
SAVE ARTIFACT target
40+
SAVE ARTIFACT $CARGO_HOME cargo_home
41+
SAVE IMAGE --cache-hint
42+
43+
# This is the default builder that all other builders should inherit from
44+
builder:
45+
FROM +rust-toolchain
46+
47+
WORKDIR /src
48+
49+
# Install build dependencies
50+
RUN apt-get update && \
51+
apt-get install -y --no-install-recommends \
52+
build-essential \
53+
libssl-dev \
54+
libpq-dev \
55+
libsqlite3-dev \
56+
pkg-config \
57+
protobuf-compiler
58+
COPY --dir jormungandr jormungandr-lib jcli explorer modules testing .
59+
COPY --dir Cargo.lock Cargo.toml .
60+
COPY +build-cache/cargo_home $CARGO_HOME
61+
COPY +build-cache/target target
62+
SAVE ARTIFACT /src
63+
64+
build:
65+
FROM +builder
66+
67+
COPY --dir jormungandr jormungandr-lib jcli explorer modules testing .
68+
COPY Cargo.toml Cargo.lock ./
69+
70+
RUN cargo build --locked --release -p jormungandr -p jcli -p explorer
71+
72+
SAVE ARTIFACT /src/target/release/explorer explorer
73+
SAVE ARTIFACT /src/target/release/jcli jcli
74+
SAVE ARTIFACT /src/target/release/jormungandr jormungandr
75+
SAVE IMAGE --cache-hint
76+
77+
docker:
78+
FROM debian:stable-slim
79+
80+
WORKDIR /app
81+
ARG tag="latest"
82+
ARG registry
83+
84+
# Install voting-node system dependencies
85+
RUN apt-get update && \
86+
apt-get install -y --no-install-recommends \
87+
libpq5 \
88+
openssh-client \
89+
build-essential \
90+
libxml2-dev \
91+
libxslt-dev \
92+
zlib1g-dev
93+
94+
## apt cleanup
95+
RUN apt-get clean && \
96+
rm -rf /var/lib/apt/lists/*
97+
98+
COPY +build/jormungandr .
99+
COPY +build/jcli .
100+
COPY entry.sh .
101+
RUN chmod +x entry.sh
102+
103+
ENV BIN_PATH=/app/jormungandr
104+
ENTRYPOINT ["/app/entry.sh"]
105+
SAVE IMAGE --push ${registry}jormungandr:$tag

entry.sh

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#!/bin/bash
2+
3+
# Enable strict mode
4+
set +x
5+
set -o errexit
6+
set -o pipefail
7+
set -o nounset
8+
set -o functrace
9+
set -o errtrace
10+
set -o monitor
11+
set -o posix
12+
shopt -s dotglob
13+
14+
echo ">>> Entering entrypoint script..."
15+
# Verify the storage path exists
16+
if [[ ! -d "$STORAGE_PATH" ]]; then
17+
echo "ERROR: storage path does not exist at: $STORAGE_PATH";
18+
echo ">>> Aborting..."
19+
exit 1
20+
fi
21+
# Verify config is present
22+
if [[ ! -f "$NODE_CONFIG_PATH" ]]; then
23+
echo "ERROR: node configuration is absent at: $NODE_CONFIG_PATH"
24+
echo ">>> Aborting..."
25+
exit 1
26+
fi
27+
# Verify genesis block is present
28+
if [[ ! -f "$GENESIS_PATH" ]]; then
29+
echo "ERROR: genesis block is absent at: $GENESIS_PATH"
30+
echo ">>> Aborting..."
31+
exit 1
32+
fi
33+
# Allow overriding jormungandr binary
34+
if [[ ! -f "$BIN_PATH" ]]; then
35+
echo "ERROR: path to jormungandr binary is absent at: $BIN_PATH"
36+
echo ">>> Aborting..."
37+
exit 1
38+
fi
39+
echo ">>> Using the following parameters:"
40+
echo "Storage path: $STORAGE_PATH"
41+
echo "Node config: $NODE_CONFIG_PATH"
42+
echo "Genesis block: $GENESIS_PATH"
43+
echo "Binary path: $BIN_PATH"
44+
args=()
45+
args+=("--storage" "$STORAGE_PATH")
46+
args+=("--config" "$NODE_CONFIG_PATH")
47+
args+=("--genesis-block" "$GENESIS_PATH")
48+
if [[ -n "${LEADER:-}" ]]; then
49+
echo ">>> Configuring node as leader..."
50+
# shellcheck disable=SC2153
51+
if [[ ! -f "$BFT_PATH" ]]; then
52+
echo "ERROR: BFT is absent at: $BFT_PATH"
53+
echo ">>> Aborting..."
54+
exit 1
55+
fi
56+
echo ">>> Using BFT at: $BFT_PATH"
57+
args+=("--secret" "$BFT_PATH")
58+
fi
59+
# Nodes will fail to start if they cannot resolve the domain names of
60+
# their respective peers. If domains are used for peers, it's necessary
61+
# to wait for them to resolve first before starting the node.
62+
if [[ -n "${DNS_PEERS:-}" ]]; then
63+
for PEER in $DNS_PEERS
64+
do
65+
while ! nslookup "$PEER"; do
66+
echo ">>> Waiting for $PEER to be resolvable..."
67+
sleep 1
68+
done
69+
echo "Successfully resolved $PEER"
70+
done
71+
fi
72+
# Allows resetting our footprint in persistent storage
73+
if [[ -f "$STORAGE_PATH/reset" ]]; then
74+
echo ">>> Reset file detected at $STORAGE_PATH/reset"
75+
rm -rf "$STORAGE_PATH/reset"
76+
if [[ -d "$STORAGE_PATH/fragments" ]]; then
77+
echo ">>> Deleting $STORAGE_PATH/fragments"
78+
rm -rf "$STORAGE_PATH/fragments"
79+
fi
80+
if [[ -d "$STORAGE_PATH/permanent" ]]; then
81+
echo ">>> Deleting $STORAGE_PATH/permanent"
82+
rm -rf "$STORAGE_PATH/permanent"
83+
fi
84+
if [[ -d "$STORAGE_PATH/volatile" ]]; then
85+
echo ">>> Deleting $STORAGE_PATH/volatile"
86+
rm -rf "$STORAGE_PATH/volatile"
87+
fi
88+
echo ">>> Reset complete"
89+
fi
90+
91+
# Define the command to be executed
92+
ARGS="${args[*]}"
93+
EXTRA_ARGS=$*
94+
CMD="$BIN_PATH $ARGS $EXTRA_ARGS"
95+
echo ">>> Executing command: $CMD"
96+
97+
# Wait for DEBUG_SLEEP seconds if the DEBUG_SLEEP environment variable is set
98+
if [ -n "${DEBUG_SLEEP:-}" ]; then
99+
echo "DEBUG_SLEEP is set to $DEBUG_SLEEP. Sleeping..."
100+
sleep "$DEBUG_SLEEP"
101+
fi
102+
103+
echo "Starting node..."
104+
# Expand the command with arguments and capture the exit code
105+
set +e
106+
eval "$CMD"
107+
EXIT_CODE=$?
108+
set -e
109+
110+
# If the exit code is 0, the executable returned successfully
111+
if [ $EXIT_CODE -ne 0 ]; then
112+
echo "Error: jormungandr returned with exit code $EXIT_CODE"
113+
exit 1
114+
fi

jormungandr/src/fragment/pool.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
22
blockcfg::{ApplyBlockLedger, LedgerParameters},
3-
blockchain::{Ref, Tip},
3+
blockchain::Tip,
44
fragment::{
55
selection::{
66
FragmentSelectionAlgorithm, FragmentSelectionAlgorithmParams, FragmentSelectionResult,
@@ -13,9 +13,7 @@ use crate::{
1313
utils::async_msg::MessageBox,
1414
};
1515
use chain_core::{packer::Codec, property::Serialize};
16-
use chain_impl_mockchain::{
17-
block::BlockDate, fragment::Contents, setting::Settings, transaction::Transaction,
18-
};
16+
use chain_impl_mockchain::{block::BlockDate, fragment::Contents, transaction::Transaction};
1917
use futures::channel::mpsc::SendError;
2018
use futures::sink::SinkExt;
2119
use jormungandr_lib::{
@@ -44,6 +42,7 @@ pub struct Pool {
4442
pool: internal::Pool,
4543
network_msg_box: MessageBox<NetworkMsg>,
4644
persistent_log: Option<BufWriter<File>>,
45+
#[allow(dead_code)]
4746
tip: Tip,
4847
metrics: Metrics,
4948
}

0 commit comments

Comments
 (0)