From f91968cf6fac592787f004420cf6c12164c3e66e Mon Sep 17 00:00:00 2001 From: Massimiliano Culpo Date: Mon, 3 Apr 2023 21:05:19 +0200 Subject: Improve Dockerfile recipe generation (#35187) - Update default image to Ubuntu 22.04 (previously was still Ubuntu 18.04) - Optionally use depfiles to install the environment within the container - Allow extending Dockerfile Jinja2 template - Allow extending Singularity definition file Jinja2 template - Deprecate previous options to add extra instructions --- share/spack/templates/container/Dockerfile | 10 ++++++++++ share/spack/templates/container/singularity.def | 15 +++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) (limited to 'share') diff --git a/share/spack/templates/container/Dockerfile b/share/spack/templates/container/Dockerfile index b10dcf084a..9116590480 100644 --- a/share/spack/templates/container/Dockerfile +++ b/share/spack/templates/container/Dockerfile @@ -6,6 +6,7 @@ # Build stage with Spack pre-installed and ready to be used FROM {{ build.image }} as builder +{% block build_stage %} {% if os_packages_build %} # Install OS packages needed to build the software RUN {% if os_package_update %}{{ os_packages_build.update }} \ @@ -19,7 +20,11 @@ RUN mkdir {{ paths.environment }} \ {{ manifest }} > {{ paths.environment }}/spack.yaml # Install the software, remove unnecessary deps +{% if depfile %} +RUN cd {{ paths.environment }} && spack env activate . && spack concretize && spack env depfile -o Makefile && make -j $(nproc) && spack gc -y +{% else %} RUN cd {{ paths.environment }} && spack env activate . && spack install --fail-fast && spack gc -y +{% endif %} {% if strip %} # Strip all the binaries @@ -37,7 +42,9 @@ RUN cd {{ paths.environment }} && \ {% if extra_instructions.build %} {{ extra_instructions.build }} {% endif %} +{% endblock build_stage %} {% endif %} + {% if render_phase.final %} # Bare OS image to run the installed executables FROM {{ run.image }} @@ -48,6 +55,8 @@ COPY --from=builder {{ paths.hidden_view }} {{ paths.hidden_view }} COPY --from=builder {{ paths.view }} {{ paths.view }} COPY --from=builder /etc/profile.d/z10_spack_environment.sh /etc/profile.d/z10_spack_environment.sh +{% block final_stage %} + {% if os_packages_final %} RUN {% if os_package_update %}{{ os_packages_final.update }} \ && {% endif %}{{ os_packages_final.install }} {{ os_packages_final.list | join | replace('\n', ' ') }} \ @@ -57,6 +66,7 @@ RUN {% if os_package_update %}{{ os_packages_final.update }} \ {{ extra_instructions.final }} {% endif %} +{% endblock final_stage %} {% for label, value in labels.items() %} LABEL "{{ label }}"="{{ value }}" {% endfor %} diff --git a/share/spack/templates/container/singularity.def b/share/spack/templates/container/singularity.def index 684fe9f988..d5778f0d41 100644 --- a/share/spack/templates/container/singularity.def +++ b/share/spack/templates/container/singularity.def @@ -3,6 +3,7 @@ From: {{ build.image }} Stage: build %post +{% block build_stage %} {% if os_packages_build.list %} # Update, install and cleanup of system packages needed at build-time {% if os_package_update %} @@ -20,10 +21,14 @@ EOF # Install all the required software . /opt/spack/share/spack/setup-env.sh - spack env activate . - spack install --fail-fast + spack -e . concretize +{% if depfile %} + spack -e . env depfile -o Makefile + make -j $(nproc) +{% else %} + spack -e . install +{% endif %} spack gc -y - spack env deactivate spack env activate --sh -d . >> {{ paths.environment }}/environment_modifications.sh {% if strip %} @@ -37,7 +42,7 @@ EOF {% if extra_instructions.build %} {{ extra_instructions.build }} {% endif %} - +{% endblock build_stage %} {% if apps %} {% for application, help_text in apps.items() %} @@ -61,6 +66,7 @@ Stage: final {{ paths.environment }}/environment_modifications.sh {{ paths.environment }}/environment_modifications.sh %post +{% block final_stage %} {% if os_packages_final.list %} # Update, install and cleanup of system packages needed at run-time {% if os_package_update %} @@ -74,6 +80,7 @@ Stage: final {% if extra_instructions.final %} {{ extra_instructions.final }} {% endif %} +{% endblock final_stage %} {% if runscript %} %runscript -- cgit v1.2.3-70-g09d2