Skip to content

Commit

Permalink
Merge pull request #159 from Extheoisah/fix-docker
Browse files Browse the repository at this point in the history
fix: issue with docker config and volume setup
  • Loading branch information
carlaKC authored Jan 26, 2024
2 parents 6a056fe + bbda19f commit 71d3aa3
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 19 deletions.
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."
@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
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:
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"

# 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.
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/'

0 comments on commit 71d3aa3

Please sign in to comment.