23 releases

0.3.9 Jul 26, 2024
0.3.8 Jun 5, 2024
0.3.5 May 28, 2024
0.2.9 Apr 11, 2024
0.1.0 Jul 24, 2022

#28 in Build Utils

Download history 2036/week @ 2024-07-21 1809/week @ 2024-07-28 2537/week @ 2024-08-04 2285/week @ 2024-08-11 2380/week @ 2024-08-18 3126/week @ 2024-08-25 2643/week @ 2024-09-01 2137/week @ 2024-09-08 2364/week @ 2024-09-15 2383/week @ 2024-09-22 2373/week @ 2024-09-29 2549/week @ 2024-10-06 2548/week @ 2024-10-13 2301/week @ 2024-10-20 2332/week @ 2024-10-27 2140/week @ 2024-11-03

9,436 downloads per month
Used in 69 crates (4 directly)

MIT/Apache

100KB
2K SLoC

ocipkg

crate docs.rs master

OCI Registry for package distribution.

Features

ocipkg is designed as a thin OCI registry client:

  • Read and Write oci-archive format (tar archive of OCI Image Layout).
  • Push and Pull container images to OCI registry without external container runtime, e.g. docker or podman

In addition, ocipkg provides utilities for using OCI registry for package distribution:

  • CLI tool for building containers from files, directory, and Rust project with Cargo.toml metadata.
  • build.rs helper for getting and linking library file (*.a or *.so) as a container

Why ocipkg?

I have determined to start this project while writing FFI crate in Rust. The problem is "how to get a share/static library linked to FFI crate". This is the problem bothered me and prevent from creating portable C++ library.

We have three options:

  1. Use library in the system
    • ✔ Library is prepared by the system administrator who would be most familiar with the system.
    • ❌ Developer have to know how the library is distributed in user's system, possibly Ubuntu 22.04, 20.04, 18.04, Debian sid, 11, 10, 9, RHEL9, 8, 7, ArchLinux, Gentoo Linux, FreeBSD, macOS with brew, Windows with winget, chocolatey, scoop, ...
    • ❌ Some system does not allows co-existence of multi-version libraries.
    • Most of *-sys crate support this option.
  2. Get source code from the internet, and build and link them
    • ✔ Developer can control the library fully.
    • ❌ Development tool, e.g. cmake, is required in user system, and requires additional build resources.
    • Some crate support this option, and they are named with *-src.
  3. Get compiled library from the internet on build time
    • ✔ Developer can control the library fully, too.
    • ❌ Requires HTTP(or other protocol) server to distribute the library
    • ❌ Developer have to ready binaries for every supported platforms, e.g. x86_64-unknown-linux-gnu, x86_64-pc-windows-msvc, aarch64-unknown-linux-gnu,...

ocipkg focuses on the option 3., i.e. helping distributing binary compiled by the developer through OCI registry.

Examples

Rust

C++/cmake

CLI tools

Install

cargo install ocipkg-cli

ocipkg command

TBW

cargo-ocipkg command

A tool for creating and publishing container consists of static or dynamic library built by cargo build:

$ cargo ocipkg build --release
    Finished release [optimized] target(s) in 0.00s
    Creating oci-archive (/home/teramura/github.com/termoshtt/ocipkg/examples/dynamic/rust/lib/target/release/ocipkg_dd0c7a812fd0fcbc.tar)

The filename is in form of ocipkg_{{ hash }}.tar, and this hash is calculated from image name and Cargo.toml.

Container image name is determined using git commit hash as {{ registry }}:$(git rev-parse HEAD --short) where registry name is set by Cargo.toml:

[package.metadata.ocipkg]
registry = "ghcr.io/termoshtt/ocipkg/dynamic/rust"

This container can be published by cargo-ocipkg publish:

$ cargo ocipkg publish --release
     Publish container (ghcr.io/termoshtt/ocipkg/dynamic/rust:be7f108)

Open Container Initiative (OCI) is a project under Linux Foundation.

This project does not depend on OCI Runtime specification since we never run a container.

The idea that distribute any files (not a system image) using OCI registry is based on ORAS.

Similar projects trying to distribute packages using OCI registries:

License

© 2020 Toshiki Teramura (@termoshtt)

This project is licensed under either of

at your option.

Dependencies

~10–22MB
~322K SLoC