summaryrefslogtreecommitdiff
path: root/share
diff options
context:
space:
mode:
authorMassimiliano Culpo <massimiliano.culpo@gmail.com>2021-10-25 22:09:27 +0200
committerGitHub <noreply@github.com>2021-10-25 13:09:27 -0700
commit6063600a7bff427d5ae404cd8386186026191228 (patch)
treef5b8830e38dea74546fffcc9e46d21fad7a6cbc1 /share
parentff65e6352f1a3d906514fed971f074115b97ded2 (diff)
downloadspack-6063600a7bff427d5ae404cd8386186026191228.tar.gz
spack-6063600a7bff427d5ae404cd8386186026191228.tar.bz2
spack-6063600a7bff427d5ae404cd8386186026191228.tar.xz
spack-6063600a7bff427d5ae404cd8386186026191228.zip
containerize: pin the Spack version used in a container (#21910)
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
Diffstat (limited to 'share')
-rwxr-xr-xshare/spack/spack-completion.bash2
-rw-r--r--share/spack/templates/container/Dockerfile12
-rw-r--r--share/spack/templates/container/alpine_3.dockerfile7
-rw-r--r--share/spack/templates/container/amazonlinux_2.dockerfile24
-rw-r--r--share/spack/templates/container/bootstrap-base.dockerfile45
-rw-r--r--share/spack/templates/container/centos_7.dockerfile26
-rw-r--r--share/spack/templates/container/centos_8.dockerfile29
l---------share/spack/templates/container/cuda_11_2_1.dockerfile1
-rw-r--r--share/spack/templates/container/ubuntu_1604.dockerfile32
-rw-r--r--share/spack/templates/container/ubuntu_1804.dockerfile6
l---------share/spack/templates/container/ubuntu_2004.dockerfile1
11 files changed, 181 insertions, 4 deletions
diff --git a/share/spack/spack-completion.bash b/share/spack/spack-completion.bash
index bf5300ea96..72fa08a33a 100755
--- a/share/spack/spack-completion.bash
+++ b/share/spack/spack-completion.bash
@@ -794,7 +794,7 @@ _spack_config_revert() {
}
_spack_containerize() {
- SPACK_COMPREPLY="-h --help --monitor --monitor-save-local --monitor-no-auth --monitor-tags --monitor-keep-going --monitor-host --monitor-prefix"
+ SPACK_COMPREPLY="-h --help --monitor --monitor-save-local --monitor-no-auth --monitor-tags --monitor-keep-going --monitor-host --monitor-prefix --list-os --last-stage"
}
_spack_create() {
diff --git a/share/spack/templates/container/Dockerfile b/share/spack/templates/container/Dockerfile
index c23ad64188..67b8986a00 100644
--- a/share/spack/templates/container/Dockerfile
+++ b/share/spack/templates/container/Dockerfile
@@ -1,3 +1,8 @@
+{% 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
@@ -35,7 +40,8 @@ RUN cd {{ paths.environment }} && \
{% if extra_instructions.build %}
{{ extra_instructions.build }}
{% endif %}
-
+{% endif %}
+{% if render_phase.final %}
# Bare OS image to run the installed executables
FROM {{ run.image }}
@@ -49,12 +55,12 @@ 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 %}
diff --git a/share/spack/templates/container/alpine_3.dockerfile b/share/spack/templates/container/alpine_3.dockerfile
new file mode 100644
index 0000000000..583288b7cb
--- /dev/null
+++ b/share/spack/templates/container/alpine_3.dockerfile
@@ -0,0 +1,7 @@
+{% extends "container/bootstrap-base.dockerfile" %}
+{% block install_os_packages %}
+RUN apk update \
+ && apk add --no-cache curl findutils gcc g++ gfortran git gnupg \
+ make patch python3 py3-pip tcl unzip bash \
+ && pip3 install boto3
+{% endblock %}
diff --git a/share/spack/templates/container/amazonlinux_2.dockerfile b/share/spack/templates/container/amazonlinux_2.dockerfile
new file mode 100644
index 0000000000..5ab05562c0
--- /dev/null
+++ b/share/spack/templates/container/amazonlinux_2.dockerfile
@@ -0,0 +1,24 @@
+{% extends "container/bootstrap-base.dockerfile" %}
+{% block install_os_packages %}
+RUN yum update -y \
+ && yum groupinstall -y "Development Tools" \
+ && yum install -y \
+ curl \
+ findutils \
+ gcc-c++ \
+ gcc \
+ gcc-gfortran \
+ git \
+ gnupg2 \
+ hostname \
+ iproute \
+ make \
+ patch \
+ python \
+ python-pip \
+ python-setuptools \
+ unzip \
+ && pip install boto3 \
+ && rm -rf /var/cache/yum \
+ && yum clean all
+{% endblock %}
diff --git a/share/spack/templates/container/bootstrap-base.dockerfile b/share/spack/templates/container/bootstrap-base.dockerfile
new file mode 100644
index 0000000000..0674ddd541
--- /dev/null
+++ b/share/spack/templates/container/bootstrap-base.dockerfile
@@ -0,0 +1,45 @@
+FROM {{ bootstrap.image }} as bootstrap
+
+{% block env_vars %}
+ENV SPACK_ROOT=/opt/spack \
+ CURRENTLY_BUILDING_DOCKER_IMAGE=1 \
+ container=docker
+{% endblock %}
+
+{% block install_os_packages %}
+{% endblock %}
+
+RUN mkdir $SPACK_ROOT && cd $SPACK_ROOT && \
+ {{ bootstrap.spack_checkout }} && \
+ mkdir -p $SPACK_ROOT/opt/spack
+
+RUN ln -s $SPACK_ROOT/share/spack/docker/entrypoint.bash \
+ /usr/local/bin/docker-shell \
+ && ln -s $SPACK_ROOT/share/spack/docker/entrypoint.bash \
+ /usr/local/bin/interactive-shell \
+ && ln -s $SPACK_ROOT/share/spack/docker/entrypoint.bash \
+ /usr/local/bin/spack-env
+
+RUN mkdir -p /root/.spack \
+ && cp $SPACK_ROOT/share/spack/docker/modules.yaml \
+ /root/.spack/modules.yaml \
+ && rm -rf /root/*.* /run/nologin $SPACK_ROOT/.git
+
+# [WORKAROUND]
+# https://superuser.com/questions/1241548/
+# xubuntu-16-04-ttyname-failed-inappropriate-ioctl-for-device#1253889
+RUN [ -f ~/.profile ] \
+ && sed -i 's/mesg n/( tty -s \\&\\& mesg n || true )/g' ~/.profile \
+ || true
+
+{% block post_checkout %}
+{% endblock %}
+
+WORKDIR /root
+SHELL ["docker-shell"]
+
+# Creates the package cache
+RUN spack spec hdf5+mpi
+
+ENTRYPOINT ["/bin/bash", "/opt/spack/share/spack/docker/entrypoint.bash"]
+CMD ["interactive-shell"]
diff --git a/share/spack/templates/container/centos_7.dockerfile b/share/spack/templates/container/centos_7.dockerfile
new file mode 100644
index 0000000000..6ce2181298
--- /dev/null
+++ b/share/spack/templates/container/centos_7.dockerfile
@@ -0,0 +1,26 @@
+{% extends "container/bootstrap-base.dockerfile" %}
+{% block install_os_packages %}
+RUN yum update -y \
+ && yum install -y epel-release \
+ && yum update -y \
+ && yum --enablerepo epel groupinstall -y "Development Tools" \
+ && yum --enablerepo epel install -y \
+ curl \
+ findutils \
+ gcc-c++ \
+ gcc \
+ gcc-gfortran \
+ git \
+ gnupg2 \
+ hostname \
+ iproute \
+ make \
+ patch \
+ python \
+ python-pip \
+ python-setuptools \
+ unzip \
+ && pip install boto3 \
+ && rm -rf /var/cache/yum \
+ && yum clean all
+{% endblock %}
diff --git a/share/spack/templates/container/centos_8.dockerfile b/share/spack/templates/container/centos_8.dockerfile
new file mode 100644
index 0000000000..48deb14673
--- /dev/null
+++ b/share/spack/templates/container/centos_8.dockerfile
@@ -0,0 +1,29 @@
+{% extends "container/bootstrap-base.dockerfile" %}
+{% block install_os_packages %}
+RUN yum update -y \
+ # See https://fedoraproject.org/wiki/EPEL#Quickstart for powertools
+ && yum install -y dnf-plugins-core \
+ && dnf config-manager --set-enabled powertools \
+ && yum install -y epel-release \
+ && yum update -y \
+ && yum --enablerepo epel groupinstall -y "Development Tools" \
+ && yum --enablerepo epel install -y \
+ curl \
+ findutils \
+ gcc-c++ \
+ gcc \
+ gcc-gfortran \
+ git \
+ gnupg2 \
+ hostname \
+ iproute \
+ make \
+ patch \
+ python38 \
+ python38-pip \
+ python38-setuptools \
+ unzip \
+ && pip3 install boto3 \
+ && rm -rf /var/cache/yum \
+ && yum clean all
+{% endblock %}
diff --git a/share/spack/templates/container/cuda_11_2_1.dockerfile b/share/spack/templates/container/cuda_11_2_1.dockerfile
new file mode 120000
index 0000000000..9c0cea3c2a
--- /dev/null
+++ b/share/spack/templates/container/cuda_11_2_1.dockerfile
@@ -0,0 +1 @@
+ubuntu_2004.dockerfile \ No newline at end of file
diff --git a/share/spack/templates/container/ubuntu_1604.dockerfile b/share/spack/templates/container/ubuntu_1604.dockerfile
new file mode 100644
index 0000000000..95864e6bed
--- /dev/null
+++ b/share/spack/templates/container/ubuntu_1604.dockerfile
@@ -0,0 +1,32 @@
+{% extends "container/bootstrap-base.dockerfile" %}
+{% block env_vars %}
+{{ super() }}
+ENV DEBIAN_FRONTEND=noninteractive \
+ LANGUAGE=en_US.UTF-8 \
+ LANG=en_US.UTF-8 \
+ LC_ALL=en_US.UTF-8
+{% endblock %}
+{% block install_os_packages %}
+RUN apt-get -yqq update \
+ && apt-get -yqq install --no-install-recommends \
+ build-essential \
+ ca-certificates \
+ curl \
+ file \
+ g++ \
+ gcc \
+ gfortran \
+ git \
+ gnupg2 \
+ iproute2 \
+ locales \
+ lua-posix \
+ make \
+ python3 \
+ python3-pip \
+ python3-setuptools \
+ unzip \
+ && locale-gen en_US.UTF-8 \
+ && pip3 install boto3 \
+ && rm -rf /var/lib/apt/lists/*
+{% endblock %}
diff --git a/share/spack/templates/container/ubuntu_1804.dockerfile b/share/spack/templates/container/ubuntu_1804.dockerfile
new file mode 100644
index 0000000000..47af990d6a
--- /dev/null
+++ b/share/spack/templates/container/ubuntu_1804.dockerfile
@@ -0,0 +1,6 @@
+{% extends "container/ubuntu_1604.dockerfile" %}
+{% block post_checkout %}
+# [WORKAROUND]
+# https://bugs.launchpad.net/ubuntu/+source/lua-posix/+bug/1752082
+RUN ln -s posix_c.so /usr/lib/x86_64-linux-gnu/lua/5.2/posix.so
+{% endblock %}
diff --git a/share/spack/templates/container/ubuntu_2004.dockerfile b/share/spack/templates/container/ubuntu_2004.dockerfile
new file mode 120000
index 0000000000..106119ce68
--- /dev/null
+++ b/share/spack/templates/container/ubuntu_2004.dockerfile
@@ -0,0 +1 @@
+ubuntu_1604.dockerfile \ No newline at end of file