-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
289 lines (259 loc) · 10.2 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
ARG PYTHON_VERSION=3.10.14
ARG DEBIAN_VERSION=bookworm
# Build modelica-dependencies on bullseye (this uses an older version of GLibc which allows for making manylinux wheels)
FROM python:${PYTHON_VERSION}-slim-bullseye AS modelica-dependencies
ARG SUNDIALS_VERSION=v7.1.1
ARG ASSIMULO_VERSION=3.5.2
RUN apt-get update \
&& apt-get install -y \
cmake \
liblapack-dev \
libsuitesparse-dev \
libhypre-dev \
curl \
git \
build-essential \
dpkg-dev \
&& rm -rf /var/lib/apt/lists/*
RUN python3 -m pip install \
Cython \
numpy \
scipy \
matplotlib \
setuptools==69.1.0 \
auditwheel \
patchelf
RUN gnuArch="$(dpkg-architecture --query DEB_HOST_MULTIARCH)"; \
ln -s /usr/lib/$gnuArch/libblas.so /usr/lib/$gnuArch/libblas_OPENMP.so
WORKDIR /build
RUN curl -fSsL https://portal.nersc.gov/project/sparse/superlu/superlu_mt_3.1.tar.gz | tar xz \
&& cd SuperLU_MT_3.1 \
&& make CFLAGS="-O2 -fPIC -fopenmp" BLASLIB="-lblas" PLAT="_OPENMP" MPLIB="-fopenmp" lib -j1 \
&& cp -v ./lib/libsuperlu_mt_OPENMP.a /usr/lib \
&& cp -v ./SRC/*.h /usr/include
RUN git clone --depth 1 -b ${SUNDIALS_VERSION} https://github.com/LLNL/sundials.git \
&& cd sundials \
&& mkdir build && cd build \
&& cmake \
-LAH \
-DSUPERLUMT_BLAS_LIBRARIES=blas \
-DSUPERLUMT_LIBRARIES=blas \
-DSUPERLUMT_INCLUDE_DIR=/usr/include \
-DSUPERLUMT_LIBRARY=/usr/lib/libsuperlu_mt_OPENMP.a \
-DSUPERLUMT_THREAD_TYPE=OpenMP \
-DCMAKE_INSTALL_PREFIX=/usr \
-DSUPERLUMT_ENABLE=ON \
-DSUNDIALS_INDEX_SIZE=32 \
-DLAPACK_ENABLE=ON \
-DEXAMPLES_ENABLE=OFF \
-DEXAMPLES_ENABLE_C=OFF \
.. \
&& make -j4 \
&& make install
RUN gnuArch="$(dpkg-architecture --query DEB_HOST_MULTIARCH)" \
&& git clone --depth 1 -b Assimulo-3.5.2 https://github.com/modelon-community/Assimulo.git \
&& cd Assimulo \
&& python3 setup.py bdist_wheel --sundials-home=/usr --blas-home=/usr/lib/${gnuArch} --lapack-home=/usr/lib/${gnuArch} --superlu-home=/usr \
&& auditwheel repair --plat manylinux_2_31_$(uname -m) build/dist/*.whl \
&& pip3 install wheelhouse/*.whl
RUN git clone --depth 1 -b 2.4.1 https://github.com/modelon-community/fmi-library.git \
&& cd fmi-library \
&& sed -i "/CMAKE_INSTALL_PREFIX/d" CMakeLists.txt \
&& mkdir fmi_build && cd fmi_build \
&& mkdir fmi_library \
&& cmake -DCMAKE_INSTALL_PREFIX=/build/fmi-libary/fmi_library .. \
&& make -j4 \
&& make install
RUN git clone --depth 1 -b PyFMI-2.13.1 https://github.com/modelon-community/PyFMI.git \
&& cd PyFMI \
&& python3 setup.py bdist_wheel --fmil-home=/build/fmi-libary/fmi_library --with-openmp\
&& auditwheel repair --plat manylinux_2_31_$(uname -m) dist/*.whl
WORKDIR /artifacts
RUN cp /build/Assimulo/wheelhouse/* . \
&& cp /build/PyFMI/wheelhouse/* .
RUN gnuArch="$(dpkg-architecture --query DEB_HOST_ARCH_CPU)"\
&& curl -SfL http://ftp.us.debian.org/debian/pool/main/g/gcc-7/libgfortran4_7.4.0-6_${gnuArch}.deb -o libgfortran4.deb \
&& curl -SfL http://ftp.us.debian.org/debian/pool/main/g/gcc-7/gcc-7-base_7.4.0-6_${gnuArch}.deb -o gcc-7.deb \
&& curl -SfL https://archive.debian.org/debian/pool/main/g/gcc-6/gcc-6-base_6.3.0-18+deb9u1_${gnuArch}.deb -o gcc-6.deb \
&& curl -SfL https://archive.debian.org/debian/pool/main/g/gcc-6/libgfortran3_6.3.0-18+deb9u1_${gnuArch}.deb -o libgfortran3.deb
FROM python:${PYTHON_VERSION}-slim-${DEBIAN_VERSION} AS energyplus-dependencies
ARG OPENSTUDIO_VERSION=3.8.0
ARG OPENSTUDIO_VERSION_SHA=f953b6fcaf
ARG ENERGYPLUS_VERSION=24.1.0
ARG ENERGYPLUS_VERSION_SHA=9d7789a3ac
RUN apt-get update \
&& apt-get install -y \
curl \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /artifacts
RUN export gnuArch=x86_64; if [ "$(uname -m)" = "aarch64" ]; then gnuArch=arm64; fi; export gnuArch \
&& echo https://github.com/NREL/EnergyPlus/releases/download/v${ENERGYPLUS_VERSION}/EnergyPlus-${ENERGYPLUS_VERSION}-${ENERGYPLUS_VERSION_SHA}-Linux-Ubuntu22.04-${gnuArch}.tar.gz \
&& curl -SfL https://github.com/NREL/EnergyPlus/releases/download/v${ENERGYPLUS_VERSION}/EnergyPlus-${ENERGYPLUS_VERSION}-${ENERGYPLUS_VERSION_SHA}-Linux-Ubuntu22.04-${gnuArch}.tar.gz -o energyplus.tar.gz \
&& curl -SfL https://github.com/NREL/OpenStudio/releases/download/v${OPENSTUDIO_VERSION}/OpenStudio-${OPENSTUDIO_VERSION}+${OPENSTUDIO_VERSION_SHA}-Ubuntu-22.04-${gnuArch}.deb -o openstudio.deb \
&& curl -SfL https://openstudio-resources.s3.amazonaws.com/bcvtb-linux.tar.gz -o bcvtb.tar.gz
FROM python:${PYTHON_VERSION}-slim-${DEBIAN_VERSION} AS dual-python
ENV PYTHON_VERSION=3.8.19
ENV GPG_KEY=E3FF2839C048B25C084DEBE9B26995E310250568
RUN set -eux; \
\
savedAptMark="$(apt-mark showmanual)"; \
apt-get update; \
apt-get install -y --no-install-recommends \
dpkg-dev \
gcc \
gnupg \
libbluetooth-dev \
libbz2-dev \
libc6-dev \
libdb-dev \
libexpat1-dev \
libffi-dev \
libgdbm-dev \
liblzma-dev \
libncursesw5-dev \
libreadline-dev \
libsqlite3-dev \
libssl-dev \
make \
tk-dev \
uuid-dev \
wget \
xz-utils \
zlib1g-dev \
; \
\
wget -O python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz"; \
wget -O python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc"; \
GNUPGHOME="$(mktemp -d)"; export GNUPGHOME; \
gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys "$GPG_KEY"; \
gpg --batch --verify python.tar.xz.asc python.tar.xz; \
gpgconf --kill all; \
rm -rf "$GNUPGHOME" python.tar.xz.asc; \
mkdir -p /usr/src/python; \
tar --extract --directory /usr/src/python --strip-components=1 --file python.tar.xz; \
rm python.tar.xz; \
\
cd /usr/src/python; \
gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \
./configure \
--build="$gnuArch" \
--enable-loadable-sqlite-extensions \
--enable-optimizations \
--enable-option-checking=fatal \
--enable-shared \
--with-system-expat \
--without-ensurepip \
; \
nproc="$(nproc)"; \
EXTRA_CFLAGS="$(dpkg-buildflags --get CFLAGS)"; \
LDFLAGS="$(dpkg-buildflags --get LDFLAGS)"; \
LDFLAGS="${LDFLAGS:--Wl},--strip-all"; \
make -j "$nproc" \
"EXTRA_CFLAGS=${EXTRA_CFLAGS:-}" \
"LDFLAGS=${LDFLAGS:-}" \
"PROFILE_TASK=${PROFILE_TASK:-}" \
; \
# https://github.com/docker-library/python/issues/784
# prevent accidental usage of a system installed libpython of the same version
rm python; \
make -j "$nproc" \
"EXTRA_CFLAGS=${EXTRA_CFLAGS:-}" \
"LDFLAGS=${LDFLAGS:--Wl},-rpath='\$\$ORIGIN/../lib'" \
"PROFILE_TASK=${PROFILE_TASK:-}" \
python \
; \
make altinstall; \
\
cd /; \
rm -rf /usr/src/python; \
\
find /usr/local -depth \
\( \
\( -type d -a \( -name test -o -name tests -o -name idle_test \) \) \
-o \( -type f -a \( -name '*.pyc' -o -name '*.pyo' -o -name 'libpython*.a' \) \) \
-o \( -type f -a -name 'wininst-*.exe' \) \
\) -exec rm -rf '{}' + \
; \
\
ldconfig; \
\
apt-mark auto '.*' > /dev/null; \
apt-mark manual $savedAptMark; \
find /usr/local -type f -executable -not \( -name '*tkinter*' \) -exec ldd '{}' ';' \
| awk '/=>/ { so = $(NF-1); if (index(so, "/usr/local/") == 1) { next }; gsub("^/(usr/)?", "", so); printf "*%s\n", so }' \
| sort -u \
| xargs -r dpkg-query --search \
| cut -d: -f1 \
| sort -u \
| xargs -r apt-mark manual \
; \
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
rm -rf /var/lib/apt/lists/*; \
\
python3.8 --version
RUN python3.8 -m ensurepip --altinstall
FROM dual-python AS alfalfa-dependencies
ENV ENERGYPLUS_DIR=/usr/local/EnergyPlus
ENV HOME=/alfalfa
WORKDIR /artifacts
# Install EnergyPlus
RUN --mount=type=bind,from=energyplus-dependencies,source=/artifacts,target=/artifacts set -eux; \
mkdir ${ENERGYPLUS_DIR}; \
tar -C $ENERGYPLUS_DIR/ --strip-components=1 -xzf energyplus.tar.gz; \
cd ${ENERGYPLUS_DIR}; \
rm -rf \
ExampleFiles \
DataSets \
Documentation \
MacroDataSets \
python_standard_lib \
WeatherData \
libpython3.8.so.1.0 \
; \
ln -s $ENERGYPLUS_DIR/energyplus /usr/local/bin/; \
ln -s $ENERGYPLUS_DIR/ExpandObjects /usr/local/bin/; \
ln -s $ENERGYPLUS_DIR/runenergyplus /usr/local/bin/; \
ln -s /usr/local/lib/python3.8 ${ENERGYPLUS_DIR}/python_standard_lib; \
ln -s /usr/local/lib/libpython3.8.so.1.0 ${ENERGYPLUS_DIR}/libpython3.8.so.1.0
# Install OpenStudio
RUN --mount=type=bind,from=energyplus-dependencies,source=/artifacts,target=/artifacts set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends \
gdebi-core \
openjdk-17-jre-headless \
; \
gdebi -o "APT::Install-Recommends=0" -n openstudio.deb; \
cd /usr/local/openstudio*; \
rm -rf \
EnergyPlus \
Examples \
*Release_Notes*.pdf \
; \
ln -s ${ENERGYPLUS_DIR} EnergyPlus; \
apt-get purge -y \
gdebi-core \
; \
apt-get autoremove -y; \
rm -rf /var/lib/apt/lists/*
# Install Assimulo, PyFMI and Old Fortran Libraries
RUN --mount=type=bind,from=modelica-dependencies,source=/artifacts,target=/artifacts set -eux; \
python3.10 -m pip install 'numpy>=1.19.5' 'scipy>=1.10.1' 'matplotlib>3'; \
python3.10 -m pip install --no-deps Assimulo*.whl PyFMI*.whl; \
pip3 cache purge; \
apt-get update; \
apt-get install -y --no-install-recommends \
gdebi-core \
libgfortran5 \
; \
gdebi -n gcc-6.deb; \
gdebi -n libgfortran3.deb; \
gdebi -n gcc-7.deb; \
gdebi -n libgfortran4.deb; \
apt-get purge -y \
gdebi-core \
; \
apt-get autoremove -y; \
rm -rf /var/lib/apt/lists/*
WORKDIR $HOME
# Only the xml lib component of bcvtb is actaully required for communication, so we just extract that to save space
RUN --mount=type=bind,from=energyplus-dependencies,source=/artifacts,target=/artifacts tar -xzf /artifacts/bcvtb.tar.gz bcvtb/lib/xml