Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

containerize: pin the Spack version used in a container #21910

Merged
merged 13 commits into from
Oct 25, 2021

Conversation

alalazo
Copy link
Member

@alalazo alalazo commented Feb 24, 2021

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:

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:

  • Permit to pin the version of Spack, either by branch or tag or sha
  • Added a few new OSes (centos:8, amazonlinux:2, ubuntu:20.04, alpine:3, cuda:11.2.1)
  • Permit to print the bootstrap image as a standalone
  • Add documentation on the new part of the schema
  • Add unit tests for different use cases

@alalazo alalazo force-pushed the features/containerize_fix_spack_sha branch 6 times, most recently from 2c246d7 to 3355414 Compare March 3, 2021 15:10
@haampie
Copy link
Member

haampie commented Mar 3, 2021

Some issues I found:

spack:
  view: true
  specs:
  - sirius +cuda ^cuda@:10.2 ^mpich ^openblas@0.3.10 threads=openmp target=haswell
  container:
    images:
      os: amazonlinux:2
      spack:
        ref: develop
        enforce-sha: true
  • I'm used to clingo and I'm missing it here :p normally i wouldnt have to specify the openblas version and let the concretizer figure that one out
  • strip fails because it is applied to powerpc shared libs that apparently ship with the cuda package
    Step 16/23 : 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
     ---> Running in 257649bd6d9a
    strip: Unable to recognise the format of the input file `/opt/software/linux-amzn2-haswell/gcc-7.3.1/cuda-10.2.89-mao6gttdiesgc5ff4uvjdlk5iqodjubz/nsight-compute-2019.5.0/target/linux-desktop-glibc_2_19_0-ppc64le/libcuda-injection.so'
    strip: Unable to recognise the format of the input file `/opt/software/linux-amzn2-haswell/gcc-7.3.1/cuda-10.2.89-mao6gttdiesgc5ff4uvjdlk5iqodjubz/nsight-compute-2019.5.0/target/linux-desktop-glibc_2_19_0-ppc64le/TreeLauncherSubreaper'
    strip: Unable to recognise the format of the input file `/opt/software/linux-amzn2-haswell/gcc-7.3.1/cuda-10.2.89-mao6gttdiesgc5ff4uvjdlk5iqodjubz/nsight-compute-2019.5.0/target/linux-desktop-glibc_2_19_0-ppc64le/libInterceptorInjectionTarget.so'
    strip: Unable to recognise the format of the input file `/opt/software/linux-amzn2-haswell/gcc-7.3.1/cuda-10.2.89-mao6gttdiesgc5ff4uvjdlk5iqodjubz/nsight-compute-2019.5.0/target/linux-desktop-glibc_2_19_0-ppc64le/libTreeLauncherTargetInjection.so'
    strip: Unable to recognise the format of the input file `/opt/software/linux-amzn2-haswell/gcc-7.3.1/cuda-10.2.89-mao6gttdiesgc5ff4uvjdlk5iqodjubz/nsight-compute-2019.5.0/target/linux-desktop-glibc_2_19_0-ppc64le/libnvperf_target.so'
    strip: Unable to recognise the format of the input file `/opt/software/linux-amzn2-haswell/gcc-7.3.1/cuda-10.2.89-mao6gttdiesgc5ff4uvjdlk5iqodjubz/nsight-compute-2019.5.0/target/linux-desktop-glibc_2_19_0-ppc64le/libnvperfapi64.so'
    strip: Unable to recognise the format of the input file `/opt/software/linux-amzn2-haswell/gcc-7.3.1/cuda-10.2.89-mao6gttdiesgc5ff4uvjdlk5iqodjubz/nsight-compute-2019.5.0/target/linux-desktop-glibc_2_19_0-ppc64le/nv-nsight-cu-cli'
    strip: Unable to recognise the format of the input file `/opt/software/linux-amzn2-haswell/gcc-7.3.1/cuda-10.2.89-mao6gttdiesgc5ff4uvjdlk5iqodjubz/nsight-compute-2019.5.0/target/linux-desktop-glibc_2_19_0-ppc64le/libnvperf_host.so'
    strip: Unable to recognise the format of the input file `/opt/software/linux-amzn2-haswell/gcc-7.3.1/cuda-10.2.89-mao6gttdiesgc5ff4uvjdlk5iqodjubz/nsight-compute-2019.5.0/target/linux-desktop-glibc_2_19_0-ppc64le/libNvSwCounterApi.so'
    strip: Unable to recognise the format of the input file `/opt/software/linux-amzn2-haswell/gcc-7.3.1/cuda-10.2.89-mao6gttdiesgc5ff4uvjdlk5iqodjubz/nsight-compute-2019.5.0/target/linux-desktop-glibc_2_19_0-ppc64le/libTreeLauncherPlaceholder.so'
    strip: Unable to recognise the format of the input file `/opt/software/linux-amzn2-haswell/gcc-7.3.1/cuda-10.2.89-mao6gttdiesgc5ff4uvjdlk5iqodjubz/nsight-compute-2019.5.0/target/linux-desktop-glibc_2_19_0-ppc64le/TreeLauncherTargetLdPreloadHelper'
    strip: Unable to recognise the format of the input file `/opt/software/linux-amzn2-haswell/gcc-7.3.1/cuda-10.2.89-mao6gttdiesgc5ff4uvjdlk5iqodjubz/nsight-compute-2019.5.0/target/linux-desktop-glibc_2_19_0-ppc64le/libTreeLauncherTargetUpdatePreloadInjection.so'
    
  • setting LD_LIBRARY_PATH makes system executables fail to work:
    bash-4.2# yum install libgomp
    There was a problem importing one of the Python modules
    required to run yum. The error leading to this problem was:
       /opt/view/lib/liblzma.so.5: version `XZ_5.1.2alpha' not found (required by /lib64/librpmio.so.3)
    Please install a package which provides this module, or
    verify that the module is installed correctly.
    It's possible that the above module doesn't match the
    current version of Python, which is:
    2.7.18 (default, Feb 18 2021, 06:07:59) 
    [GCC 7.3.1 20180712 (Red Hat 7.3.1-12)]
    If you cannot solve this problem yourself, please go to 
    the yum faq at:
      http://yum.baseurl.org/wiki/Faq
    

@alalazo
Copy link
Member Author

alalazo commented Mar 3, 2021

Thanks for test-driving the PR @haampie

@alalazo alalazo force-pushed the features/containerize_fix_spack_sha branch from 3355414 to e4ad7dc Compare March 3, 2021 16:17
@alalazo alalazo marked this pull request as ready for review March 3, 2021 16:57
@alalazo alalazo added this to In progress in Spack 0.17.0 Release via automation Mar 3, 2021
@alalazo
Copy link
Member Author

alalazo commented Mar 3, 2021

@victorusu

@alalazo alalazo force-pushed the features/containerize_fix_spack_sha branch from e4ad7dc to 690e8a5 Compare March 3, 2021 18:51
Copy link
Member

@tgamblin tgamblin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor requests and some arg tweaks, and one larger question about bootstrapping images.

lib/spack/docs/containers.rst Outdated Show resolved Hide resolved
lib/spack/docs/containers.rst Outdated Show resolved Hide resolved
lib/spack/docs/containers.rst Outdated Show resolved Hide resolved
lib/spack/docs/containers.rst Outdated Show resolved Hide resolved
lib/spack/llnl/util/filesystem.py Outdated Show resolved Hide resolved
share/spack/templates/container/amazonlinux_2.dockerfile Outdated Show resolved Hide resolved
lib/spack/spack/container/images.json Show resolved Hide resolved
lib/spack/spack/schema/container.py Outdated Show resolved Hide resolved
share/spack/templates/container/Dockerfile Outdated Show resolved Hide resolved
share/spack/templates/container/centos_7.dockerfile Outdated Show resolved Hide resolved
Spack 0.17.0 Release automation moved this from In progress to Review in progress Mar 16, 2021
@alalazo alalazo force-pushed the features/containerize_fix_spack_sha branch from 690e8a5 to 313b581 Compare April 28, 2021 15:54
@alalazo
Copy link
Member Author

alalazo commented May 25, 2021

@tgamblin This is ready for another review

@alalazo
Copy link
Member Author

alalazo commented Jun 1, 2021

@tgamblin ping

@alalazo
Copy link
Member Author

alalazo commented Jun 30, 2021

@tgamblin Do you have some time for a second review?

@alalazo alalazo force-pushed the features/containerize_fix_spack_sha branch from 2517ceb to 1b0ff7a Compare July 28, 2021 07:55
@spackbot-app spackbot-app bot added commands docker documentation Improvements or additions to documentation tests General test capability(ies) labels Jul 28, 2021
@kniec
Copy link
Contributor

kniec commented Sep 9, 2021

I updated the containers-on-pcluster workshop to reflect that. Do you also are going to kick out the CUDA binary problem from above?

@alalazo
Copy link
Member Author

alalazo commented Sep 9, 2021

@kniec Maybe in a smaller, follow up PR? Would that work?

@kniec
Copy link
Contributor

kniec commented Sep 9, 2021

@alalazo sure thing - I just kick that part out with

spack containerize \
  | sed -e '/RUN find -L /,+4d' > Dockerfile

@alalazo
Copy link
Member Author

alalazo commented Sep 9, 2021

@vsoch With respect to Ubuntu 20.04 you can try:

spack:
  specs:
  - zlib

  container:
    images:
      os: ubuntu:20.04
      spack:
        ref: develop

with this PR

@vsoch
Copy link
Member

vsoch commented Sep 9, 2021

will do!

@vsoch
Copy link
Member

vsoch commented Sep 9, 2021

Okay testing for 20.04! The Dockerfile looks great, builds without issue:

FROM ubuntu:20.04 as bootstrap

ENV SPACK_ROOT=/opt/spack \
    CURRENTLY_BUILDING_DOCKER_IMAGE=1 \
    container=docker

ENV DEBIAN_FRONTEND=noninteractive   \
    LANGUAGE=en_US.UTF-8 \
    LANG=en_US.UTF-8 \
    LC_ALL=en_US.UTF-8

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/*

RUN mkdir $SPACK_ROOT && cd $SPACK_ROOT && \
    git clone https://github.com/spack/spack.git . && git checkout develop  && \
    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


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"]

# Build stage with Spack pre-installed and ready to be used
FROM bootstrap 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 "  - zlib" \
&&   echo "  concretization: together" \
&&   echo "  config:" \
&&   echo "    install_tree: /opt/software" \
&&   echo "  view: /opt/view") > /opt/spack-environment/spack.yaml

# Install the software, remove unnecessary deps
RUN cd /opt/spack-environment && \
    spack env activate . && \
    spack install --fail-fast && \
    spack gc -y

# Strip all the binaries
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:20.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

ENTRYPOINT ["/bin/bash", "--rcfile", "/etc/profile", "-l"]

Shelling in is very straight forward:

$ docker run -it test 

I think my one question is if spack should be already on the path? As a user I wouldn't know what to do after shelling in and not seeing it.

root@a6cc2bd49210:/# which spack

@alalazo
Copy link
Member Author

alalazo commented Sep 9, 2021

@vsoch The Dockerfile, by default, is a 3 stage build where Spack is in the first two. The last stage is just the software required in the environment. You can:

$ spack containerize --last-stage build

If you want to stop before the last stage.

@vsoch
Copy link
Member

vsoch commented Sep 9, 2021

ah okay, that does make sense. Sorry didn't look closely enough!

@vsoch
Copy link
Member

vsoch commented Sep 14, 2021

@davidbeckingsale see this PR here for ubuntu 20.04 support

@kniec
Copy link
Contributor

kniec commented Sep 15, 2021

@alalazo docker build defines the stage to build for with --target - I am voting to use the same option.

@alalazo
Copy link
Member Author

alalazo commented Sep 22, 2021

@kniec I think "target" would be confusing for people using Spack since in specs it's used to identify the target microarchitecture.

@kniec
Copy link
Contributor

kniec commented Sep 22, 2021

yeah, that is true.

@alalazo alalazo force-pushed the features/containerize_fix_spack_sha branch from d78d65b to 6942705 Compare October 1, 2021 13:36
@tgamblin tgamblin merged commit 6063600 into spack:develop Oct 25, 2021
Spack 0.17.0 Release automation moved this from Review in progress to Done Oct 25, 2021
@alalazo alalazo deleted the features/containerize_fix_spack_sha branch October 25, 2021 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
commands containers docker documentation Improvements or additions to documentation feature tests General test capability(ies) utilities
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

5 participants