Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: issue with docker config and volume setup #159

Merged
merged 4 commits into from
Jan 26, 2024
Merged
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
17 changes: 10 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
LOG_LEVEL ?= info
DEFAULT_DATA_DIR ?= /data_dir
DEFAULT_SIMFILE_PATH ?= /data_dir/sim.json

build-docker:
docker build -f docker/Dockerfile -t sim-ln .
Expand All @@ -15,17 +17,18 @@ help:
@echo "stop Stops the Docker container."
@echo ""
@echo "Variables:"
@echo "SIMFILE_PATH Path to the sim.json file."
@echo "LOG_LEVEL Set the logging level (default: info) e.g. <make run LOG_LEVEL=debug>"
@echo "HELP Set to true to print the help message (default: false) e.g. <make run HELP=true>"
@echo "PRINT_BATCH_SIZE Set the batch size for printing the results e.g. <make run PRINT_BATCH_SIZE=100>"
@echo "TOTAL_TIME Set the total time for the simulation e.g. <make run TOTAL_TIME=1000>"
@echo "SIMFILE_PATH Path to the sim.json file."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this line and the one for stop three lines above end with a ., while the rest do not.

@echo "LOG_LEVEL Set the logging level (default: info) e.g. <make run LOG_LEVEL=debug>."
@echo "HELP Set to true to print the help message (default: false) e.g. <make run HELP=true>."
@echo "PRINT_BATCH_SIZE Set the batch size for printing the results e.g. <make run PRINT_BATCH_SIZE=100>."
@echo "TOTAL_TIME Set the total time for the simulation e.g. <make run TOTAL_TIME=1000>."
@echo "DATA_DIR Set the data directory for the simulation containing simulation files and results e.g. <make run-docker DATA_DIR="/Users/anon/data_dir>"."

run-docker:
docker run -d --rm --name sim-ln --init -v simln-data:/data -e SIMFILE_PATH=/data/sim.json -e LOG_LEVEL=$(LOG_LEVEL) -e HELP=${HELP} -e PRINT_BATCH_SIZE=${PRINT_BATCH_SIZE} -e TOTAL_TIME=${TOTAL_TIME} sim-ln
carlaKC marked this conversation as resolved.
Show resolved Hide resolved
docker run -d --rm --name sim-ln --init -v simln-data:${DEFAULT_DATA_DIR} -e SIMFILE_PATH=${DEFAULT_SIMFILE_PATH} -e LOG_LEVEL=$(LOG_LEVEL) -e HELP=${HELP} -e PRINT_BATCH_SIZE=${PRINT_BATCH_SIZE} -e TOTAL_TIME=${TOTAL_TIME} sim-ln

run-interactive:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't catch this when it was added, but I'm wondering now:

Don't we want to also pass the env variables when running interactively?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm... we should. I'll fix that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed here -> 85082b3

docker run --rm --name sim-ln --init -v simln-data:/data -e SIMFILE_PATH=/data/sim.json -it sim-ln
docker run -it --rm --name sim-ln --init -v simln-data:${DEFAULT_DATA_DIR} -e SIMFILE_PATH=${DEFAULT_SIMFILE_PATH} -e DATA_DIR=${DATA_DIR} -e LOG_LEVEL=$(LOG_LEVEL) -e HELP=${HELP} -e PRINT_BATCH_SIZE=${PRINT_BATCH_SIZE} -e TOTAL_TIME=${TOTAL_TIME} sim-ln

stop-docker:
docker stop sim-ln
5 changes: 4 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ ENV TARGET_RUST_ARCH="x86_64-unknown-linux-musl"

FROM base as builder-arm64
ENV TARGET_RUST_ARCH="aarch64-unknown-linux-musl"
RUN apt-get update && apt-get install clang llvm -y --no-install-recommends
RUN apt-get update \
&& apt-get install clang llvm -y --no-install-recommends \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
ENV CC_aarch64_unknown_linux_musl=clang
ENV AR_aarch64_unknown_linux_musl=llvm-ar
ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_RUSTFLAGS="-Clink-self-contained=yes -Clinker=rust-lld"
Expand Down
5 changes: 3 additions & 2 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,20 @@ make run-docker
You can adjust the logging level by providing the `LOG_LEVEL` variable. The default value is `info`. Example:

```bash
make run LOG_LEVEL=debug
make run-docker LOG_LEVEL=debug
```

Other configurable variables include:

- `HELP`: Set to `true` to print the help message.
- `PRINT_BATCH_SIZE`: determines the number of payment results that will be written to disk at a time.
- `TOTAL_TIME`: the total runtime for the simulation expressed in seconds.
- `DATA_DIR`: Path to a directory containing simulation files, and where simulation results will be stored (default is the `/data_dir` volume directory).

Example usage:

```bash
make run PRINT_BATCH_SIZE=100 TOTAL_TIME=5000
make run-docker PRINT_BATCH_SIZE=100 TOTAL_TIME=5000
```

For an interactive session:
Expand Down
7 changes: 6 additions & 1 deletion docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#!/bin/sh

# Define the start command
START_COMMAND="/usr/local/bin/sim-cli $SIMFILE_PATH"
START_COMMAND="/usr/local/bin/sim-cli --sim-file $SIMFILE_PATH"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this only be passed now if $SIMFILE_PATH is defined? If not passed, this will default to pick it from data_dir/sim.json

Copy link
Contributor Author

@Extheoisah Extheoisah Nov 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need it because the cli looks for the config JSON in the root by default. whereas in docker, we're mounting a volume that hosts the JSON. So we need to point it to the docker volume where the sim.json is hosted and use that as a default if no SIMFILE_PATH is specified


# Check if a custom data directory was provided
if [[ ! -z ${DATA_DIR} ]]; then
START_COMMAND="$START_COMMAND --data-dir $DATA_DIR"
fi

# Check for version arg
if [[ ! -z ${VERSION} ]]; then
Expand Down
15 changes: 7 additions & 8 deletions docker/setup-volume.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ NODE_COUNT=$(cat $SIMFILE_PATH_ON_HOST | jq '.nodes | length')

# Loop Over Each Node
for (( i=0; i<$NODE_COUNT; i++ )); do
NODE_TYPE=$(cat $SIMFILE_PATH_ON_HOST | jq -r ".nodes[$i] | keys[0]") # Determine if it's LND or CLN.
NODE_ID=$(cat $SIMFILE_PATH_ON_HOST | jq -r ".nodes[$i].$NODE_TYPE.id") # Extract node ID for directory creation.
NODE_TLS_PATH_ON_HOST=$(cat $SIMFILE_PATH_ON_HOST | jq -r ".nodes[$i].$NODE_TYPE.cert") # TLS path
NODE_MACAROON_PATH_ON_HOST=$(cat $SIMFILE_PATH_ON_HOST | jq -r ".nodes[$i].$NODE_TYPE.macaroon") # Macaroon path

NODE_ID=$(cat $SIMFILE_PATH_ON_HOST | jq -r ".nodes[$i].id") # Extract node ID for directory creation.
Extheoisah marked this conversation as resolved.
Show resolved Hide resolved
NODE_TLS_PATH_ON_HOST=$(cat $SIMFILE_PATH_ON_HOST | jq -r ".nodes[$i].cert") # TLS path
NODE_MACAROON_PATH_ON_HOST=$(cat $SIMFILE_PATH_ON_HOST | jq -r ".nodes[$i].macaroon") # Macaroon path

# Create staging directories for each node
mkdir -p $STAGING_DIR/lnd/$NODE_ID

Expand All @@ -41,10 +40,10 @@ for (( i=0; i<$NODE_COUNT; i++ )); do
cp $NODE_MACAROON_PATH_ON_HOST $STAGING_DIR/lnd/$NODE_ID/admin.macaroon

# Adjust the paths in the staging sim.json so we don't use the host path
sed -i '' 's|'$(dirname $NODE_TLS_PATH_ON_HOST)'/tls.cert|/data/lnd/'$NODE_ID'/tls.cert|' $STAGING_DIR/sim.json
sed -i '' 's|'$(dirname $NODE_MACAROON_PATH_ON_HOST)'/admin.macaroon|/data/lnd/'$NODE_ID'/admin.macaroon|' $STAGING_DIR/sim.json
sed -i '' 's|'$(dirname $NODE_TLS_PATH_ON_HOST)'/tls.cert|/data_dir/lnd/'$NODE_ID'/tls.cert|' $STAGING_DIR/sim.json
sed -i '' 's|'$(dirname $NODE_MACAROON_PATH_ON_HOST)'/admin.macaroon|/data_dir/lnd/'$NODE_ID'/admin.macaroon|' $STAGING_DIR/sim.json
done

# Create Docker volume and copy the data
docker volume create $VOLUME_NAME
docker run --rm -v $VOLUME_NAME:/data -v $STAGING_DIR:/staging alpine sh -c 'cp -r /staging/* /data/'
docker run --rm -v $VOLUME_NAME:/data_dir -v $STAGING_DIR:/staging alpine sh -c 'cp -r /staging/* /data_dir/'
Loading