Repository navigation
Library
If your program needs registry metadata, the library keeps process setup and ownership in your hands. You provide the allocator, std.http.Client, configuration, and parsed reference.
This example calls a live registry with anonymous access. Config{} does not read process credentials; inject credential sources when the registry requires them.
const std = @import("std");
const z_oci = @import("z_oci");
pub fn main(init: std.process.Init) !void {
const allocator = init.gpa;
var client = std.http.Client{
.allocator = allocator,
.io = init.io,
};
defer client.deinit();
var reference = try z_oci.Reference.parse(allocator, "ubuntu:22.04");
const outcome = blk: {
errdefer reference.deinit(allocator);
break :blk try z_oci.resolve(
allocator,
&client,
z_oci.Config{},
reference,
.{ .os = "linux", .architecture = "amd64" },
);
};
switch (outcome) {
.success => |result| {
var owned = result;
defer owned.deinit(allocator);
std.debug.print("resolved: {f}\n", .{owned.digest});
},
.failure => |failure| {
std.debug.print("resolve failed: {f}\n", .{failure});
z_oci.deinitResolveFailure(failure, allocator);
reference.deinit(allocator);
return error.ResolveFailed;
},
}
}The resolve call returns a verified digest-pinned ResolveResult. On success it moves the reference fields into that result, so do not call reference.deinit on that path. On failure, release the failure and then release the input reference as shown.
-
Reference.parseparses and normalizes a Docker or OCI image reference. -
resolvefetches and verifies a manifest, returning an owned digest-pinned result. A multi-arch reference requires aPlatformto select a leaf manifest. -
validatechecks an exact digest reference without returning a manifest. It returns.valid,.not_found, or a failure. A multi-arch digest requires a platform selection. -
getManifestreturns the parsed manifest document. The successfulstd.json.Parsed(Manifest)value owns a JSON arena and must be released withparsed.deinit(). -
inspectreturns the top-level manifest or index and, when a platform is supplied for an index, an optional selected leaf. Release a successful result withInspectionResult.deinit(). -
resolveManyresolves references sequentially with one HTTP client and auth session. Its platform option applies to the whole batch, and its result owns every success and failure item. -
pingRegistryprobeshttps://<registry>/v2/without fetching a manifest. It reports anonymous reachability, an authentication-required response, or a classified failure; it is independent ofresolve.
The allocator passed to a public call owns the returned result or failure data:
- Call
ResolveResult.deinit(allocator)for a successfulresolveresult. - Call
z_oci.deinitResolveFailure(failure, allocator)for a single-call failure fromresolve,validate,getManifest, orinspect. - Call
parsed.deinit()for a successfulgetManifestresult. - Call
InspectionResult.deinit()for a successfulinspectresult. - Call
ResolveManyResult.deinit(allocator)once for aresolveManyresult. Do not usedeinitResolveFailureon a batch item failure.
The HTTP client remains caller-owned. Keep it alive through the operation and release it after the returned value has been released. Reference.parse also returns caller-owned storage; release it on paths where resolve did not move it into a successful result.
Configuration slices and injected credential-source views are borrowed for the call. Keep their backing storage alive until the operation returns. See Credentials for the supported sources and precedence.
The z_oci.testing namespace exposes injected token and manifest exchangers for tests that should not contact a registry. examples/resolve-many.zig demonstrates the batch seam with checked-in fixture data, while examples/resolve-reference.zig shows the live public path.
- Installation covers dependency and checkout builds.
- CLI documents the command-line path.
- Examples separates offline fixtures from live registry access.
- Platform and limits documents platform matching, HTTPS boundaries, and configuration limits.