ocibuild_registry (ocibuild v0.10.4)
View SourceOCI Distribution registry client.
Implements the OCI Distribution Specification for pulling and pushing container images to registries like Docker Hub, GHCR, etc.
Summary
Functions
Check if a blob exists in the registry.
Check if an error is retriable (transient network/server issues).
Pull a blob from a registry.
Pull a blob from a registry with authentication.
Pull a blob from a registry with options including progress callback.
Pull a manifest and config from a registry.
Pull a manifest and config from a registry with authentication.
Pull a manifest and config from a registry with options.
Pull manifests and configs for multiple platforms.
Push an image to a registry. Returns the manifest digest on success.
Push an image to a registry with options (supports chunked uploads). Returns the manifest digest on success.
Push a pre-built image from raw blobs to a registry.
Push multiple pre-built images as a multi-platform image.
Push multiple platform-specific images as a single multi-platform image.
Push an artifact as a referrer to an image manifest.
Push a referrer artifact with options.
Push a cosign-compatible signature as a referrer to an image manifest.
Push a cosign signature with options.
Stop the fallback httpc to allow clean VM exit.
Tag an existing manifest with a new tag.
Execute a function with retry logic for transient failures.
Types
-type operation_scope() :: pull | push.
-type progress_callback() :: fun((progress_info()) -> ok).
-type progress_info() :: #{phase := progress_phase(), layer_index => non_neg_integer(), total_layers => non_neg_integer(), bytes_received := non_neg_integer(), bytes_sent => non_neg_integer(), total_bytes := non_neg_integer() | unknown}.
-type progress_phase() :: manifest | config | layer | uploading.
-type pull_opts() :: #{progress => progress_callback(), auth => map(), size => non_neg_integer(), layer_index => non_neg_integer(), total_layers => non_neg_integer()}.
-type push_opts() :: #{chunk_size => pos_integer(), progress => progress_callback(), layer_index => non_neg_integer(), total_layers => non_neg_integer()}.
-type upload_session() :: #{upload_url := string(), bytes_uploaded := non_neg_integer()}.
Functions
Check if a blob exists in the registry.
-spec format_content_range(non_neg_integer(), non_neg_integer()) -> string().
Check if an error is retriable (transient network/server issues).
Returns true for connection failures, timeouts, and server errors (5xx).
-spec parse_range_header(string()) -> {ok, non_neg_integer()} | error.
Pull a blob from a registry.
Pull a blob from a registry with authentication.
-spec pull_blob(binary(), binary(), binary(), map(), pull_opts()) -> {ok, binary()} | {error, term()}.
Pull a blob from a registry with options including progress callback.
-spec pull_manifest(binary(), binary(), binary()) -> {ok, Manifest :: map(), Config :: map()} | {error, term()}.
Pull a manifest and config from a registry.
-spec pull_manifest(binary(), binary(), binary(), map()) -> {ok, Manifest :: map(), Config :: map()} | {error, term()}.
Pull a manifest and config from a registry with authentication.
-spec pull_manifest(binary(), binary(), binary(), map(), pull_opts()) -> {ok, Manifest :: map(), Config :: map()} | {error, term()}.
Pull a manifest and config from a registry with options.
-spec pull_manifests_for_platforms(binary(), binary(), binary(), map(), [ocibuild:platform()]) -> {ok, [{ocibuild:platform(), map(), map()}]} | {error, term()}.
Pull manifests and configs for multiple platforms.
Given a list of platforms, this function pulls the manifest and config for each platform from the base image. Used for multi-platform builds.
Returns a list of {Platform, Manifest, Config} tuples, one for each requested platform.
-spec push(ocibuild:image(), binary(), binary(), binary(), map()) -> {ok, Digest :: binary()} | {error, term()}.
Push an image to a registry. Returns the manifest digest on success.
-spec push(ocibuild:image(), binary(), binary(), binary(), map(), push_opts()) -> {ok, Digest :: binary()} | {error, term()}.
Push an image to a registry with options (supports chunked uploads). Returns the manifest digest on success.
-spec push_blobs(binary(), binary(), binary(), push_blobs_input(), map()) -> {ok, Digest :: binary()} | {error, term()}.
Push a pre-built image from raw blobs to a registry.
This function is used to push images loaded from tarballs without rebuilding. It reuses all existing push infrastructure (authentication, progress callbacks, chunked uploads, etc.).
Blobs contains:
- manifest: Raw manifest JSON
- config: Raw config JSON
- layers: List of layer info with lazy
get_datafunctions
Returns the manifest digest on success.
-spec push_blobs_multi(binary(), binary(), binary(), [push_blobs_input()], map()) -> {ok, Digest :: binary()} | {error, term()}.
Push multiple pre-built images as a multi-platform image.
Each image in the list should have platform information. Creates an image index referencing all platform manifests.
-spec push_multi([ocibuild:image()], binary(), binary(), binary(), map(), push_opts()) -> {ok, Digest :: binary()} | {error, term()}.
Push multiple platform-specific images as a single multi-platform image.
This function:
- Pushes all layers, configs, and manifests for each platform
- Creates an OCI image index referencing all platform manifests
- Tags the index so the registry serves the correct platform to clients
Each image in the list must have a platform field set.
Returns the digest of the image index on success.
-spec push_referrer(ArtifactData :: binary(), ArtifactType :: binary(), Registry :: binary(), Repo :: binary(), SubjectDigest :: binary(), SubjectSize :: non_neg_integer(), Auth :: map()) -> ok | {error, term()}.
Push an artifact as a referrer to an image manifest.
This implements the OCI Referrers API, attaching artifacts (like SBOMs)
to an existing image manifest. The artifact manifest includes a subject
field that references the target image.
ArtifactData is the raw artifact content (e.g., SPDX JSON). ArtifactType is the media type (e.g., "application/spdx+json"). SubjectDigest is the digest of the image manifest this artifact refers to. SubjectSize is the size of the subject manifest.
Returns ok on success, or {error, {referrernot_supported, }} if the registry doesn't support the referrers API.
-spec push_referrer(ArtifactData :: binary(), ArtifactType :: binary(), Registry :: binary(), Repo :: binary(), SubjectDigest :: binary(), SubjectSize :: non_neg_integer(), Auth :: map(), Opts :: push_opts()) -> ok | {error, term()}.
Push a referrer artifact with options.
-spec push_signature(PayloadJson :: binary(), Signature :: binary(), Registry :: binary(), Repo :: binary(), SubjectDigest :: binary(), SubjectSize :: non_neg_integer(), Auth :: map()) -> ok | {error, term()}.
Push a cosign-compatible signature as a referrer to an image manifest.
The signature is attached using the OCI referrers API with:
- artifactType: application/vnd.dev.cosign.simplesigning.v1+json
- Signature stored as base64 in layer annotation
- Payload stored as config blob
Returns ok on success, or {error, {referrernot_supported, }} if the registry doesn't support the referrers API.
-spec push_signature(PayloadJson :: binary(), Signature :: binary(), Registry :: binary(), Repo :: binary(), SubjectDigest :: binary(), SubjectSize :: non_neg_integer(), Auth :: map(), Opts :: push_opts()) -> ok | {error, term()}.
Push a cosign signature with options.
-spec stop_httpc() -> ok.
Stop the fallback httpc to allow clean VM exit.
Note: When using the supervised HTTP pool (ocibuild_http), this is not needed as cleanup happens automatically through OTP supervision.
-spec tag_from_digest(binary(), binary(), binary(), binary(), map()) -> {ok, binary()} | {error, term()}.
Tag an existing manifest with a new tag.
This function fetches a manifest by its digest from the registry and pushes it to a new tag. This is efficient because it doesn't re-upload blobs - it only creates a new tag reference to the same manifest.
This is used to push an image with multiple tags: the first tag does a full push (blobs + manifest), and additional tags use this function to just create new tag references.
-spec with_retry(fun(() -> {ok, T} | {error, term()}), non_neg_integer()) -> {ok, T} | {error, term()} when T :: term().
Execute a function with retry logic for transient failures.
Takes a zero-arity function that returns {ok, Result} or {error, Reason}.
Retries up to MaxRetries times with exponential backoff for retriable errors.
Example:
with_retry(fun() -> pull_blob(R, Repo, D, Auth, Opts) end, 3)