summaryrefslogtreecommitdiff
path: root/lib/spack/spack/test/container/images.py
diff options
context:
space:
mode:
authorMassimiliano Culpo <massimiliano.culpo@gmail.com>2020-01-31 02:19:55 +0100
committerGitHub <noreply@github.com>2020-01-30 17:19:55 -0800
commit9635ff3d20c17a92a89cf82db8d3f877dd04e1c7 (patch)
treefb4e5d0b2319a308e24572fa06e7399cbad88bf2 /lib/spack/spack/test/container/images.py
parented501eaab275f50dc3d689ee9e8d6c7fa707fd94 (diff)
downloadspack-9635ff3d20c17a92a89cf82db8d3f877dd04e1c7.tar.gz
spack-9635ff3d20c17a92a89cf82db8d3f877dd04e1c7.tar.bz2
spack-9635ff3d20c17a92a89cf82db8d3f877dd04e1c7.tar.xz
spack-9635ff3d20c17a92a89cf82db8d3f877dd04e1c7.zip
`spack containerize` generates containers from envs (#14202)
This PR adds a new command to Spack: ```console $ spack containerize -h usage: spack containerize [-h] [--config CONFIG] creates recipes to build images for different container runtimes optional arguments: -h, --help show this help message and exit --config CONFIG configuration for the container recipe that will be generated ``` which takes an environment with an additional `container` section: ```yaml spack: specs: - gromacs build_type=Release - mpich - fftw precision=float packages: all: target: [broadwell] container: # Select the format of the recipe e.g. docker, # singularity or anything else that is currently supported format: docker # Select from a valid list of images base: image: "ubuntu:18.04" spack: prerelease # Additional system packages that are needed at runtime os_packages: - libgomp1 ``` and turns it into a `Dockerfile` or a Singularity definition file, for instance: ```Dockerfile # Build stage with Spack pre-installed and ready to be used FROM spack/ubuntu-bionic:prerelease as builder # What we want to install and how we want to install it # is specified in a manifest file (spack.yaml) RUN mkdir /opt/spack-environment \ && (echo "spack:" \ && echo " specs:" \ && echo " - gromacs build_type=Release" \ && echo " - mpich" \ && echo " - fftw precision=float" \ && echo " packages:" \ && echo " all:" \ && echo " target:" \ && echo " - broadwell" \ && echo " config:" \ && echo " install_tree: /opt/software" \ && echo " concretization: together" \ && echo " view: /opt/view") > /opt/spack-environment/spack.yaml # Install the software, remove unecessary deps and strip executables RUN cd /opt/spack-environment && spack install && spack autoremove -y RUN find -L /opt/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 # Modifications to the environment that are necessary to run RUN cd /opt/spack-environment && \ spack env activate --sh -d . >> /etc/profile.d/z10_spack_environment.sh # Bare OS image to run the installed executables FROM ubuntu:18.04 COPY --from=builder /opt/spack-environment /opt/spack-environment COPY --from=builder /opt/software /opt/software COPY --from=builder /opt/view /opt/view COPY --from=builder /etc/profile.d/z10_spack_environment.sh /etc/profile.d/z10_spack_environment.sh RUN apt-get -yqq update && apt-get -yqq upgrade \ && apt-get -yqq install libgomp1 \ && rm -rf /var/lib/apt/lists/* ENTRYPOINT ["/bin/bash", "--rcfile", "/etc/profile", "-l"] ```
Diffstat (limited to 'lib/spack/spack/test/container/images.py')
-rw-r--r--lib/spack/spack/test/container/images.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/lib/spack/spack/test/container/images.py b/lib/spack/spack/test/container/images.py
new file mode 100644
index 0000000000..808676c39a
--- /dev/null
+++ b/lib/spack/spack/test/container/images.py
@@ -0,0 +1,58 @@
+# Copyright 2013-2020 Lawrence Livermore National Security, LLC and other
+# Spack Project Developers. See the top-level COPYRIGHT file for details.
+#
+# SPDX-License-Identifier: (Apache-2.0 OR MIT)
+import os.path
+
+import pytest
+
+import spack.container
+
+
+@pytest.mark.parametrize('image,spack_version,expected', [
+ ('ubuntu:18.04', 'develop', ('spack/ubuntu-bionic', 'latest')),
+ ('ubuntu:18.04', '0.14.0', ('spack/ubuntu-bionic', '0.14.0')),
+])
+def test_build_info(image, spack_version, expected):
+ output = spack.container.images.build_info(image, spack_version)
+ assert output == expected
+
+
+@pytest.mark.parametrize('image,spack_version', [
+ ('ubuntu:18.04', 'doesnotexist')
+])
+def test_build_info_error(image, spack_version):
+ with pytest.raises(ValueError, match=r"has no tag for"):
+ spack.container.images.build_info(image, spack_version)
+
+
+@pytest.mark.parametrize('image', [
+ 'ubuntu:18.04'
+])
+def test_package_info(image):
+ update, install, clean = spack.container.images.package_info(image)
+ assert update
+ assert install
+ assert clean
+
+
+@pytest.mark.parametrize('extra_config,expected_msg', [
+ ({'modules': {'enable': ['tcl']}}, 'the subsection "modules" in'),
+ ({'concretization': 'separately'}, 'the "concretization" attribute'),
+ ({'config': {'install_tree': '/some/dir'}},
+ 'the "config:install_tree" attribute has been set'),
+ ({'view': '/some/dir'}, 'the "view" attribute has been set')
+])
+def test_validate(
+ extra_config, expected_msg, minimal_configuration, config_dumper
+):
+ minimal_configuration['spack'].update(extra_config)
+ spack_yaml_dir = config_dumper(minimal_configuration)
+ spack_yaml = os.path.join(spack_yaml_dir, 'spack.yaml')
+
+ with pytest.warns(UserWarning) as w:
+ spack.container.validate(spack_yaml)
+
+ # Tests are designed to raise only one warning
+ assert len(w) == 1
+ assert expected_msg in str(w.pop().message)