spack/lib/spack/docs
Harmen Stoppels 195f965076
OCI buildcache (#38358)
Credits to @ChristianKniep for advocating the idea of OCI image layers
being identical to spack buildcache tarballs.

With this you can configure an OCI registry as a buildcache:

```console 
$ spack mirror add my_registry oci://user/image # Dockerhub

$ spack mirror add my_registry oci://ghcr.io/haampie/spack-test # GHCR

$ spack mirror set --push --oci-username ... --oci-password ... my_registry  # set login credentials
```

which should result in this config:

```yaml
mirrors:
  my_registry:
    url: oci://ghcr.io/haampie/spack-test
    push:
      access_pair: [<username>, <password>]
```

It can be used like any other registry

```
spack buildcache push my_registry [specs...]
```

It will upload the Spack tarballs in parallel, as well as manifest + config
files s.t. the binaries are compatible with `docker pull` or `skopeo copy`.

In fact, a base image can be added to get a _runnable_ image:

```console
$ spack buildcache push --base-image ubuntu:23.04 my_registry python
Pushed ... as [image]:python-3.11.2-65txfcpqbmpawclvtasuog4yzmxwaoia.spack

$ docker run --rm -it [image]:python-3.11.2-65txfcpqbmpawclvtasuog4yzmxwaoia.spack
```

which should really be a game changer for sharing binaries.

Further, all content-addressable blobs that are downloaded and verified
will be cached in Spack's download cache. This should make repeated
`push` commands faster, as well as `push` followed by a separate
`update-index` command.

An end to end example of how to use this in Github Actions is here:

**https://github.com/haampie/spack-oci-buildcache-example**


TODO:

- [x] Generate environment modifications in config so PATH is set up
- [x] Enrich config with Spack's `spec` json (this is allowed in the OCI specification)
- [x] When ^ is done, add logic to create an index in say `<image>:index` by fetching all config files (using OCI distribution discovery API)
- [x] Add logic to use object storage in an OCI registry in `spack install`.
- [x] Make the user pick the base image for generated OCI images.
- [x] Update buildcache install logic to deal with absolute paths in tarballs
- [x] Merge with `spack buildcache` command
- [x] Merge #37441 (included here)
- [x] Merge #39077 (included here)
- [x] #39187 + #39285
- [x] #39341
- [x] Not a blocker: #35737 fixes correctness run env for the generated container images

NOTE:

1. `oci://` is unfortunately taken, so it's being abused in this PR to mean "oci type mirror". `skopeo` uses `docker://` which I'd like to avoid, given that classical docker v1 registries are not supported.
2. this is currently `https`-only, given that basic auth is used to login. I _could_ be convinced to allow http, but I'd prefer not to, given that for a `spack buildcache push` command multiple domains can be involved (auth server, source of base image, destination registry). Right now, no urllib http handler is added, so redirects to https and auth servers with http urls will simply result in a hard failure.

CAVEATS:

1. Signing is not implemented in this PR. `gpg --clearsign` is not the nicest solution, since (a) the spec.json is merged into the image config, which must be valid json, and (b) it would be better to sign the manifest (referencing both config/spec file and tarball) using more conventional image signing tools
2. `spack.binary_distribution.push` is not yet implemented for the OCI buildcache, only `spack buildcache push` is. This is because I'd like to always push images + deps to the registry, so that it's `docker pull`-able, whereas in `spack ci` we really wanna push an individual package without its deps to say `pr-xyz`, while its deps reside in some `develop` buildcache.
3. The `push -j ...` flag only works for OCI buildcache, not for others
2023-10-27 15:30:04 +02:00
..
_gh_pages_redirect Use https for links (#19244) 2020-10-09 11:24:09 -05:00
_pygments Update RtD and Sphinx configuration (#38046) 2023-06-05 17:39:11 +02:00
_static
build_systems Docs: Update spec variant checks plus python quotes and string formatting (#40643) 2023-10-23 09:15:03 +02:00
example_files Implement an optional compiler bootstrapping phase 2019-09-13 22:57:15 -07:00
images Make "minimal" the default duplicate strategy (#39621) 2023-10-06 10:24:21 +02:00
tables AutotoolsPackage / MakefilePackage: add gmake build dependency (#40380) 2023-10-18 19:56:54 +02:00
.gitignore docs: Replace package list with packages.spack.io (#40251) 2023-10-01 05:36:22 +02:00
basic_usage.rst docs: Replace package list with packages.spack.io (#40251) 2023-10-01 05:36:22 +02:00
binary_caches.rst OCI buildcache (#38358) 2023-10-27 15:30:04 +02:00
bootstrapping.rst containerize: ensure bootstrap images contain all system dependencies (#36818) 2023-08-09 09:46:59 +02:00
build_settings.rst Make "minimal" the default duplicate strategy (#39621) 2023-10-06 10:24:21 +02:00
build_systems.rst license year bump (#34921) 2023-01-18 14:30:17 -08:00
chain.rst license year bump (#34921) 2023-01-18 14:30:17 -08:00
command_index.in Rework command reference in docs, add spack commands command 2018-02-12 20:25:17 -08:00
conf.py OCI buildcache (#38358) 2023-10-27 15:30:04 +02:00
config_yaml.rst installer: Improve status reporting (#37903) 2023-07-12 08:54:45 +02:00
configuration.rst Relax environment manifest filename requirements and lockfile identification criteria (#37413) 2023-05-05 07:40:49 -05:00
containers.rst containerize: update docs to activate env before using container templates (#40493) 2023-10-13 06:59:44 +00:00
contribution_guide.rst docs: Replace package list with packages.spack.io (#40251) 2023-10-01 05:36:22 +02:00
developer_guide.rst Fix case spelling for Lmod and Tcl (#36215) 2023-03-19 01:42:50 +00:00
environments.rst docs: add quotes around some values in a YAML example (#38412) 2023-06-16 10:29:09 +02:00
extensions.rst license year bump (#34921) 2023-01-18 14:30:17 -08:00
features.rst Add a maintainers directive (#35083) 2023-01-27 07:51:24 +01:00
getting_started.rst modules: improve default naming scheme (#37808) 2023-05-28 10:06:30 +02:00
gpu_configuration.rst External ROCm: add example configuration (#39602) 2023-08-26 15:46:25 -07:00
index.rst docs: Replace package list with packages.spack.io (#40251) 2023-10-01 05:36:22 +02:00
Makefile API Docs: fix broken reference targets 2021-07-16 08:30:56 -07:00
mirrors.rst Relax environment manifest filename requirements and lockfile identification criteria (#37413) 2023-05-05 07:40:49 -05:00
module_file_generation.svg SC17: reworked module file tutorial section (#5657) 2017-11-12 00:27:20 -08:00
module_file_support.rst modules: add support for conflict in lua modulefile (#36701) 2023-07-18 10:24:46 +02:00
packaging_guide.rst Docs: Update spec variant checks plus python quotes and string formatting (#40643) 2023-10-23 09:15:03 +02:00
pipelines.rst gitlab ci: Rework how mirrors are configured (#39939) 2023-10-19 11:04:59 -05:00
replace_conda_homebrew.rst docs: Replace package list with packages.spack.io (#40251) 2023-10-01 05:36:22 +02:00
repositories.rst Allow choosing the name of the packages subdirectory in repositories (#36643) 2023-05-04 23:36:21 +02:00
requirements.txt build(deps): bump pytest from 7.4.2 to 7.4.3 in /lib/spack/docs (#40697) 2023-10-25 20:58:53 +02:00
signing.rst buildcache extractall: extract directly into spec.prefix (#37441) 2023-08-02 17:06:13 +02:00
spack.yaml license year bump (#34921) 2023-01-18 14:30:17 -08:00