Skip to content

Commit 88847e3

Browse files
authored
Merge pull request #4954 from ESMCI/prebuild_cprnc
Pre-build CPRNC in the container
2 parents e143016 + ca388eb commit 88847e3

3 files changed

Lines changed: 32 additions & 20 deletions

File tree

.github/workflows/testing.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ jobs:
4040
steps:
4141
- name: Checkout code
4242
uses: actions/checkout@v4
43+
with:
44+
submodules: "true"
4345
- name: Set up QEMU
4446
uses: docker/setup-qemu-action@v3
4547
- name: Set up Docker Buildx

docker/Dockerfile

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ghcr.io/spack/ubuntu-noble:1.0.4 AS builder
1+
FROM ghcr.io/spack/ubuntu-noble:1.0.4 AS spack
22

33
RUN apt-get update \
44
&& apt-get install -y --no-install-recommends \
@@ -25,6 +25,21 @@ RUN spack compiler find \
2525
&& spack external find --not-buildable openmpi \
2626
&& spack -e /opt/spack-envs install --fail-fast
2727

28+
ENV PATH=/opt/spack-envs/view/bin:$PATH
29+
ENV PKG_CONFIG_PATH=/opt/spack-envs/view/lib/pkgconfig
30+
ENV LD_LIBRARY_PATH=/opt/spack-envs/view/lib
31+
ENV ESMFMKFILE=/opt/spack-envs/view/lib/esmf.mk
32+
33+
FROM spack AS cprnc
34+
35+
COPY CIME/non_py/cprnc /src/cprnc
36+
COPY docker/entrypoint.sh /entrypoint.sh
37+
38+
RUN SKIP_ENTRYPOINT=true source /entrypoint.sh \
39+
&& CPRNC_DIR=/src/cprnc build_cprnc
40+
41+
FROM spack AS main
42+
2843
RUN apt-get update \
2944
&& apt-get install -y --no-install-recommends \
3045
vim \
@@ -41,9 +56,12 @@ RUN curl -LsSf https://astral.sh/uv/install.sh | sh \
4156
&& uv pip install -r /requirements.txt
4257

4358
COPY docker/entrypoint.sh /entrypoint.sh
44-
COPY docker/.cime /root/.cime
4559

4660
RUN SKIP_ENTRYPOINT=true source /entrypoint.sh \
61+
&& mkdir -p /root/{tools,inputdata,cases,timings,archive,baselines} \
4762
&& download_input_data
4863

64+
COPY --from=cprnc /root/tools/cprnc /root/tools/cprnc
65+
COPY docker/.cime /root/.cime
66+
4967
ENTRYPOINT ["/entrypoint.sh"]

docker/entrypoint.sh

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ SKIP_ENTRYPOINT="${SKIP_ENTRYPOINT:-false}"
99

1010
# Build the cprnc tool from CIME sources
1111
function build_cprnc() {
12-
cprnc_dir="${PWD}/CIME/non_py/cprnc"
12+
cprnc_dir="${CPRNC_DIR:-${PWD}/CIME/non_py/cprnc}"
1313

1414
if [[ ! -e "${cprnc_dir}" ]]; then
1515
echo "CPRNC path does not exist. Change to CIME's root directory."
@@ -18,10 +18,12 @@ function build_cprnc() {
1818

1919
pushd "$(mktemp -d)" || exit 1
2020

21-
cmake "${cprnc_dir}"
21+
cmake -S "${cprnc_dir}" -B .
2222

2323
make
2424

25+
mkdir "${HOME}/tools"
26+
2527
# Needs to be copied into the machines configured tool path
2628
cp cprnc "${HOME}/tools/cprnc"
2729

@@ -32,15 +34,8 @@ function build_cprnc() {
3234
# Download input data needed for model setup
3335
# required for grid generation tests
3436
function download_input_data() {
35-
local storage="${HOME}/storage"
36-
3737
mkdir -p "${HOME}/inputdata/cpl/gridmaps/oQU240"
3838
mkdir -p "${HOME}/inputdata/share/domains"
39-
mkdir -p "${storage}/cases"
40-
mkdir -p "${storage}/timings"
41-
mkdir -p "${storage}/archive"
42-
mkdir -p "${storage}/baselines"
43-
mkdir -p "${storage}/tools"
4439

4540
wget -O "${HOME}/inputdata/cpl/gridmaps/oQU240/map_oQU240_to_ne4np4_aave.160614.nc" \
4641
https://portal.nersc.gov/project/e3sm/inputdata/cpl/gridmaps/oQU240/map_oQU240_to_ne4np4_aave.160614.nc
@@ -58,12 +53,15 @@ function link_config_machines() {
5853
if [[ "${CIME_MODEL}" == "e3sm" ]]; then
5954
ln -sf "${HOME}/.cime/config_machines.v2.xml" "${HOME}/.cime/config_machines.xml"
6055
elif [[ "${CIME_MODEL}" == "cesm" ]]; then
61-
export ESMFMKFILE=/opt/conda/envs/cesm/lib/esmf.mk
62-
6356
ln -sf "${HOME}/.cime/config_machines.v3.xml" "${HOME}/.cime/config_machines.xml"
6457
fi
6558
}
6659

60+
export PATH=/opt/spack-envs/view/bin:$PATH
61+
export PKG_CONFIG_PATH=/opt/spack-envs/view/lib/pkgconfig
62+
export LD_LIBRARY_PATH=/opt/spack-envs/view/lib
63+
export ESMFMKFILE=/opt/spack-envs/view/lib/esmf.mk
64+
6765
if [[ "${CI:-false}" == "true" ]]; then
6866
cp -rf /root/.cime "${HOME}"
6967
fi
@@ -75,17 +73,11 @@ if [[ -e "${PWD}/.git" ]]; then
7573
git config --global --add safe.directory "*"
7674
fi
7775

78-
export PATH=/opt/spack-envs/view/bin:$PATH
79-
export PKG_CONFIG_PATH=/opt/spack-envs/view/lib/pkgconfig
80-
export LD_LIBRARY_PATH=/opt/spack-envs/view/lib
81-
export ESMFMKFILE=/opt/spack-envs/view/lib/esmf.mk
82-
83-
if [[ "${CI:-false}" == "false" ]]; then
76+
if [[ "${CI:-false}" == "false" ]] && [[ "${SKIP_ENTRYPOINT}" == "false" ]]; then
8477
source ${HOME}/.local/bin/env
8578
source ${HOME}/.venv/bin/activate
8679
fi
8780

88-
# If not skipping entrypoint, set up user/group IDs and exec given command.
8981
if [[ "${SKIP_ENTRYPOINT}" == "false" ]]; then
9082
exec "${@}"
9183
fi

0 commit comments

Comments
 (0)