Repository navigation
Add Chef Supermarket proxy support for Berkshelf and Policyfiles - #518
Conversation
andrew
left a comment
There was a problem hiding this comment.
Changing upstream.chef can serve a cached cookbook archive from the previous Supermarket. Please scope archive cache identity to the upstream and add a regression test covering an upstream switch with the same cookbook name and version.
|
Thanks, fixed. Archives are now cached under a filename that carries the upstream's key ( |
andrew
left a comment
There was a problem hiding this comment.
The upstream cache isolation issue is fixed. Archive filenames now include the upstream identity, and the regression test covers switching upstreams and retrieving each cached archive.
Closes #264
Adds read-only caching proxy support for Chef Supermarket at
/chef, so Berkshelf and Policyfiles can resolve and download cookbooks through the proxy. Chef moves to ✓ in the supported registries table.Usage
A private Supermarket is configured with
upstream.chef(orPROXY_UPSTREAM_CHEF), which defaults tohttps://supermarket.chef.io. Credentials go underupstream.auth, scoped to its URL.How it works
The protocol was checked against the live
supermarket.chef.ioAPI:GET /chef/universelocation_pathanddownload_urlto the proxy. Dependencies and all other fields are kept byte for byte.GET /chef/api/v1/cookbooks/{name}latest_versionandversions[]GET /chef/api/v1/cookbooks/{name}/versions/{version}cookbookandfile. Also accepts7_5_22, the form Berkshelf uses in URLs.GET /chef/api/v1/cookbooks/{name}/versions/{version}/download302to its storage host and caches the archive aspkg:chef/{name}@{version}serveRewrittenMetadata, the same path npm and Composer use. It followsmetadata_ttl, falls back to the stored copy when the upstream fails and supports ETag/304. The rewritten universe (about 7.6 MB) is cached rather than rebuilt on every request.>= 0.0.0keep their spelling rather than becoming\u003e= 0.0.0.502instead of being passed through, since passing them through would send clients around the proxy.upstream.chefat another Supermarket never serves the previous one's documents.upstream.authtransport. Because credentials are scoped by URL, the storage host behind the download redirect never receives them.Wiring
upstream.chefwith its default, env var andserve -helpentryserver.go, plus thecheflabel in request metricsconfig.example.yamlanddocs/configuration.mdwith a private Supermarket auth exampleTests
New
internal/handler/chef_test.go, against a fake Supermarket shaped like the real API, with downloads redirecting to a separate storage host:7.5.22and7_5_22), fetched from upstream oncelocation_path, thenfiledownload), covering the redirect, a cache hit and offline reads of both the cookbook and the universe400for invalid names or versions,404for unknown cookbooks,502for an unreadable universeChef is also added to the existing config,
serve -help, route-label and missing-artifact404tests. Removing the URL rewrite, the underscore handling or the credentials each makes a test fail.Live check against supermarket.chef.io
Using
proxy serve:/chef/universereturned 4,074 cookbooks with every entry rewritten. Compared with the upstream universe, all 31,355 versions have identical dependencies and fields.apt7.5.22 downloaded through the redirect as a valid tarball. Its 24,561 bytes match Supermarket'starball_file_size.go build,go vet,golangci-lint(v2.13.1),go test -race ./...and Swagger regeneration all pass locally.Not included
chef: each ecosystem has received retention in its own PR (Add per-ecosystem artifact retention (age-based eviction) #306). Chef archives are still limited bystorage.max_size.