Skip to content

Commit

Permalink
feat: update to path specification in bitcoin-dev-project#132
Browse files Browse the repository at this point in the history
  • Loading branch information
Extheoisah committed Jan 25, 2024
1 parent 4bb1f4c commit a495e9d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 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
1 change: 1 addition & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ 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:

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
6 changes: 3 additions & 3 deletions docker/setup-volume.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,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 a495e9d

Please sign in to comment.