Tutorial setup

If you have not done the prior sections, you’ll need to set Spack up like this:

git clone https://github.com/spack/spack
. spack/share/spack/setup-env.sh
spack tutorial

See the Basic Installation Tutorial for full details on setup. For more help join us in the #tutorial channel on Slack – get an invitation at spackpm.herokuapp.com

Mirror Tutorial

This tutorial will guide you through the process of setting up a source mirror with a binary cache. Source mirrors and binary caches are extremely useful when using spack on a machine without internet access. Source mirrors allow you to fetch source code from a directory on your filesystem instead of accessing the outside internet, and binary caches allow you to install pre-compiled binaries to your spack installation path. Together, these two features can speed up builds when using spack within a larger development team.

We will use the filesystem for the mirrors in this tutorial, but mirrors can also be setup on web servers or s3 buckets – any URL that curl can access can be setup as a Spack mirror.

By default, Spack comes configured with a source mirror in the cloud to increase download reliability. We’ve also already set up a mirror in this tutorial for binary caches. We can see these mirrors are configured

$ spack mirror list
tutorial	file:///mirror
spack-public	https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/

Setting up a source cache mirror

When you run spack install, spack goes out to the internet to grab the source code to build your packages. This works fine on most clusters, but what do you do if the cluster in question doesn’t have access to the outside internet? This could happen for a variety of reasons. Maybe you’re building on a compute node that isn’t connected to the greater internet, or maybe even the whole cluster has been isolated from the internet.

Spack has an easy answer to this – setting up a source mirror. When you use a source mirror, spack checks the mirror for the source code before going to the outside internet.

Building a source mirror is easy. Let’s start with the same simple environment. First, let’s build our software on a computer with external internet access.

$ cd ~
$ mkdir cache-env
$ cd cache-env
$ spack env create -d .
==> Updating view at /home/spack/cache-env/.spack-env/view
==> Created environment in /home/spack/cache-env
==> You can activate this environment with:
==>   spack env activate /home/spack/cache-env
$ spacktivate .
$ # for now, disable fortran support in all packages
$ spack config add "packages:all:variants: ~fortran"
$ spack add macsio+scr
==> Adding macsio+scr to environment /home/spack/cache-env
$ spack install
==> Concretized macsio+scr
[+]  lbkg732  macsio@1.1%gcc@7.5.0~exodus~hdf5~ipo+mpi~pdb+scr+silo~szip~typhonio~zfp~zlib build_type=RelWithDebInfo patches=59479b946e5bbf677e814dc1cde12b38dd3b083fec8c543fc6d3abf9f73dbbfa arch=linux-ubuntu18.04-x86_64
[+]  bltycqw	  ^cmake@3.18.4%gcc@7.5.0~doc+ncurses+openssl+ownlibs~qt patches=bf695e3febb222da2ed94b3beea600650e4318975da90e4a71d6f31a6d5d8c3d arch=linux-ubuntu18.04-x86_64
[+]  crhlefo	      ^ncurses@6.2%gcc@7.5.0~symlinks+termlib arch=linux-ubuntu18.04-x86_64
[+]  4sh6pym		  ^pkgconf@1.7.3%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  es377uq	      ^openssl@1.1.1h%gcc@7.5.0+systemcerts arch=linux-ubuntu18.04-x86_64
[+]  zfdvt2j		  ^perl@5.32.0%gcc@7.5.0+cpanm+shared+threads arch=linux-ubuntu18.04-x86_64
[+]  4ihuiaz		      ^berkeley-db@18.1.40%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  4av4gyw		      ^gdbm@1.18.1%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  t54jzdy			  ^readline@8.0%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  smoyzzo		  ^zlib@1.2.11%gcc@7.5.0+optimize+pic+shared arch=linux-ubuntu18.04-x86_64
[+]  7tkgwjv	  ^json-cwx@0.12%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  mm33a3o	      ^autoconf@2.69%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  mkc3u4x		  ^m4@1.4.18%gcc@7.5.0+sigsegv patches=3877ab548f88597ab2327a2230ee048d2d07ace1062efe81fc92e91b7f39cd00,fc9b61654a3ba1a8d6cd78ce087e7c96366c290bc8d2c299f09828d793b853c8 arch=linux-ubuntu18.04-x86_64
[+]  lbrx7ln		      ^libsigsegv@2.12%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  d2krmb5	      ^automake@1.16.2%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  jdxbjft	      ^libtool@2.4.6%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  pmsyupw	  ^openmpi@3.1.6%gcc@7.5.0~atomics~cuda~cxx~cxx_exceptions+gpfs~java~legacylaunchers~lustre~memchecker~pmi~singularity~sqlite3+static~thread_multiple+vt+wrapper-rpath fabrics=none schedulers=none arch=linux-ubuntu18.04-x86_64
[+]  zqwfzhw	      ^hwloc@1.11.11%gcc@7.5.0~cairo~cuda~gl~libudev+libxml2~netloc~nvml+pci+shared arch=linux-ubuntu18.04-x86_64
[+]  bob4o5m		  ^libpciaccess@0.16%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  gs6ag7k		      ^util-macros@1.19.1%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  yn2r3wf		  ^libxml2@2.9.10%gcc@7.5.0~python arch=linux-ubuntu18.04-x86_64
[+]  jearpk4		      ^libiconv@1.16%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  komekkm		      ^xz@5.2.5%gcc@7.5.0~pic arch=linux-ubuntu18.04-x86_64
[+]  wbqbc5v		  ^numactl@2.0.14%gcc@7.5.0 patches=4e1d78cbbb85de625bad28705e748856033eaafab92a66dffd383a3d7e00cc94 arch=linux-ubuntu18.04-x86_64
[+]  sqm6ik6	  ^scr@2.0.0%gcc@7.5.0+dtcmp~fortran~ipo+libyogrt async_api=NONE build_type=RelWithDebInfo cache_base=/tmp cntl_base=/tmp copy_config=none file_lock=FLOCK resource_manager=SLURM scr_config=scr.conf arch=linux-ubuntu18.04-x86_64
[+]  fxiami4	      ^dtcmp@1.1.1%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  tzf27nc		  ^lwgrp@1.0.3%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  ld352tm	      ^libyogrt@1.24%gcc@7.5.0~static scheduler=system arch=linux-ubuntu18.04-x86_64
[+]  pv3zp64	      ^pdsh@2.31%gcc@7.5.0+ssh+static_modules arch=linux-ubuntu18.04-x86_64
[+]  vfrf7as	  ^silo@4.10.2%gcc@7.5.0~fortran+mpi+pic+shared~silex patches=7b5a1dc2a0e358e667088d77e7caa780967fa8ea60be89c44986605df9990abe arch=linux-ubuntu18.04-x86_64
[+]  vedchc5	      ^hdf5@1.10.7%gcc@7.5.0~cxx~debug~fortran~hl~java+mpi+pic+shared~szip~threadsafe api=none arch=linux-ubuntu18.04-x86_64

==> Installing environment /home/spack/cache-env
==> All of the packages are already installed
==> Updating view at /home/spack/cache-env/.spack-env/view

Once we’ve created and installed this environment, we can easily upload source code needed to reproduce this build to a mirror. The following command both creates the mirror and uploads the source code for the scr package included in our environment. The -d flag (short for --directory) tells spack where to place the mirrored source code files.

$ spack mirror create -d ~/mirror scr
==> Adding package scr@2.0.0 to mirror
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/47/471978ae0afb56a20847d3989b994fbd680d1dea21e77a5a46a964b6e3deed6b.tar.gz
####################################################################################################################################################################### 100.0%
==> Successfully created mirror in file:///home/spack/mirror
  Archive stats:
    0	 already present
    1	 added
    0	 failed to fetch.

We can configure spack to use this source mirror by adding a few lines to your spack.yaml file.

$ spack mirror add mymirror ~/mirror

Manually uploading every package in an environment can be tedious. Luckily, when run within an environment, spack mirror create with the --all flag will upload every source used to build the current environment to the specified directory.

$ spack mirror create -d ~/mirror -a
==> Adding package autoconf@2.69 to mirror
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/95/954bd69b391edc12d6a4a51a2dd1476543da5c6bbf05a95b59dc0dd6fd4c2969.tar.gz
####################################################################################################################################################################### 100.0%
==> Adding package automake@1.16.2 to mirror
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/b2/b2f361094b410b4acbf4efba7337bdb786335ca09eb2518635a09fb7319ca5c1.tar.gz
####################################################################################################################################################################### 100.0%
==> Adding package berkeley-db@18.1.40 to mirror
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/0c/0cecb2ef0c67b166de93732769abdeba0555086d51de1090df325e18ee8da9c8.tar.gz
####################################################################################################################################################################### 100.0%
==> Adding package cmake@3.18.4 to mirror
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/59/597c61358e6a92ecbfad42a9b5321ddd801fc7e7eca08441307c9138382d4f77.tar.gz
####################################################################################################################################################################### 100.0%
==> Adding package dtcmp@1.1.1 to mirror
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/dd/ddf3c57cbb83515e1b7e4111b8a83f832e66376b40eee5d8a5549dd7b8446bc6.tar.gz
####################################################################################################################################################################### 100.0%
==> Adding package gdbm@1.18.1 to mirror
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/86/86e613527e5dba544e73208f42b78b7c022d4fa5a6d5498bf18c8d6f745b91dc.tar.gz
####################################################################################################################################################################### 100.0%
==> Adding package hdf5@1.10.7 to mirror
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/7a/7a1a0a54371275ce2dfc5cd093775bb025c365846512961e7e5ceaecb437ef15.tar.gz
####################################################################################################################################################################### 100.0%
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/57/57cee5ff1992b4098eda079815c36fc2da9b10e00a9056df054f2384c4fc7523
####################################################################################################################################################################### 100.0%
==> Adding package hwloc@1.11.11 to mirror
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/74/74329da3be1b25de8e98a712adb28b14e561889244bf3a8138afe91ab18e0b3a.tar.gz
####################################################################################################################################################################### 100.0%
==> Adding package json-cwx@0.12 to mirror
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/3b/3bfae1f23eacba53ee130dbd1a6acf617af4627a9b4e4581d64b20a99b4e2b60.tar.gz
####################################################################################################################################################################### 100.0%
==> Adding package libiconv@1.16 to mirror
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/e6/e6a1b1b589654277ee790cce3734f07876ac4ccfaecbee8afa0b649cf529cc04.tar.gz
####################################################################################################################################################################### 100.0%
==> Adding package libpciaccess@0.16 to mirror
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/84/84413553994aef0070cf420050aa5c0a51b1956b404920e21b81e96db6a61a27.tar.gz
####################################################################################################################################################################### 100.0%
==> Adding package libsigsegv@2.12 to mirror
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/3a/3ae1af359eebaa4ffc5896a1aee3568c052c99879316a1ab57f8fe1789c390b6.tar.gz
####################################################################################################################################################################### 100.0%
==> Adding package libtool@2.4.6 to mirror
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/e3/e3bd4d5d3d025a36c21dd6af7ea818a2afcd4dfc1ea5a17b39d7854bcd0c06e3.tar.gz
####################################################################################################################################################################### 100.0%
==> Adding package libxml2@2.9.10 to mirror
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/aa/aafee193ffb8fe0c82d4afef6ef91972cbaf5feea100edc2f262750611b4be1f.tar.gz
####################################################################################################################################################################### 100.0%
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/96/96151685cec997e1f9f3387e3626d61e6284d4d6e66e0e440c209286c03e9cc7.tar.gz
####################################################################################################################################################################### 100.0%
==> Adding package libyogrt@1.24 to mirror
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/36/36695030e72b24b1f22bfcfe42bfd1d3c87f9c0eea5e94ce0120782581ea522f.tar.gz
####################################################################################################################################################################### 100.0%
==> Adding package lwgrp@1.0.3 to mirror
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/20/20b2fc3908bfdf04d1c177f86e227a147214cd155c548b3dd75e54c78e1c1c47.tar.gz
####################################################################################################################################################################### 100.0%
==> Adding package m4@1.4.18 to mirror
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/ab/ab2633921a5cd38e48797bf5521ad259bdc4b979078034a3b790d7fec5493fab.tar.gz
####################################################################################################################################################################### 100.0%
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/fc/fc9b61654a3ba1a8d6cd78ce087e7c96366c290bc8d2c299f09828d793b853c8
####################################################################################################################################################################### 100.0%
==> Adding package macsio@1.1 to mirror
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/a8/a86249b0f10647c0b631773db69568388094605ec1a0af149d9e61e95e6961ec.tar.gz
####################################################################################################################################################################### 100.0%
==> Adding package ncurses@6.2 to mirror
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/30/30306e0c76e0f9f1f0de987cf1c82a5c21e1ce6568b9227f7da5b71cbea86c9d.tar.gz
####################################################################################################################################################################### 100.0%
==> Adding package numactl@2.0.14 to mirror
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/1e/1ee27abd07ff6ba140aaf9bc6379b37825e54496e01d6f7343330cf1a4487035.tar.gz
####################################################################################################################################################################### 100.0%
==> Adding package openmpi@3.1.6 to mirror
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/50/50131d982ec2a516564d74d5616383178361c2f08fdd7d1202b80bdf66a0d279.tar.bz2
####################################################################################################################################################################### 100.0%
==> Adding package openssl@1.1.1h to mirror
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/5c/5c9ca8774bd7b03e5784f26ae9e9e6d749c9da2438545077e6b3d755a06595d9.tar.gz
####################################################################################################################################################################### 100.0%
==> Adding package pdsh@2.31 to mirror
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/0e/0ee066ce395703285cf4f6cf00b54b7097d12457a4b1c146bc6f33d8ba73caa7.tar.gz
####################################################################################################################################################################### 100.0%
==> Adding package perl@5.32.0 to mirror
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/ef/efeb1ce1f10824190ad1cadbcccf6fdb8a5d37007d0100d2d9ae5f2b5900c0b4.tar.gz
####################################################################################################################################################################### 100.0%
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/9d/9da50e155df72bce55cb69f51f1dbb4b62d23740fb99f6178bb27f22ebdf8a46.tar.gz
####################################################################################################################################################################### 100.0%
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/0e/0eac10ed90aeb0459ad8851f88081d439a4e41978e586ec743069e8b059370ac
####################################################################################################################################################################### 100.0%
==> Adding package pkgconf@1.7.3 to mirror
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/b8/b846aea51cf696c3392a0ae58bef93e2e72f8e7073ca6ad1ed8b01c85871f9c0.tar.xz
####################################################################################################################################################################### 100.0%
==> Adding package readline@8.0 to mirror
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/e3/e339f51971478d369f8a053a330a190781acb9864cf4c541060f12078948e461.tar.gz
####################################################################################################################################################################### 100.0%
==> Adding package scr@2.0.0 to mirror
==> Adding package silo@4.10.2 to mirror
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/3a/3af87e5f0608a69849c00eb7c73b11f8422fa36903dd14610584506e7f68e638.tar.gz
####################################################################################################################################################################### 100.0%
==> Adding package util-macros@1.19.1 to mirror
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/18/18d459400558f4ea99527bc9786c033965a3db45bf4c6a32eefdc07aa9e306a6.tar.bz2
####################################################################################################################################################################### 100.0%
==> Adding package xz@5.2.5 to mirror
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/51/5117f930900b341493827d63aa910ff5e011e0b994197c3b71c08a20228a42df.tar.bz2
####################################################################################################################################################################### 100.0%
==> Adding package zlib@1.2.11 to mirror
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/c3/c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1.tar.gz
####################################################################################################################################################################### 100.0%
==> Successfully updated mirror in file:///home/spack/mirror
  Archive stats:
    1	 already present
    30	 added
    0	 failed to fetch.

This directory can be shared between users on a shared filesystem and protected with typical unix file permissions. If you’re making a spack mirror on a shared filesystem, remember to fix the file permissions every time you update the mirror, or update your umask settings so any new files you create have the appropriate permissions. Here you would replace the word spack to the appropriate unix group.

$ umask 027
$ chmod -R g+rs ~/mirror
$ chgrp -R spack ~/mirror

As long as spack can read from the mirror directory, spack will attempt to read source packages from the mirror instead of accessing the internet. This can be a huge boon for computers that can’t access the external internet but can access a shared filesystem. If you need to use spack on a system that is isolated from the external internet, you must bundle the whole spack mirror directory and unbundle it on the isolated system. From there, you follow the same steps to use the spack mirror as you would on any computer that can’t access the external internet.

If you need to add more sources to the mirror, you can re-run the command you used to create the mirror. For example, assume we want to add bzip2 to our environment.

$ spack add bzip2
==> Adding bzip2 to environment /home/spack/cache-env
==> Updating view at /home/spack/cache-env/.spack-env/view
$ spack install
==> Concretized bzip2
 -   fvfpt26  bzip2@1.0.8%gcc@7.5.0+shared arch=linux-ubuntu18.04-x86_64
 -   otkkten	  ^diffutils@3.7%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  jearpk4	      ^libiconv@1.16%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64

==> Installing environment /home/spack/cache-env
[+] /home/spack/spack/opt/spack/linux-ubuntu18.04-x86_64/gcc-7.5.0/libiconv-1.16-jearpk4xci4zc7dkrza4fufaqfkq7rfl
==> Installing diffutils-3.7-otkktenrrvcaf37a7zyeytmjuwsalvtr
==> Fetching file:///mirror/build_cache/linux-ubuntu18.04-x86_64/gcc-7.5.0/diffutils-3.7/linux-ubuntu18.04-x86_64-gcc-7.5.0-diffutils-3.7-otkktenrrvcaf37a7zyeytmjuwsalvtr.spack
####################################################################################################################################################################### 100.0%
==> Extracting diffutils-3.7-otkktenrrvcaf37a7zyeytmjuwsalvtr from binary cache
gpgconf: socketdir is '/home/spack/.gnupg'
gpgconf:	no /run/user dir
gpgconf:	using homedir as fallback
[+] /home/spack/spack/opt/spack/linux-ubuntu18.04-x86_64/gcc-7.5.0/diffutils-3.7-otkktenrrvcaf37a7zyeytmjuwsalvtr
==> Installing bzip2-1.0.8-fvfpt26p5divvq6344vojyn64enojlui
==> Fetching file:///mirror/build_cache/linux-ubuntu18.04-x86_64/gcc-7.5.0/bzip2-1.0.8/linux-ubuntu18.04-x86_64-gcc-7.5.0-bzip2-1.0.8-fvfpt26p5divvq6344vojyn64enojlui.spack
####################################################################################################################################################################### 100.0%
==> Extracting bzip2-1.0.8-fvfpt26p5divvq6344vojyn64enojlui from binary cache
[+] /home/spack/spack/opt/spack/linux-ubuntu18.04-x86_64/gcc-7.5.0/bzip2-1.0.8-fvfpt26p5divvq6344vojyn64enojlui
==> Updating view at /home/spack/cache-env/.spack-env/view
==> Updating view at /home/spack/cache-env/.spack-env/view

Now that we’ve added bzip2, we need to update the mirror.

$ spack mirror create -d ~/mirror -a
==> Adding package autoconf@2.69 to mirror
==> Adding package automake@1.16.2 to mirror
==> Adding package berkeley-db@18.1.40 to mirror
==> Adding package bzip2@1.0.8 to mirror
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/ab/ab5a03176ee106d3f0fa90e381da478ddae405918153cca248e682cd0c4a2269.tar.gz
####################################################################################################################################################################### 100.0%
==> Adding package cmake@3.18.4 to mirror
==> Adding package diffutils@3.7 to mirror
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/b3/b3a7a6221c3dc916085f0d205abf6b8e1ba443d4dd965118da364a1dc1cb3a26.tar.xz
####################################################################################################################################################################### 100.0%
==> Adding package dtcmp@1.1.1 to mirror
==> Adding package gdbm@1.18.1 to mirror
==> Adding package hdf5@1.10.7 to mirror
==> Adding package hwloc@1.11.11 to mirror
==> Adding package json-cwx@0.12 to mirror
==> Adding package libiconv@1.16 to mirror
==> Adding package libpciaccess@0.16 to mirror
==> Adding package libsigsegv@2.12 to mirror
==> Adding package libtool@2.4.6 to mirror
==> Adding package libxml2@2.9.10 to mirror
==> Adding package libyogrt@1.24 to mirror
==> Adding package lwgrp@1.0.3 to mirror
==> Adding package m4@1.4.18 to mirror
==> Adding package macsio@1.1 to mirror
==> Adding package ncurses@6.2 to mirror
==> Adding package numactl@2.0.14 to mirror
==> Adding package openmpi@3.1.6 to mirror
==> Adding package openssl@1.1.1h to mirror
==> Adding package pdsh@2.31 to mirror
==> Adding package perl@5.32.0 to mirror
==> Adding package pkgconf@1.7.3 to mirror
==> Adding package readline@8.0 to mirror
==> Adding package scr@2.0.0 to mirror
==> Adding package silo@4.10.2 to mirror
==> Adding package util-macros@1.19.1 to mirror
==> Adding package xz@5.2.5 to mirror
==> Adding package zlib@1.2.11 to mirror
==> Successfully updated mirror in file:///home/spack/mirror
  Archive stats:
    31	 already present
    2	 added
    0	 failed to fetch.

Spack will skip uploading source code packages that are already included in the spack mirror. Mirrors can be shared across different environments, meaning one mirror can house all the source code needed to build your team’s dependencies.

Setting up a binary cache mirror

If you’re going to be setting up a team to use spack as part of their development practice, you’ll run up against the biggest disadvantage to using spack: building all your packages from scratch is slow. Recompiling the software dependencies for a large project can take hours to complete. If every developer is rebuilding their own software stack, that leads to a massive waste of computational resources and a loss of developer productivity.

Spack has two ways to help alleviate this problem: chained spack instances and spack binary caches. For now, we’re going to discuss spack binary caches as a way of solving this issue.

A spack binary cache is made up of spack binary packages. Each spack binary package, ending with a *.spack extension, is a tarball of an installed spack package signed with a gpg signature. When you install a package from a mirror with a binary cache, spack

  • Checks to see if there is a spack binary package that exactly matches the hash of the spec you want to build.

  • If a binary package is found, spack checks to see if the signature on the spack binary package is trusted. If the signature isn’t trusted or no package was found, spack builds the package from source.

  • If the signature is trusted, then spack unzips and relocates the spack package.

For the user, spack binary caches are transparent to use. This is a clear departure from systems like conda, where you need to chose separate workflows for binary and source packages. We’ve already demonstrated using spack binary caches earlier in the tutorial when we set up spack to use a binary mirror. As a reminder, we ran:

$ spack mirror add tutorial /mirror
$ spack buildcache keys --install --trust
==> Fetching file:///mirror/build_cache/_pgp/95C717877AC00FFDAA8FD6E99CFA4A453B7C69B2.pub
 ###################################################################################################################################################################### 100.0%
gpgconf: socketdir is '/home/spack/.gnupg'
gpgconf:	no /run/user dir
gpgconf:	using homedir as fallback
gpg: keybox '/home/spack/spack/opt/spack/gpg/pubring.kbx' created
gpg: /home/spack/spack/opt/spack/gpg/trustdb.gpg: trustdb created
gpg: key 9CFA4A453B7C69B2: public key "sc-tutorial (GPG created for Spack) <becker33@llnl.gov>" imported
gpg: Total number processed: 1
gpg:		   imported: 1

Building a spack binary cache has some gotchas, but is almost as easy as building a source mirror. We’ll start by making a new environment for ourselves. Since we’re intending to publish to a binary cache, we’ll need to compile all these packages ourselves. This can take some time, so we’ll make a new environment with some packages that compile quickly.

$ cd ~
$ mkdir cache-binary
$ cd cache-binary
$ spack env create -d .
==> Updating view at /home/spack/cache-binary/.spack-env/view
==> Created environment in /home/spack/cache-binary
==> You can activate this environment with:
==>   spack env activate /home/spack/cache-binary
$ spacktivate .
$ spack add bzip2
==> Adding bzip2 to environment /home/spack/cache-binary
==> Updating view at /home/spack/cache-binary/.spack-env/view
$ spack add zlib
==> Adding zlib to environment /home/spack/cache-binary
==> Updating view at /home/spack/cache-binary/.spack-env/view

Before we build anything, we need to modify the following line in our spack configuration file. Then, just to be sure, we’ll initiate a build of this environment and force ourselves to not use any cache.

$ spack config add "config:install_tree:padded_length:128"
$ spack install --no-cache
==> Concretized bzip2
 -   fvfpt26  bzip2@1.0.8%gcc@7.5.0+shared arch=linux-ubuntu18.04-x86_64
 -   otkkten	  ^diffutils@3.7%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
 -   jearpk4	      ^libiconv@1.16%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64

==> Concretized zlib
 -   smoyzzo  zlib@1.2.11%gcc@7.5.0+optimize+pic+shared arch=linux-ubuntu18.04-x86_64

==> Installing environment /home/spack/cache-binary
==> Installing libiconv-1.16-jearpk4xci4zc7dkrza4fufaqfkq7rfl
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/e6/e6a1b1b589654277ee790cce3734f07876ac4ccfaecbee8afa0b649cf529cc04.tar.gz
####################################################################################################################################################################### 100.0%
==> libiconv: Executing phase: 'autoreconf'
==> libiconv: Executing phase: 'configure'
==> libiconv: Executing phase: 'build'
==> libiconv: Executing phase: 'install'
==> Warning: Module file already exists : skipping creation
file : /home/spack/spack/share/spack/modules/linux-ubuntu18.04-x86_64/libiconv-1.16-gcc-7.5.0-jearpk4
spec : libiconv@1.16%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+] /home/spack/spack/opt/spack/spack_path_placeholder/spack_path_placeholder/spack_path_placeholder/spack_path_placeholder/spack_pa/linux-ubuntu18.04-x86_64/gcc-7.5.0/libiconv-1.16-jearpk4xci4zc7dkrza4fufaqfkq7rfl
==> Installing zlib-1.2.11-smoyzzo2qhzpn6mg6rd3l2p7b23enshg
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/c3/c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1.tar.gz
####################################################################################################################################################################### 100.0%
==> zlib: Executing phase: 'install'
==> Warning: Module file already exists : skipping creation
file : /home/spack/spack/share/spack/modules/linux-ubuntu18.04-x86_64/zlib-1.2.11-gcc-7.5.0-smoyzzo
spec : zlib@1.2.11%gcc@7.5.0+optimize+pic+shared arch=linux-ubuntu18.04-x86_64
[+] /home/spack/spack/opt/spack/spack_path_placeholder/spack_path_placeholder/spack_path_placeholder/spack_path_placeholder/spack_pa/linux-ubuntu18.04-x86_64/gcc-7.5.0/zlib-1.2.11-smoyzzo2qhzpn6mg6rd3l2p7b23enshg
==> Installing diffutils-3.7-otkktenrrvcaf37a7zyeytmjuwsalvtr
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/b3/b3a7a6221c3dc916085f0d205abf6b8e1ba443d4dd965118da364a1dc1cb3a26.tar.xz
####################################################################################################################################################################### 100.0%
==> diffutils: Executing phase: 'autoreconf'
==> diffutils: Executing phase: 'configure'
==> diffutils: Executing phase: 'build'
==> diffutils: Executing phase: 'install'
==> Warning: Module file already exists : skipping creation
file : /home/spack/spack/share/spack/modules/linux-ubuntu18.04-x86_64/diffutils-3.7-gcc-7.5.0-otkkten
spec : diffutils@3.7%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64 ^libiconv@1.16%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+] /home/spack/spack/opt/spack/spack_path_placeholder/spack_path_placeholder/spack_path_placeholder/spack_path_placeholder/spack_pa/linux-ubuntu18.04-x86_64/gcc-7.5.0/diffutils-3.7-otkktenrrvcaf37a7zyeytmjuwsalvtr
==> Installing bzip2-1.0.8-fvfpt26p5divvq6344vojyn64enojlui
==> Fetching https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/_source-cache/archive/ab/ab5a03176ee106d3f0fa90e381da478ddae405918153cca248e682cd0c4a2269.tar.gz
####################################################################################################################################################################### 100.0%
==> bzip2: Executing phase: 'install'
==> Warning: Module file already exists : skipping creation
file : /home/spack/spack/share/spack/modules/linux-ubuntu18.04-x86_64/bzip2-1.0.8-gcc-7.5.0-fvfpt26
spec : bzip2@1.0.8%gcc@7.5.0+shared arch=linux-ubuntu18.04-x86_64 ^diffutils@3.7%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64 ^libiconv@1.16%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+] /home/spack/spack/opt/spack/spack_path_placeholder/spack_path_placeholder/spack_path_placeholder/spack_path_placeholder/spack_pa/linux-ubuntu18.04-x86_64/gcc-7.5.0/bzip2-1.0.8-fvfpt26p5divvq6344vojyn64enojlui
==> Updating view at /home/spack/cache-binary/.spack-env/view
==> Updating view at /home/spack/cache-binary/.spack-env/view

This configuration change ensures that spack installs all our packages to a path that is at least 128 characters. We need this change because of how spack relocates packages. Relocation consists of the following steps:

  • Search all text files to replace the package builder’s path with your specific local installation path.

  • Use patchelf to replace all the RPATHs in your binaries to point to your specific local installation path.

  • Search all binaries to replace hard-coded C strings of the package builder’s path with your specific local installation path.

Adding padding ensures that any paths hard-coded as C strings in our binaries will be large enough to hold our user’s eventual install path. We advise picking 128 because longer strings occasionally cause compilation problems with some software packages. If the user’s install path is too long, spack will give you a warning. All scripts and and RPATHs will still be properly relocated, but C strings within any binaries will not be modified. Depending on the package, this may cause problems when you try and use the software.

We also need to create a gpg key to sign all our packages. You should back up the secret and public keys to a secure place so they can be re-used in the future.

$ spack gpg create "My Name" "<my.email@my.domain.com>"
gpgconf: socketdir is '/home/spack/.gnupg'
gpgconf:	no /run/user dir
gpgconf:	using homedir as fallback
gpg: key 070F30B4CDF253A9 marked as ultimately trusted
gpg: directory '/home/spack/spack/opt/spack/gpg/openpgp-revocs.d' created
gpg: revocation certificate stored as '/home/spack/spack/opt/spack/gpg/openpgp-revocs.d/ABC74A4103675F76561A607E070F30B4CDF253A9.rev'
$ mkdir ~/private_gpg_backup
$ cp ~/spack/opt/spack/gpg/*.gpg ~/private_gpg_backup
$ cp ~/spack/opt/spack/gpg/pubring.* ~/mirror

With this setup done, we’re ready to fill a binary cache with binary packages. Binary packages are attached to an existing source mirror. We follow the same steps we used for the source mirror – making an environment, creating the source mirror, and building the packages to a spack installation with our padded path. To upload a spec to a binary cache, simply use the command spack buildcache create --only=package spec. We use this here in a for loop to create binary packages for every non-external package in our environment. We do this by writing a find command that will return a hash of each spec in this environment and filtering out the external packages.

$
for ii in $(spack find --format "yyy {version} /{hash}" |
	    grep -v -E "^(develop^master)" |
	    grep "yyy" |
	    cut -f3 -d" ")
do
  spack buildcache create -af -d ~/mirror --only=package $ii
done
==> Buildcache files will be output to file:///home/spack/mirror/build_cache
gpgconf: socketdir is '/home/spack/.gnupg'
gpgconf:	no /run/user dir
gpgconf:	using homedir as fallback
gpg: checking the trustdb
gpg: marginals needed: 3  completes needed: 1  trust model: pgp
gpg: depth: 0  valid:	1  signed:   0	trust: 0-, 0q, 0n, 0m, 0f, 1u
gpg: using "ABC74A4103675F76561A607E070F30B4CDF253A9" as default secret key for signing
==> Buildcache files will be output to file:///home/spack/mirror/build_cache
gpgconf: socketdir is '/home/spack/.gnupg'
gpgconf:	no /run/user dir
gpgconf:	using homedir as fallback
gpg: using "ABC74A4103675F76561A607E070F30B4CDF253A9" as default secret key for signing
==> Buildcache files will be output to file:///home/spack/mirror/build_cache
gpgconf: socketdir is '/home/spack/.gnupg'
gpgconf:	no /run/user dir
gpgconf:	using homedir as fallback
gpg: using "ABC74A4103675F76561A607E070F30B4CDF253A9" as default secret key for signing
==> Buildcache files will be output to file:///home/spack/mirror/build_cache
gpgconf: socketdir is '/home/spack/.gnupg'
gpgconf:	no /run/user dir
gpgconf:	using homedir as fallback
gpg: using "ABC74A4103675F76561A607E070F30B4CDF253A9" as default secret key for signing

Voila, done! Our spack mirror has now been augmented with a binary cache. This cache can be used on systems without external internet access, just like with a spack source mirror. As always, remember to update the file permissions after updating the mirror.

$ umask 027
$ chmod -R g+rs ~/mirror
$ chgrp -R spack ~/mirror

Though it’s outside the scope of this tutorial, spack mirrors and build caches can also be hosted over https:// and s3:// as well. Consult the spack documentation for more information on how to do this.

Before a user can use this binary cache, they will need to make sure that they trust all the packages listed in the binary cache. If you’re sharing files between trusted users on a filesystem, you can do this with the following command:

$ spack buildcache keys --install --trust --force
==> Fetching file:///mirror/build_cache/_pgp/95C717877AC00FFDAA8FD6E99CFA4A453B7C69B2.pub
####################################################################################################################################################################### 100.0%
gpgconf: socketdir is '/home/spack/.gnupg'
gpgconf:	no /run/user dir
gpgconf:	using homedir as fallback
gpg: key 9CFA4A453B7C69B2: "sc-tutorial (GPG created for Spack) <becker33@llnl.gov>" not changed
gpg: Total number processed: 1
gpg:		  unchanged: 1

Together, this means download all the keys on the binary cache and trust them. Have your users run the above command on a new spack instance before they initiate a build.

Cache Summary

If you’re using spack within a development team, consider setting up source mirrors with binary caches. Source mirrors will let you replicate a spack environment on a machine without external internet access, and binary mirrors free you from the burden of recompiling everything from scratch and save you development time.