
This PR permits to specify the `url` and `ref` of the Spack instance used in a container recipe simply by expanding the YAML schema as outlined in #20442: ```yaml container: images: os: amazonlinux:2 spack: ref: develop resolve_sha: true ``` The `resolve_sha` option, if true, verifies the `ref` by cloning the Spack repository in a temporary directory and transforming any tag or branch name to a commit sha. When this new ability is leveraged an additional "bootstrap" stage is added, which builds an image with Spack setup and ready to install software. The Spack repository to be used can be customized with the `url` keyword under `spack`. Modifications: - [x] Permit to pin the version of Spack, either by branch or tag or sha - [x] Added a few new OSes (centos:8, amazonlinux:2, ubuntu:20.04, alpine:3, cuda:11.2.1) - [x] Permit to print the bootstrap image as a standalone - [x] Add documentation on the new part of the schema - [x] Add unit tests for different use cases
67 lines
2.8 KiB
Docker
67 lines
2.8 KiB
Docker
{% if render_phase.bootstrap %}
|
|
{{ bootstrap.recipe }}
|
|
|
|
{% endif %}
|
|
{% if render_phase.build %}
|
|
# Build stage with Spack pre-installed and ready to be used
|
|
FROM {{ build.image }} as builder
|
|
|
|
{% if os_packages_build %}
|
|
# Install OS packages needed to build the software
|
|
RUN {% if os_package_update %}{{ os_packages_build.update }} \
|
|
&& {% endif %}{{ os_packages_build.install }} {{ os_packages_build.list | join | replace('\n', ' ') }} \
|
|
&& {{ os_packages_build.clean }}
|
|
{% endif %}
|
|
|
|
# What we want to install and how we want to install it
|
|
# is specified in a manifest file (spack.yaml)
|
|
RUN mkdir {{ paths.environment }} \
|
|
{{ manifest }} > {{ paths.environment }}/spack.yaml
|
|
|
|
# Install the software, remove unnecessary deps
|
|
RUN {% if monitor.enabled %}--mount=type=secret,id=su --mount=type=secret,id=st {% endif %}cd {{ paths.environment }} && \
|
|
spack env activate . {% if monitor.enabled %}{% if not monitor.disable_auth %}&& export SPACKMON_USER=$(cat /run/secrets/su) && export SPACKMON_TOKEN=$(cat /run/secrets/st) {% endif %}{% endif %}&& \
|
|
spack install {% if monitor.enabled %}--monitor {% if monitor.prefix %}--monitor-prefix {{ monitor.prefix }} {% endif %}{% if monitor.tags %}--monitor-tags {{ monitor.tags }} {% endif %}{% if monitor.keep_going %}--monitor-keep-going {% endif %}{% if monitor.host %}--monitor-host {{ monitor.host }} {% endif %}{% if monitor.disable_auth %}--monitor-disable-auth {% endif %}{% endif %}--fail-fast && \
|
|
spack gc -y
|
|
{% if strip %}
|
|
|
|
# Strip all the binaries
|
|
RUN find -L {{ paths.view }}/* -type f -exec readlink -f '{}' \; | \
|
|
xargs file -i | \
|
|
grep 'charset=binary' | \
|
|
grep 'x-executable\|x-archive\|x-sharedlib' | \
|
|
awk -F: '{print $1}' | xargs strip -s
|
|
{% endif %}
|
|
|
|
# Modifications to the environment that are necessary to run
|
|
RUN cd {{ paths.environment }} && \
|
|
spack env activate --sh -d . >> /etc/profile.d/z10_spack_environment.sh
|
|
|
|
{% if extra_instructions.build %}
|
|
{{ extra_instructions.build }}
|
|
{% endif %}
|
|
{% endif %}
|
|
{% if render_phase.final %}
|
|
# Bare OS image to run the installed executables
|
|
FROM {{ run.image }}
|
|
|
|
COPY --from=builder {{ paths.environment }} {{ paths.environment }}
|
|
COPY --from=builder {{ paths.store }} {{ paths.store }}
|
|
COPY --from=builder {{ paths.view }} {{ paths.view }}
|
|
COPY --from=builder /etc/profile.d/z10_spack_environment.sh /etc/profile.d/z10_spack_environment.sh
|
|
|
|
{% 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', ' ') }} \
|
|
&& {{ os_packages_final.clean }}
|
|
{% endif %}
|
|
{% if extra_instructions.final %}
|
|
|
|
{{ extra_instructions.final }}
|
|
{% endif %}
|
|
{% for label, value in labels.items() %}
|
|
LABEL "{{ label }}"="{{ value }}"
|
|
{% endfor %}
|
|
ENTRYPOINT ["/bin/bash", "--rcfile", "/etc/profile", "-l"]
|
|
{% endif %}
|