Skip to content

Commit 71d3aa3

Browse files
authored
Merge pull request #159 from Extheoisah/fix-docker
fix: issue with docker config and volume setup
2 parents 6a056fe + bbda19f commit 71d3aa3

File tree

5 files changed

+30
-19
lines changed

5 files changed

+30
-19
lines changed

Makefile

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
LOG_LEVEL ?= info
2+
DEFAULT_DATA_DIR ?= /data_dir
3+
DEFAULT_SIMFILE_PATH ?= /data_dir/sim.json
24

35
build-docker:
46
docker build -f docker/Dockerfile -t sim-ln .
@@ -15,17 +17,18 @@ help:
1517
@echo "stop Stops the Docker container."
1618
@echo ""
1719
@echo "Variables:"
18-
@echo "SIMFILE_PATH Path to the sim.json file."
19-
@echo "LOG_LEVEL Set the logging level (default: info) e.g. <make run LOG_LEVEL=debug>"
20-
@echo "HELP Set to true to print the help message (default: false) e.g. <make run HELP=true>"
21-
@echo "PRINT_BATCH_SIZE Set the batch size for printing the results e.g. <make run PRINT_BATCH_SIZE=100>"
22-
@echo "TOTAL_TIME Set the total time for the simulation e.g. <make run TOTAL_TIME=1000>"
20+
@echo "SIMFILE_PATH Path to the sim.json file."
21+
@echo "LOG_LEVEL Set the logging level (default: info) e.g. <make run LOG_LEVEL=debug>."
22+
@echo "HELP Set to true to print the help message (default: false) e.g. <make run HELP=true>."
23+
@echo "PRINT_BATCH_SIZE Set the batch size for printing the results e.g. <make run PRINT_BATCH_SIZE=100>."
24+
@echo "TOTAL_TIME Set the total time for the simulation e.g. <make run TOTAL_TIME=1000>."
25+
@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>"."
2326

2427
run-docker:
25-
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
28+
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
2629

2730
run-interactive:
28-
docker run --rm --name sim-ln --init -v simln-data:/data -e SIMFILE_PATH=/data/sim.json -it sim-ln
31+
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
2932

3033
stop-docker:
3134
docker stop sim-ln

docker/Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ ENV TARGET_RUST_ARCH="x86_64-unknown-linux-musl"
1010

1111
FROM base as builder-arm64
1212
ENV TARGET_RUST_ARCH="aarch64-unknown-linux-musl"
13-
RUN apt-get update && apt-get install clang llvm -y --no-install-recommends
13+
RUN apt-get update \
14+
&& apt-get install clang llvm -y --no-install-recommends \
15+
&& apt-get clean \
16+
&& rm -rf /var/lib/apt/lists/*
1417
ENV CC_aarch64_unknown_linux_musl=clang
1518
ENV AR_aarch64_unknown_linux_musl=llvm-ar
1619
ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_RUSTFLAGS="-Clink-self-contained=yes -Clinker=rust-lld"

docker/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,20 @@ make run-docker
7373
You can adjust the logging level by providing the `LOG_LEVEL` variable. The default value is `info`. Example:
7474

7575
```bash
76-
make run LOG_LEVEL=debug
76+
make run-docker LOG_LEVEL=debug
7777
```
7878

7979
Other configurable variables include:
8080

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

8586
Example usage:
8687

8788
```bash
88-
make run PRINT_BATCH_SIZE=100 TOTAL_TIME=5000
89+
make run-docker PRINT_BATCH_SIZE=100 TOTAL_TIME=5000
8990
```
9091

9192
For an interactive session:

docker/entrypoint.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
#!/bin/sh
22

33
# Define the start command
4-
START_COMMAND="/usr/local/bin/sim-cli $SIMFILE_PATH"
4+
START_COMMAND="/usr/local/bin/sim-cli --sim-file $SIMFILE_PATH"
5+
6+
# Check if a custom data directory was provided
7+
if [[ ! -z ${DATA_DIR} ]]; then
8+
START_COMMAND="$START_COMMAND --data-dir $DATA_DIR"
9+
fi
510

611
# Check for version arg
712
if [[ ! -z ${VERSION} ]]; then

docker/setup-volume.sh

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,10 @@ NODE_COUNT=$(cat $SIMFILE_PATH_ON_HOST | jq '.nodes | length')
2828

2929
# Loop Over Each Node
3030
for (( i=0; i<$NODE_COUNT; i++ )); do
31-
NODE_TYPE=$(cat $SIMFILE_PATH_ON_HOST | jq -r ".nodes[$i] | keys[0]") # Determine if it's LND or CLN.
32-
NODE_ID=$(cat $SIMFILE_PATH_ON_HOST | jq -r ".nodes[$i].$NODE_TYPE.id") # Extract node ID for directory creation.
33-
NODE_TLS_PATH_ON_HOST=$(cat $SIMFILE_PATH_ON_HOST | jq -r ".nodes[$i].$NODE_TYPE.cert") # TLS path
34-
NODE_MACAROON_PATH_ON_HOST=$(cat $SIMFILE_PATH_ON_HOST | jq -r ".nodes[$i].$NODE_TYPE.macaroon") # Macaroon path
35-
31+
NODE_ID=$(cat $SIMFILE_PATH_ON_HOST | jq -r ".nodes[$i].id") # Extract node ID for directory creation.
32+
NODE_TLS_PATH_ON_HOST=$(cat $SIMFILE_PATH_ON_HOST | jq -r ".nodes[$i].cert") # TLS path
33+
NODE_MACAROON_PATH_ON_HOST=$(cat $SIMFILE_PATH_ON_HOST | jq -r ".nodes[$i].macaroon") # Macaroon path
34+
3635
# Create staging directories for each node
3736
mkdir -p $STAGING_DIR/lnd/$NODE_ID
3837

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

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

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

0 commit comments

Comments
 (0)