oci
is a generic driver interface around OCI (Open Container Initiative) based runtime engines. This library provides an abstraction layer for connecting to and interacting with OCI compliant runtime engines, offering a unified interface regardless of the underlying engine (Docker, Podman, etc.).
This library simplifies the process of developing containerized applications and services, offering consistent interfaces for common operations like pulling images and executing requests. It allows developers to switch between different runtime engines with minimal code changes.
- Interface-based design that enables loose coupling and easy interchangeability of runtime engines.
- Operations for pulling images from registries.
- Request execution that aligns with the standard OCI specifications.
- Standardized error handling and response structures.
- Concurrency safety for multi-threaded workloads.
import "oci"
To create a new client with a driver:
driver := NewDriver() // This should be your custom driver that implements the Driver interface
client, err := oci.NewClient(context.Background(), driver, "unix:///var/run/docker.sock")
if err != nil {
log.Fatal(err)
}
defer client.Close()
After setting up the client, you can execute OCI compliant commands. For example, to pull an image:
response, err := client.Pull(context.Background(), "alpine:latest")
if err != nil {
log.Fatal(err)
}
// Process the response...
This interface is to be implemented by different runtime engines (adapters). It provides methods for connecting to the runtime engine and handling requests.
This interface represents a connection to the runtime engine and must be implemented by the adapters. It provides methods to close the connection.
If you want to write a custom adapter for a runtime engine not currently supported, implement the Driver
and Conn
interfaces. For example:
type MyDriver struct {
// ...
}
func (d *MyDriver) Connect(ctx context.Context, sock string) (oci.Conn, error) {
// Implement connection logic...
}
func (d *MyDriver) Handler(method string) oci.Handler {
// Implement handler logic...
}
Then you can define handlers which have same signature as the HandlerFunc
var handlers map[string]oci.HandlerFunc{
string(oci.PULL): oci.HandlerFunc(MyHandler),
}
func MyHandler(req *oci.Request) (*oci.Response, error) {
// Implement handler logic...
}
Contributions to oci
are welcomed! Whether it's bug reports, feature requests, or pull requests, we appreciate all help in improving this library.
oci
is open source software [licensed under BSD 3-Clause License].