ocibuild_mix (ocibuild v0.10.4)

View Source

OCI build adapter for Mix (Elixir) projects.

This module implements the ocibuild_adapter behaviour for Mix/Elixir build systems. The Elixir side (Mix.Tasks.Ocibuild and Ocibuild.MixRelease) extracts configuration and calls into this module.

Usage from Elixir

# Get configuration map to pass to ocibuild_release functions
config = :ocibuild_mix.get_config(state)

# Find release
{:ok, name, path} = :ocibuild_mix.find_release(state, opts)

# Use logging
:ocibuild_mix.info("Building image: ~s", [tag])

State Format

The state passed to this adapter is a map containing:

#{
    base_image => <<\"debian:stable-slim\">>,
    workdir => <<\"/app\">>,
    env => #{<<\"LANG\">> => <<\"C.UTF-8\">>},
    expose => [8080],
    labels => #{},
    cmd => <<\"start\">>,
    description => <<\"My app\">>,
    tags => [<<\"myapp:1.0.0\">>],
    output => <<\"myapp-1.0.0.tar.gz\">>,
    push => <<\"ghcr.io/myorg\">>,
    chunk_size => 5242880,
    %% Mix-specific fields
    release_name => myapp,
    release_path => <<\"/path/to/release\">>,
    releases_config => [...]
}

Summary

Functions

Print a message to the console.

Log an error message.

Find the release directory.

Get application version from Mix state.

Extract configuration from Mix state.

Get dependencies from Mix state.

Log an informational message.

Functions

console(Format, Args)

-spec console(io:format(), [term()]) -> ok.

Print a message to the console.

Uses standard io:format for output.

error(Format, Args)

-spec error(io:format(), [term()]) -> ok.

Log an error message.

Outputs to standard_error for visibility.

find_release(State, Opts)

-spec find_release(map(), map()) -> {ok, binary(), file:filename()} | {error, term()}.

Find the release directory.

For Mix, the release path is typically passed in the state from Elixir. If not provided, this function returns an error.

get_app_version(State)

-spec get_app_version(map()) -> binary() | undefined.

Get application version from Mix state.

The version is passed from Elixir via the state map as app_version. This is used for the org.opencontainers.image.version annotation.

get_config(State)

-spec get_config(map()) -> ocibuild_adapter:config().

Extract configuration from Mix state.

The state is expected to be a map that was already normalized by the Elixir Mix task, so we just return it with defaults applied.

get_dependencies(State)

-spec get_dependencies(map()) ->
                          {ok, [#{name := binary(), version := binary(), source := binary()}]} |
                          {error, term()}.

Get dependencies from Mix state.

The dependencies are passed from Elixir via the state map as dependencies. This is used for smart layer classification (deps vs app code) and future SBOM.

info(Format, Args)

-spec info(io:format(), [term()]) -> ok.

Log an informational message.

Uses standard io:format for output, which will be captured by the Elixir shell.