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
This commit is contained in:

committed by
GitHub

parent
3d149a7db2
commit
f91968cf6f
@@ -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 %}
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user