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