From 26ac691a9057d4fb7a1148a68d6bd6bea2b5c0dd Mon Sep 17 00:00:00 2001 From: Arseni Kalma Date: Mon, 29 Jul 2024 08:54:29 +0200 Subject: [PATCH] Add dockerfile for the demo client (#3) * Arseni- add * Update Dockerfile-demo * Arseni- add * Arseni- add --- Dockerfile-demo | 49 ++++++++++ README.md | 30 +++++- fetch-params.sh | 247 ++++++++++++++++++++++++++++++++++++++++++++++++ src/config.rs | 14 ++- 4 files changed, 335 insertions(+), 5 deletions(-) create mode 100644 Dockerfile-demo create mode 100755 fetch-params.sh diff --git a/Dockerfile-demo b/Dockerfile-demo new file mode 100644 index 0000000..5f67bff --- /dev/null +++ b/Dockerfile-demo @@ -0,0 +1,49 @@ +# Use a more recent Rust version +FROM rust:1.74.0 + +# Install system dependencies +RUN apt-get update && apt-get install -y \ + sqlite3 \ + libsqlite3-dev \ + wget \ + && rm -rf /var/lib/apt/lists/* + +# Set the working directory +WORKDIR /app + +# Copy the entire repository +COPY . . + +# Install diesel_cli with specific version +RUN cargo install diesel_cli@2.1.1 --no-default-features --features sqlite --locked + +# Run migrations +RUN diesel migration run + +# Build the application in release mode +RUN cargo build --release + +# Install ipfs (for fetch-params.sh) +RUN wget https://dist.ipfs.io/go-ipfs/v0.9.1/go-ipfs_v0.9.1_linux-amd64.tar.gz && \ + tar -xvzf go-ipfs_v0.9.1_linux-amd64.tar.gz && \ + cd go-ipfs && \ + bash install.sh && \ + cd .. && \ + rm -rf go-ipfs go-ipfs_v0.9.1_linux-amd64.tar.gz + +# Make fetch-params.sh executable +RUN chmod +x fetch-params.sh + +# Run fetch-params.sh +RUN ./fetch-params.sh + +# Create necessary directories +RUN mkdir -p /root/.local/share/ZcashParams + +# Set default environment variables +ENV ZCASH_NODE_ADDRESS=127.0.0.1 +ENV ZCASH_NODE_PORT=18232 +ENV ZCASH_NODE_PROTOCOL=http + +# Set the entrypoint +ENTRYPOINT ["cargo", "run", "--release", "--package", "zcash_tx_tool", "--bin", "zcash_tx_tool", "test"] diff --git a/README.md b/README.md index 6a88cc9..48136c0 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ To build and run the docker image: ```bash docker build -t qedit/zebra-singlenode-txv5 . -docker run -p 18232:18232 qedit/zebra-singlenode-txv5 +docker run --name zebra-node -p 18232:18232 qedit/zebra-singlenode-txv5 ``` More details on how the docker file is created and synced: [Link](https://github.com/QED-it/zcash_tx_tool/blob/main/Dockerfile) @@ -85,3 +85,31 @@ With optional, but recommended `--release` flag, or simply ```bash zcash_tx_tool test ``` + +You can also run the tests using docker. To do that you'll need first to build the docker image + +```bash +docker build -t zcash_tx_tool -f Dockerfile-demo . +``` + +And after that run the image itself. +The default connection parameters are set to connect to the zebra-node running on the machine itself (127.0.0.1) +If you ran the node in a docker container with the command above, you named that container "zebra-node", so you should use that as the ZCASH_NODE_ADDRESS. +If the node is running on the ECS server, you can connect to it by setting the ZCASH_NODE_ADDRESS=. + +First, make sure you created the network: +```bash +docker network create zcash-network +``` +And started the node with the network argument, like this +```bash +docker run --name zebra-node --network zcash-network -p 18232:18232 qedit/zebra-singlenode-txv5 +``` + +Here are the 3 options (No parameters will default to the first configuration) + +```bash +docker run --network zcash-network -e ZCASH_NODE_ADDRESS=127.0.0.1 -e ZCASH_NODE_PORT=18232 -e ZCASH_NODE_PROTOCOL=http zcash_tx_tool +docker run --network zcash-network -e ZCASH_NODE_ADDRESS=zebra-node -e ZCASH_NODE_PORT=18232 -e ZCASH_NODE_PROTOCOL=http zcash_tx_tool +docker run --network zcash-network -e ZCASH_NODE_ADDRESS= -e ZCASH_NODE_PORT=18232 -e ZCASH_NODE_PROTOCOL=http zcash_tx_tool +``` diff --git a/fetch-params.sh b/fetch-params.sh new file mode 100755 index 0000000..f5d6fa3 --- /dev/null +++ b/fetch-params.sh @@ -0,0 +1,247 @@ +#!/usr/bin/env bash + +export LC_ALL=C +set -eu + +SCRIPT_NAME=$(basename $0) + +[[ -v XDG_CACHE_HOME ]] || XDG_CACHE_HOME="${HOME}/.cache" +# We don’t care too much about most of the properties of `XDG_RUNTIME_DIR` in +# this script, so we just fall back to `XDG_CACHE_HOME`. +[[ -v XDG_RUNTIME_DIR ]] || XDG_RUNTIME_DIR="${XDG_CACHE_HOME}" + +uname_S=$(uname -s 2>/dev/null || echo not) + +if [ "$uname_S" = "Darwin" ]; then + PARAMS_DIR="$HOME/Library/Application Support/ZcashParams" +else + PARAMS_DIR="$HOME/.zcash-params" +fi + +# Commented out because these are unused; see below. +#SPROUT_PKEY_NAME='sprout-proving.key' +#SPROUT_VKEY_NAME='sprout-verifying.key' +SAPLING_SPEND_NAME='sapling-spend.params' +SAPLING_OUTPUT_NAME='sapling-output.params' +SAPLING_SPROUT_GROTH16_NAME='sprout-groth16.params' +DOWNLOAD_URL="https://download.z.cash/downloads" +IPFS_HASH="/ipfs/QmXRHVGLQBiKwvNq7c2vPxAKz1zRVmMYbmt7G5TQss7tY7" + +SHA256CMD="$(command -v sha256sum || echo shasum)" +SHA256ARGS="$(command -v sha256sum >/dev/null || echo '-a 256')" + +WGETCMD="$(command -v wget || echo '')" +IPFSCMD="$(command -v ipfs || echo '')" +CURLCMD="$(command -v curl || echo '')" + +# fetch methods can be disabled with ZC_DISABLE_SOMETHING=1 +ZC_DISABLE_WGET="${ZC_DISABLE_WGET:-}" +ZC_DISABLE_IPFS="${ZC_DISABLE_IPFS:-}" +ZC_DISABLE_CURL="${ZC_DISABLE_CURL:-}" + +LOCK_DIR="${XDG_RUNTIME_DIR}/zcash" +mkdir -p "${LOCK_DIR}" +LOCKFILE="${LOCK_DIR}/fetch-params.lock" + +fetch_wget() { + if [ -z "$WGETCMD" ] || [ -n "$ZC_DISABLE_WGET" ]; then + return 1 + fi + + cat <&2 < "${dlname}" + rm "${dlname}.part.1" "${dlname}.part.2" + + "$SHA256CMD" $SHA256ARGS -c <&2 + exit 1 + fi + fi + + unset -v filename + unset -v output + unset -v dlname + unset -v expectedhash +} + +# Use flock to prevent parallel execution. +lock() { + if [ "$uname_S" = "Darwin" ]; then + if shlock -f ${LOCKFILE} -p $$; then + return 0 + else + return 1 + fi + else + # create lock file + eval "exec 9>$LOCKFILE" + # acquire the lock + flock -n 9 \ + && return 0 \ + || return 1 + fi +} + +exit_locked_error() { + echo "Only one instance of ${SCRIPT_NAME} can be run at a time." >&2 + echo "If you are certain no other instance is running, you can try removing" >&2 + echo "${LOCKFILE}" >&2 + exit 1 +} + +main() { + + lock \ + || exit_locked_error + + cat <> "$README_PATH" < Self { Self { - node_address: "127.0.0.1".to_string(), - node_port: 18232, - protocol: "http".to_string(), + node_address: env::var("ZCASH_NODE_ADDRESS") + .unwrap_or_else(|_| "127.0.0.1".to_string()), + node_port: env::var("ZCASH_NODE_PORT") + .ok() + .and_then(|s| s.parse().ok()) + .unwrap_or(18232), + protocol: env::var("ZCASH_NODE_PROTOCOL") + .unwrap_or_else(|_| "http".to_string()), } } } @@ -80,4 +86,4 @@ impl Default for ChainConfig { nu5_activation_height: 1_060_755, // NU5 activation height for shorter chain, should be in sync with node's chain params } } -} \ No newline at end of file +}