Skip to content

Commit 028cc8f

Browse files
committed
sim-rs/sim-hs: add docker (#198)
* sim-(hs/rs): add docker * feat(git-action): build docker image for new tags
1 parent 7bb2dc0 commit 028cc8f

File tree

7 files changed

+395
-8
lines changed

7 files changed

+395
-8
lines changed

.dockerignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Ignore everything
2+
*
3+
!sim-rs/
4+
!simulation/
5+
!data/simulation/*.yaml
6+
!cabal.project
7+
8+
# Ignore unnecessary files even in sim-rs
9+
sim-rs/target/
10+
sim-rs/.git/
11+
sim-rs/output/
12+
**/*.rs.bk
13+
**/.DS_Store
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Docker Build and Publish
2+
3+
on:
4+
push:
5+
tags:
6+
- "leios/[0-9][0-9][0-9][0-9]w[0-9][0-9]"
7+
- "v[0-9]+.[0-9]+.[0-9]+"
8+
- "[0-9]+.[0-9]+.[0-9]+"
9+
10+
env:
11+
REGISTRY: ghcr.io
12+
OWNER: input-output-hk
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
19+
packages: write
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
25+
- name: Log in to the Container registry
26+
uses: docker/login-action@v3
27+
with:
28+
registry: ${{ env.REGISTRY }}
29+
username: ${{ github.actor }}
30+
password: ${{ secrets.GITHUB_TOKEN }}
31+
32+
- name: Extract metadata (tags, labels)
33+
id: meta
34+
uses: docker/metadata-action@v5
35+
with:
36+
images: |
37+
${{ env.REGISTRY }}/${{ env.OWNER }}/ouroboros-leios-sim-rs
38+
${{ env.REGISTRY }}/${{ env.OWNER }}/ouroboros-leios-sim-hs
39+
tags: |
40+
type=ref,event=tag
41+
type=raw,value=latest
42+
43+
- name: Build and push Rust simulation image
44+
uses: docker/build-push-action@v5
45+
with:
46+
context: .
47+
target: rs
48+
push: true
49+
tags: |
50+
${{ env.REGISTRY }}/${{ env.OWNER }}/ouroboros-leios-sim-rs:${{ github.ref_name }}
51+
${{ env.REGISTRY }}/${{ env.OWNER }}/ouroboros-leios-sim-rs:latest
52+
labels: ${{ steps.meta.outputs.labels }}
53+
54+
- name: Build and push Haskell simulation image
55+
uses: docker/build-push-action@v5
56+
with:
57+
context: .
58+
target: hs
59+
push: true
60+
tags: |
61+
${{ env.REGISTRY }}/${{ env.OWNER }}/ouroboros-leios-sim-hs:${{ github.ref_name }}
62+
${{ env.REGISTRY }}/${{ env.OWNER }}/ouroboros-leios-sim-hs:latest
63+
labels: ${{ steps.meta.outputs.labels }}

Dockerfile

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
FROM debian:bookworm-slim AS base
2+
3+
# Create shared directories and install dependencies in one layer
4+
RUN apt-get update && apt-get install -y --no-install-recommends \
5+
ca-certificates \
6+
libgmp10 \
7+
libgtk-3-0 \
8+
libglib2.0-0 \
9+
libcairo2 \
10+
libpango-1.0-0 \
11+
libpangocairo-1.0-0 \
12+
&& rm -rf /var/lib/apt/lists/* \
13+
&& mkdir -p /usr/local/share/leios \
14+
&& mkdir -p /output
15+
16+
VOLUME /output
17+
18+
# Copy shared configuration files
19+
COPY data/simulation/config.default.yaml /usr/local/share/leios/config.default.yaml
20+
COPY data/simulation/topo-default-100.yaml /usr/local/share/leios/topology.default.yaml
21+
22+
# Build Rust simulation
23+
FROM rust:1.82-slim AS rs-builder
24+
WORKDIR /usr/src/sim-rs
25+
COPY sim-rs/ .
26+
RUN cargo build --release
27+
28+
# Build Haskell simulation
29+
FROM haskell:9.8.2-slim AS hs-builder
30+
WORKDIR /build
31+
32+
# Install git, SSL certificates, and GTK3 development dependencies
33+
RUN apt-get update && \
34+
apt-get install -y \
35+
git \
36+
ca-certificates \
37+
curl \
38+
pkg-config \
39+
libgtk-3-dev \
40+
libcairo2-dev \
41+
libpango1.0-dev \
42+
libgmp-dev \
43+
libtinfo-dev \
44+
zlib1g-dev \
45+
&& rm -rf /var/lib/apt/lists/*
46+
47+
# Copy project files
48+
COPY . .
49+
50+
# Build simulation
51+
WORKDIR /build/simulation
52+
RUN cabal update && \
53+
cabal build all
54+
55+
# Create Rust simulation image
56+
FROM base AS rs
57+
WORKDIR /output
58+
59+
# Copy the sim-cli binary
60+
COPY --from=rs-builder /usr/src/sim-rs/target/release/sim-cli /usr/local/bin/
61+
62+
# Create entrypoint script
63+
RUN echo '#!/bin/sh\n\
64+
set -e\n\
65+
\n\
66+
# Create output directory if it doesnt exist\n\
67+
mkdir -p /output\n\
68+
\n\
69+
if [ $# -eq 0 ]; then\n\
70+
exec /usr/local/bin/sim-cli\n\
71+
elif [ $# -eq 1 ] && [ "${1#-}" = "$1" ]; then\n\
72+
# If only one argument and it doesnt start with -, treat it as output file\n\
73+
output_dir=$(dirname "$1")\n\
74+
mkdir -p "$output_dir"\n\
75+
exec /usr/local/bin/sim-cli /usr/local/share/leios/topology.default.yaml "$1"\n\
76+
else\n\
77+
# Pass all arguments to sim-cli\n\
78+
exec /usr/local/bin/sim-cli "$@"\n\
79+
fi' > /usr/local/bin/entrypoint-rs.sh && chmod +x /usr/local/bin/entrypoint-rs.sh
80+
81+
ENTRYPOINT ["/usr/local/bin/entrypoint-rs.sh"]
82+
CMD []
83+
84+
# Create Haskell simulation image
85+
FROM base AS hs
86+
WORKDIR /output
87+
88+
# Copy the ols binary and necessary files
89+
COPY --from=hs-builder /build/dist-newstyle/build/aarch64-linux/ghc-9.8.2/ouroboros-leios-sim-0.1.0.0/x/ols/build/ols/ols /usr/local/bin/
90+
91+
# Create entrypoint script for Haskell simulation
92+
RUN echo '#!/bin/sh\n\
93+
set -e\n\
94+
\n\
95+
# Create output directory if it doesnt exist\n\
96+
mkdir -p /output\n\
97+
\n\
98+
# Default values\n\
99+
TOPOLOGY_FILE="/usr/local/share/leios/topology.default.yaml"\n\
100+
CONFIG_FILE="/usr/local/share/leios/config.default.yaml"\n\
101+
OUTPUT_SECONDS=40\n\
102+
SEED=0\n\
103+
\n\
104+
# Parse arguments\n\
105+
while [ $# -gt 0 ]; do\n\
106+
case "$1" in\n\
107+
--topology|-t)\n\
108+
TOPOLOGY_FILE="$2"\n\
109+
shift 2\n\
110+
;;\n\
111+
--config|-l)\n\
112+
CONFIG_FILE="$2"\n\
113+
shift 2\n\
114+
;;\n\
115+
--output-seconds)\n\
116+
OUTPUT_SECONDS="$2"\n\
117+
shift 2\n\
118+
;;\n\
119+
--seed)\n\
120+
SEED="$2"\n\
121+
shift 2\n\
122+
;;\n\
123+
--output-file)\n\
124+
OUTPUT_FILE="$2"\n\
125+
shift 2\n\
126+
;;\n\
127+
*)\n\
128+
break\n\
129+
;;\n\
130+
esac\n\
131+
done\n\
132+
\n\
133+
if [ -z "$OUTPUT_FILE" ]; then\n\
134+
TIMESTAMP=$(date +%Y%m%d_%H%M%S)\n\
135+
OUTPUT_FILE="/output/simulation_${TIMESTAMP}.log"\n\
136+
fi\n\
137+
\n\
138+
# Create a temporary file\n\
139+
TEMP_FILE="${OUTPUT_FILE}.tmp"\n\
140+
\n\
141+
# Ensure output directory exists\n\
142+
mkdir -p "$(dirname "$OUTPUT_FILE")"\n\
143+
\n\
144+
# Run simulation with arguments, writing to temp file\n\
145+
/usr/local/bin/ols sim short-leios \\\n\
146+
--seed "$SEED" \\\n\
147+
--leios-config-file "$CONFIG_FILE" \\\n\
148+
--topology-file "$TOPOLOGY_FILE" \\\n\
149+
--output-seconds "$OUTPUT_SECONDS" \\\n\
150+
--output-file "$TEMP_FILE" \\\n\
151+
"$@" && \\\n\
152+
mv "$TEMP_FILE" "$OUTPUT_FILE"' > /usr/local/bin/entrypoint-hs.sh && chmod +x /usr/local/bin/entrypoint-hs.sh
153+
154+
ENTRYPOINT ["/usr/local/bin/entrypoint-hs.sh"]
155+
CMD []

README.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,99 @@ More documentation about Leios can be found in the [web site](https://leios.card
2424
- [sim-rs](sim-rs) contains experimental Rust code to simulate the Leios protocol
2525
- [site](site) contains the sources of the aforementioned web site
2626

27+
## Docker Simulation
28+
29+
You can run both the Rust and Haskell simulations using Docker to generate simulation trace logs.
30+
31+
### Building the Docker Images
32+
33+
```bash
34+
# Build the Rust simulation image
35+
docker build --target rs -t ouroboros-leios/sim-rs:latest -f Dockerfile .
36+
37+
# Build the Haskell simulation image
38+
docker build --target hs -t ouroboros-leios/sim-hs:latest -f Dockerfile .
39+
```
40+
41+
### Running the Rust Simulation
42+
43+
The Rust simulation generates JSONL trace files that can be visualized using the web-based UI:
44+
45+
#### Basic Usage (Default Settings)
46+
```bash
47+
# Run with default settings
48+
docker run -v $(pwd)/output:/output ouroboros-leios/sim-rs:latest
49+
```
50+
51+
#### Specifying Output File
52+
```bash
53+
# Run with custom output file location
54+
docker run -v $(pwd)/output:/output ouroboros-leios/sim-rs:latest /output/simulation.jsonl
55+
```
56+
57+
#### Using Custom Topology and Config Files
58+
```bash
59+
# Mount your config directory and use custom files
60+
docker run \
61+
-v $(pwd)/output:/output \
62+
-v $(pwd)/data/simulation:/config \
63+
ouroboros-leios/sim-rs:latest /config/topology-dense-52.yaml /output/simulation.jsonl -s 20 -p /config/config.default.yaml
64+
```
65+
66+
Common arguments for Rust simulation:
67+
- `-s NUMBER`: Number of slots to simulate
68+
- `-p PATH`: Path to custom parameters file
69+
- `--trace-node NODE_ID`: Enable tracing for specific node
70+
- `--timescale SCALE`: Adjust simulation speed (e.g., 16 for 16x faster)
71+
72+
### Running the Haskell Simulation
73+
74+
The Haskell simulation generates log files with simulation data:
75+
76+
#### Basic Usage (Default Settings)
77+
```bash
78+
# Run with default settings (40 seconds)
79+
docker run -v $(pwd)/output:/output ouroboros-leios/sim-hs:latest
80+
```
81+
82+
#### Custom Duration and Output File
83+
```bash
84+
# Run for 120 seconds with specific output file
85+
docker run -v $(pwd)/output:/output ouroboros-leios/sim-hs:latest \
86+
--output-seconds 120 \
87+
--output-file /output/my-simulation.log
88+
```
89+
90+
#### Using Custom Configuration
91+
```bash
92+
# Run with custom topology and config files
93+
docker run \
94+
-v $(pwd)/output:/output \
95+
-v $(pwd)/data/simulation:/config \
96+
ouroboros-leios/sim-hs:latest \
97+
--topology /config/topology-dense-52.yaml \
98+
--config /config/config.default.yaml \
99+
--output-seconds 60 \
100+
--seed 12345
101+
```
102+
103+
Common arguments for Haskell simulation:
104+
- `--output-seconds NUMBER`: Duration of simulation in seconds (default: 40)
105+
- `--seed NUMBER`: Random seed for reproducible runs
106+
- `--topology PATH`: Custom topology file
107+
- `--config PATH`: Custom configuration file
108+
- `--output-file PATH`: Custom output file location
109+
110+
> [!NOTE]
111+
> The Rust simulation generates JSONL trace files that can be visualized using the web-based UI in the `ui` directory.
112+
> The Haskell simulation generates log files in its own format.
113+
>
114+
> To visualize Rust simulation traces:
115+
> 1. Generate a trace file using the Rust simulation
116+
> 2. Use the web UI in the `ui` directory to load and visualize the trace
117+
>
118+
> For Haskell simulation visualization, use the `viz` command option directly in the Haskell simulation binary (not available in Docker).
119+
27120
## Specification
28121

29122
Build the Agda specification for Leios using either

sim-rs/.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/target/
22
/output
33
flamegraph.svg
4-
perf.data*
4+
perf.data*
5+
.docker/
6+
*.tar

sim-rs/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ While the simulation is running, it will log what's going on to the console. You
1919

2020
The simulation runs in realtime (1 slot every second), but you can speed it up by passing e.g. `-t 16` to run 16 times faster.
2121

22-
## using traces in model comparisons
22+
> [!NOTE]
23+
> For instructions on running the simulation using Docker, please refer to the Docker Simulation section in the root README.md.
24+
25+
## Using traces in model comparisons
2326

2427
### Transaction diffusion
2528

0 commit comments

Comments
 (0)