spack/share/spack
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
..
bash bugfix: only complete aliases for potential aliases (#39887) 2023-09-08 12:51:26 +02:00
bootstrap Update bootstrap buildcache to support Python 3.12 (#40404) 2023-10-11 19:03:17 +02:00
csh macos sip: apply on macos only, dont store LD_LIBRARY_PATH (#38687) 2023-07-04 10:54:13 +02:00
docker license year bump (#34921) 2023-01-18 14:30:17 -08:00
docs/docker/module-file-tutorial license year bump (#34921) 2023-01-18 14:30:17 -08:00
fish Fix suffix of tab completion scripts (#39154) 2023-08-09 08:28:55 -05:00
gitlab ci: spack compiler find should list extra config scopes (#40727) 2023-10-27 09:43:01 +02:00
keys
logo
qa Improve setup build / run / test environment (#35737) 2023-10-19 20:44:05 +02:00
templates modules: no --delim option if separator is colon character (#39010) 2023-10-26 15:55:49 +02:00
setup-env.csh license year bump (#34921) 2023-01-18 14:30:17 -08:00
setup-env.fish Revert "Add style tool to fix fish file formatting (#39155)" (#39680) 2023-08-29 18:12:19 +02:00
setup-env.ps1 Windows: Add PowerShell env support (#37951) 2023-06-27 18:26:51 -07:00
setup-env.sh Change 'exit' to 'return' in setup-env.sh (#36137) 2023-10-06 16:19:19 -07:00
setup-tutorial-env.sh license year bump (#34921) 2023-01-18 14:30:17 -08:00
spack-completion.bash OCI buildcache (#38358) 2023-10-27 15:30:04 +02:00
spack-completion.fish OCI buildcache (#38358) 2023-10-27 15:30:04 +02:00