
This should get us most of the way there to support using monitor during a spack container build, for both Singularity and Docker. Some quick notes: ### Docker Docker works by way of BUILDKIT and being able to specify --secret. What this means is that you can prefix a line with a mount of type secret as follows: ```bash # Install the software, remove unnecessary deps RUN --mount=type=secret,id=su --mount=type=secret,id=st cd /opt/spack-environment && spack env activate . && export SPACKMON_USER=$(cat /run/secrets/su) && export SPACKMON_TOKEN=$(cat /run/secrets/st) && spack install --monitor --fail-fast && spack gc -y ``` Where the id for one or more secrets corresponds to the file mounted at `/run/secrets/<name>`. So, for example, to build this container with su (spackmon user) and sv (spackmon token) defined I would export them on my host and do: ```bash $ DOCKER_BUILDKIT=1 docker build --network="host" --secret id=st,env=SPACKMON_TOKEN --secret id=su,env=SPACKMON_USER -t spack/container . ``` And when we add `env` to the secret definition that tells the build to look for the secret with id "st" in the environment variable `SPACKMON_TOKEN` for example. If the user is building locally with a local spack monitor, we also need to set the `--network` to be the host, otherwise you can't connect to it (a la isolation of course.) ## Singularity Singularity doesn't have as nice an ability to clearly specify secrets, so (hoping this eventually gets implemented) what I'm doing now is providing the user instructions to write the credentials to a file, add it to the container to source, and remove when done. ## Tags Note that the tags PR https://github.com/spack/spack/pull/23712 will need to be merged before `--monitor-tags` will actually work because I'm checking for the attribute (that doesn't exist yet): ```bash "tags": getattr(args, "monitor_tags", None) ``` So when that PR is merged to update the argument group, it will work here, and I can either update the PR here to not check if the attribute is there (it will be) or open another one in the case this PR is already merged. Finally, I added a bunch of documetation for how to use monitor with containerize. I say "mostly working" because I can't do a full test run with this new version until the container base is built with the updated spack (the request to the monitor server for an env install was missing so I had to add it here). Signed-off-by: vsoch <vsoch@users.noreply.github.com> Co-authored-by: vsoch <vsoch@users.noreply.github.com>
103 lines
2.9 KiB
Modula-2
103 lines
2.9 KiB
Modula-2
Bootstrap: docker
|
|
From: {{ build.image }}
|
|
Stage: build
|
|
|
|
%post
|
|
{% if os_packages_build.list %}
|
|
# Update, install and cleanup of system packages needed at build-time
|
|
{% 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 %}
|
|
# Create the manifest file for the installation in /opt/spack-environment
|
|
mkdir {{ paths.environment }} && cd {{ paths.environment }}
|
|
cat << EOF > spack.yaml
|
|
{{ manifest }}
|
|
EOF
|
|
|
|
# Install all the required software
|
|
. /opt/spack/share/spack/setup-env.sh
|
|
spack env activate .
|
|
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
|
|
spack env deactivate
|
|
spack env activate --sh -d . >> {{ paths.environment }}/environment_modifications.sh
|
|
{% if strip %}
|
|
|
|
# Strip the binaries to reduce the size of the image
|
|
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 %}
|
|
{% if extra_instructions.build %}
|
|
{{ extra_instructions.build }}
|
|
{% endif %}
|
|
|
|
{% if apps %}
|
|
{% for application, help_text in apps.items() %}
|
|
|
|
%apprun {{ application }}
|
|
exec /opt/view/bin/{{ application }} "$@"
|
|
|
|
%apphelp {{ application }}
|
|
{{help_text }}
|
|
{% endfor %}
|
|
{% endif %}
|
|
|
|
Bootstrap: docker
|
|
From: {{ run.image }}
|
|
Stage: final
|
|
|
|
%files from build
|
|
{{ paths.environment }} /opt
|
|
{{ paths.store }} /opt
|
|
{{ paths.view }} /opt
|
|
{{ paths.environment }}/environment_modifications.sh {{ paths.environment }}/environment_modifications.sh
|
|
|
|
%post
|
|
{% if os_packages_final.list %}
|
|
# Update, install and cleanup of system packages needed at run-time
|
|
{% 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 %}
|
|
# Modify the environment without relying on sourcing shell specific files at startup
|
|
cat {{ paths.environment }}/environment_modifications.sh >> $SINGULARITY_ENVIRONMENT
|
|
{% if extra_instructions.final %}
|
|
{{ extra_instructions.final }}
|
|
{% endif %}
|
|
{% if runscript %}
|
|
|
|
%runscript
|
|
{{ runscript }}
|
|
{% endif %}
|
|
{% if startscript %}
|
|
|
|
%startscript
|
|
{{ startscript }}
|
|
{% endif %}
|
|
{% if test %}
|
|
|
|
%test
|
|
{{ test }}
|
|
{% endif %}
|
|
{% if help %}
|
|
|
|
%help
|
|
{{ help }}
|
|
{% endif %}
|
|
{% if labels %}
|
|
|
|
%labels
|
|
{% for label, value in labels.items() %}
|
|
{{ label }} {{ value }}
|
|
{% endfor %}
|
|
{% endif %}
|