Repository navigation
Conversation
proxy mirror and mirror jobs now take pkg:swift PURLs whose namespace is the registry scope, such as pkg:swift/apple/swift-nio@2.62.0 for apple.swift-nio. The source archive is fetched from upstream.swift, checked against the SHA-256 checksum in the release metadata and cached under the key the archive route serves. PURLs whose namespace is a source repository URL don't name a registry identity and are refused. Unversioned PURLs list releases from upstream.swift. SwiftPM reads the release list and Package.swift before it downloads an archive, and the handler passed both through uncached, so a mirrored release still couldn't be resolved with the upstream down. With cache_metadata the handler now keeps them in the metadata cache along with their Link header, which carries release list pages and the version-specific manifests, and serves them when the upstream fails. Manifests are keyed by tools version, so the 5.8 of an alternate link and the 5.8.0 SwiftPM requests share a key. The mirror stores every release list page and each manifest a release links.
andrew
left a comment
There was a problem hiding this comment.
This needs a merge of main. Five files conflict with the Helm mirror, all as adjacent additions.
storeDocument in swift_cache.go drops the hash Storage.Store returns, so Swift rows have no ContentDigest, and loadDocument reads the blob back unchecked. Every other metadata path records sha256:<hash> (cacheMetadataBlob), and since 6c9505f a stored copy that fails its digest is dropped and refetched. Release lists and manifests would be the one kind of cached metadata exempt from that. Please record the digest, and load through storedMetadataEntry(ecosystem, key, true) and openMetadataEntry from #604. They check the digest as the blob is read, and passing true skips the TTL, so the stale fallback keeps working while fetchDocument keeps its own TTL check. Please also add a test that a corrupted stored manifest is refetched.
The comment block at the top of swift_cache.go isn't attached to anything. Please move it onto fetchDocument or drop it. The MirrorRelease doc comment can be cut to its last sentence, about why the list and manifests are cached.
|
Correction: SwiftPM 6.4's own SBOM generation (SE-0509,
|
…PURLs Release lists and manifests record their sha256 digest and are read back through storedMetadataEntry and openMetadataEntry, so a corrupted copy is fetched again. pkg:swift PURLs naming a source repository are looked up through the registry's /identifiers.
Title: Mirror Swift registry releases
Part of #414.
Mirroring
pkg:swift/...failed withunsupported ecosystem. A release is now mirrored fromupstream.swift(Tuist by default):/swift/{scope}/{name}/{version}.zipserves, through the handler's own key and fetch code (swiftSourceArchiveKey,fetchSourceArchive);Package.swiftwith the version-specific manifests itsLinkheader lists go into the metadata cache.The PURL namespace is the registry scope,
pkg:swift/apple/swift-argument-parser@1.5.0forapple.swift-argument-parser, as SwiftPM's own SBOMs write registry dependencies. A PURL naming the source repository,pkg:swift/github.com/apple/swift-argument-parser(syft, Trivy, GHSA), is looked up through the upstream's/identifiers?url=https://github.com/...and the first identity listed is mirrored. A repository the registry doesn't know fails with a message naming it. The lookup goes through the metadata cache like the/identifiersroute. Unversioned PURLs list releases fromupstream.swiftwith the registries client.Release lists and manifests are stored with their sha256 digest and read back through
storedMetadataEntryandopenMetadataEntry, so a corrupted copy is dropped and fetched again, as for other cached metadata.SwiftPM requests the release list, the release metadata,
Package.swiftandPackage.swift?swift-version=5.8.0before the archive. The handler passed the list and manifests through uncached, so a mirrored release still failed to resolve with the upstream down ("failed fetching releases list"). Withcache_metadatathe handler now caches both, along with the upstreamLinkheader (release list pages, alternate manifests), and serves them while fresh or when the upstream fails. Manifests are keyed by tools version, so the5.8in the alternate link and the5.8.0SwiftPM sends share a key. Upstream errors on the manifest route now get the same problem response as the release list and metadata routes instead of being relayed, so that route is no longer inTestRelayRoutes.Serving offline needs
cache_metadataon the server, since the archive route reads the checksum from the release metadata.proxy mirroralways turns it on; mirror API jobs follow the server's setting.Tested in
internal/server/mirror_swift_test.goagainst an httptest registry with a paginated release list and an alternate manifest. It mirrors, closes the upstream and requests the list, page 2, the metadata, both manifests and the archive through the Swift handler. It also covers a checksum mismatch, listing an unversioned PURL, and repository PURLs resolved through/identifiers(versioned, listed and unknown). The handler fallback and the refetch of a corrupted manifest are tested inswift_cache_test.go. The tests fail without the mirror hook, without the cached fallback, and without the tools-version key.Against tuist.dev I mirrored
pkg:swift/apple/swift-argument-parser@1.5.0, then ranservewithHTTPS_PROXYpointing at a dead port andmetadata_ttl: 0. curl got the list, metadata, both manifests and the archive (sha25624bc0025…453c, as listed), andswift package resolvein aswift:6.0container resolved and fetched 1.5.0 through the proxy. Before the handler change it failed at the release list.--dry-runon the unversioned PURL lists all 46 releases.pkg:swift/github.com/apple/swift-argument-parser@1.5.0resolved toapple.swift-argument-parserthrough tuist.dev's/identifiersand mirrored, and an unknown repository failed with "the Swift registry has no package for https://github.com/nobody/nosuchrepo-xyz".