1+ # Define the build argument
2+ ARG CHINA=False
3+
14# 1. Define the base image
25FROM ubuntu:22.04 AS base
36
7+ # Define the build argument for conditional logic
8+ ARG CHINA
9+
10+ # Use shell logic to set the ENV variable based on the build argument
11+ RUN if [ "$CHINA" = "True" ]; then \
12+ echo "Setting IS_CHINA_ENV=True" ; \
13+ echo "export IS_CHINA_ENV=True" >> /tmp/bashrc; \
14+ echo "export RootUrl=https://github.com/RESTGroup" >> /tmp/bashrc; \
15+ echo "export RootUrle=https://gitee.com/RESTGroup" >> /tmp/bashrc; \
16+ else \
17+ echo "Setting IS_CHINA_ENV=False" ; \
18+ echo "export IS_CHINA_ENV=False" >> /tmp/bashrc; \
19+ echo "export RootUrl=https://gitee.com/RESTGroup" >> /tmp/bashrc; \
20+ echo "export RootUrle=https://gitee.com/RESTGroup" >> /tmp/bashrc; \
21+ fi
22+
423# Prevent interactive prompts during installation
524ENV DEBIAN_FRONTEND=noninteractive
625
7- # Define whether the environment is inside China and GitHub URL
8- ENV IS_CHINA_ENV=False
9- ENV GITHUB=github.com
10-
1126# Set compilers for C, C++, and Fortran
1227ENV CC=gcc
1328ENV CXX=g++
1429ENV FC=gfortran
1530
16- # Define repository URL for dependencies
17- ENV resturl=https://${GITHUB}/RESTGroup
18-
1931# Set the working directory for subsequent commands
2032WORKDIR /opt
2133
2234# Configure system package sources for faster access if inside China
23- RUN if [ "$IS_CHINA_ENV" = "True" ]; then \
35+ RUN . /tmp/bashrc \
36+ && if [ "$IS_CHINA_ENV" = "True" ]; then \
2437 sed -i -e 's|http://archive.ubuntu.com/ubuntu/|http://mirrors.tuna.tsinghua.edu.cn/ubuntu/|g' \
2538 -e 's|http://security.ubuntu.com/ubuntu/|http://mirrors.tuna.tsinghua.edu.cn/ubuntu/|g' /etc/apt/sources.list; \
2639 fi
@@ -64,7 +77,8 @@ RUN git config --global http.postBuffer 524288000 \
6477 && git config --global http.lowSpeedTime 999999
6578
6679# Configure pip index URL for China mirrors if applicable
67- RUN if [ "$IS_CHINA_ENV" = "True" ]; then \
80+ RUN . /tmp/bashrc \
81+ && if [ "$IS_CHINA_ENV" = "True" ]; then \
6882 export PIP_INDEX_URL=https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple; \
6983 fi
7084
@@ -74,14 +88,16 @@ ENV RUSTUP_HOME=/opt/.rustup
7488ENV PATH="/opt/.cargo/bin:$PATH"
7589
7690# Install Rust programming language
77- RUN if [ "$IS_CHINA_ENV" = "True" ]; then \
91+ RUN . /tmp/bashrc \
92+ && if [ "$IS_CHINA_ENV" = "True" ]; then \
7893 export RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static; \
7994 export RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup; \
8095 fi && \
8196 curl https://sh.rustup.rs -sSf | sh -s -- -y
8297
8398# Configure Cargo to use China mirrors
84- RUN if [ "$IS_CHINA_ENV" = "True" ]; then \
99+ RUN . /tmp/bashrc \
100+ && if [ "$IS_CHINA_ENV" = "True" ]; then \
85101 mkdir -p /opt/.cargo && \
86102 echo "\
87103[source.crates-io] \n \
@@ -97,7 +113,8 @@ registry = 'https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git' \n\
97113RUN rustc --version && cargo --version
98114
99115# Clone the workspace repository and configure environment paths
100- RUN git clone --depth=1 ${resturl}/rest_workspace.git \
116+ RUN . /tmp/bashrc \
117+ && git clone --depth=1 ${RootUrl}/rest_workspace.git \
101118 && cd rest_workspace \
102119 && git fetch --depth=1 origin 633e4151499fdfa6b301fe8741204d5dc2892494 \
103120 && git checkout 633e4151499fdfa6b301fe8741204d5dc2892494 \
@@ -114,37 +131,36 @@ FROM base AS dependencies
114131ENV OMP_NUM_THREADS=4
115132
116133# Build and install OpenBLAS library
117- # RUN git clone https://${GITHUB}/OpenMathLib/OpenBLAS.git -b v0.3.28 OpenBLAS \
118- RUN wget https://${GITHUB}/OpenMathLib/OpenBLAS/archive/refs/tags/v0.3.28.tar.gz \
119- && tar xf v0.3.28.tar.gz && rm v0.3.28.tar.gz && mv OpenBLAS-0.3.28 OpenBLAS \
134+ RUN . /tmp/bashrc \
135+ && git clone --depth=1 ${RootUrl}/OpenBLAS.git -b v0.3.28 OpenBLAS \
120136 && cd OpenBLAS \
121137 && make DYNAMIC_ARCH=1 TARGET=HASWELL USE_OPENMP=1 \
122138 && cp libopenblas.so* $REST_EXT_DIR/
123139
124140# Build and install libcint library
125- # RUN git clone https://${GITHUB}/sunqm/libcint.git -b v6.1.2 libcint \
126- RUN wget https://${GITHUB}/sunqm/libcint/archive/refs/tags/v6.1.2.tar.gz \
127- && tar xf v6.1.2.tar.gz && rm v6.1.2.tar.gz && mv libcint-6.1.2 libcint \
141+ RUN . /tmp/bashrc \
142+ && git clone --depth=1 ${RootUrl}/libcint.git -b v6.1.2 libcint \
128143 && cd libcint \
129144 && mkdir build && cd build \
130145 && cmake -DWITH_RANGE_COULOMB=1 .. \
131146 && make -j32 \
132147 && cp libcint.so* $REST_EXT_DIR/
133148
134149# Build and install libxc library
135- RUN wget https://gitlab.com/libxc/libxc/-/archive/7.0.0/libxc-7.0.0.tar.gz \
136- && tar xf libxc-* && rm libxc-*.tar.gz \
137- && cd libxc-* \
150+ RUN . /tmp/bashrc \
151+ && git clone --depth=1 ${RootUrle}/ libxc.git -b 7.0.0 libxc \
152+ && cd libxc \
138153 && autoreconf -i \
139154 && ./configure --prefix=$(pwd) --enable-shared \
140155 && make -j32 && make install \
141156 && cp lib/libxc.so* $REST_EXT_DIR/ \
142157 && cp lib/libxc.a $REST_EXT_DIR/
143158
159+
144160# Build and install HDF5 library
145- RUN wget https://${GITHUB}/HDFGroup/hdf5/releases/download/hdf5_1.14.5/hdf5-1.14.5.tar.gz \
146- && tar xf hdf5-*.tar.gz && rm hdf5-*.tar.gz \
147- && cd hdf5-* \
161+ RUN . /tmp/bashrc \
162+ && git clone --depth=1 ${RootUrl}/ hdf5.git -b hdf5_1.14.5 hdf5_src \
163+ && cd hdf5_src \
148164 && ./configure --prefix=/opt/hdf5 \
149165 && make -j32 && make -j32 install \
150166 && cd /opt/hdf5 \
@@ -153,21 +169,25 @@ RUN wget https://${GITHUB}/HDFGroup/hdf5/releases/download/hdf5_1.14.5/hdf5-1.14
153169
154170# Build REST-specific dependencies like librest2fch and DFT libraries
155171# Install librest2fch for converting quantum chemistry formats
156- RUN git clone --depth=1 https://gitlab.com/jeanwsr/MOKIT -b for-rest \
172+ RUN . /tmp/bashrc \
173+ && git clone --depth=1 ${RootUrle}/MOKIT.git -b for-rest MOKIT \
157174 && cd MOKIT/src \
158175 && git fetch --depth=1 origin 225f55756784a0539f7ef34f97221927df84136d \
159176 && git checkout 225f55756784a0539f7ef34f97221927df84136d \
160177 && make rest2fch -f Makefile.gnu_openblas \
161178 && cp ../mokit/lib/librest2fch.so $REST_EXT_DIR/
162179
163180# Install ninja
164- RUN wget https://${GITHUB}/ninja-build/ninja/releases/download/v1.12.1/ninja-linux.zip \
165- && unzip ninja-linux.zip \
166- && mv ninja /usr/local/bin/ \
167- && rm ninja-linux.zip
181+ RUN . /tmp/bashrc \
182+ && git clone --depth=1 ${RootUrl}/ninja.git -b v1.12.1 ninja \
183+ && cd ninja \
184+ && cmake -Bbuild-cmake \
185+ && cmake --build build-cmake \
186+ && mv build-cmake/ninja /usr/local/bin/
168187
169188# Install dftd3 (Dispersion Correction)
170- RUN git clone --depth=1 https://${GITHUB}/dftd3/simple-dftd3.git -b v1.2.1 \
189+ RUN . /tmp/bashrc \
190+ && git clone --depth=1 ${RootUrl}/simple-dftd3.git -b v1.2.1 \
171191 && cd simple-dftd3 \
172192 && cmake -B build -G Ninja -DBUILD_SHARED_LIBS=1 \
173193 && cmake --build build \
@@ -177,7 +197,8 @@ RUN git clone --depth=1 https://${GITHUB}/dftd3/simple-dftd3.git -b v1.2.1 \
177197 && cd $REST_EXT_DIR && ln -s libs-dftd3.so.1 libs-dftd3.so
178198
179199# Build dftd4 for advanced dispersion correction
180- RUN git clone --depth=1 https://${GITHUB}/dftd4/dftd4.git -b v3.7.0 \
200+ RUN . /tmp/bashrc \
201+ && git clone --depth=1 ${RootUrl}/dftd4.git -b v3.7.0 \
181202 && cd dftd4 \
182203 && cmake -B build -G Ninja -DBUILD_SHARED_LIBS=1 \
183204 && cmake --build build \
@@ -195,29 +216,33 @@ COPY --from=dependencies $REST_EXT_DIR/ $REST_EXT_DIR/
195216COPY --from=dependencies $REST_EXT_INC/ $REST_EXT_INC/
196217
197218# Clone and build REST software components
198- RUN cd rest_workspace\
199- && git clone --depth=1 ${resturl}/rest.git rest \
219+ RUN . /tmp/bashrc \
220+ && cd rest_workspace\
221+ && git clone --depth=1 ${RootUrl}/rest.git rest \
200222 && cd rest \
201223 && git fetch --depth=1 origin 783158e5d6dc24edb0d7b6cbf7a4a8816c568403 \
202224 && git checkout 783158e5d6dc24edb0d7b6cbf7a4a8816c568403
203225
204- RUN cd rest_workspace\
205- && git clone --depth=1 ${resturl}/rest_tensors.git rest_tensors \
226+ RUN . /tmp/bashrc \
227+ && cd rest_workspace\
228+ && git clone --depth=1 ${RootUrl}/rest_tensors.git rest_tensors \
206229 && cd rest_tensors \
207230 && git fetch --depth=1 origin 69862164277843a3c3faccb596f62840e60ad6ae \
208231 && git checkout 69862164277843a3c3faccb596f62840e60ad6ae
209- RUN cd rest_workspace\
210- && git clone --depth=1 ${resturl}/rest_libcint.git rest_libcint \
232+ RUN . /tmp/bashrc \
233+ && cd rest_workspace\
234+ && git clone --depth=1 ${RootUrl}/rest_libcint.git rest_libcint \
211235 && cd rest_libcint \
212236 && git fetch --depth=1 origin 017c38b248077eb6d24413166a126e0fcfdbec9d \
213237 && git checkout 017c38b248077eb6d24413166a126e0fcfdbec9d
214- RUN cd rest_workspace\
215- && git clone --depth=1 ${resturl}/rest_regression.git rest_regression \
238+ RUN . /tmp/bashrc \
239+ && cd rest_workspace\
240+ && git clone --depth=1 ${RootUrl}/rest_regression.git rest_regression \
216241 && cd rest_regression \
217242 && git fetch --depth=1 origin c45e5d8c3d2d8ff6c76977e45425aaf5c07012bd \
218243 && git checkout c45e5d8c3d2d8ff6c76977e45425aaf5c07012bd
219244
220- # # Build and verify REST
245+ # Build and verify REST
221246RUN cd rest_workspace \
222247 && ./Config -r github -f $FC -e
223248
0 commit comments