mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-27 11:33:33 +00:00
chore(images): initialise Docker service with containerd client
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package containerd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/containerd/containerd/v2/client"
|
||||
)
|
||||
|
||||
// Client is a containerd client for image operations.
|
||||
type Client struct {
|
||||
Client *client.Client
|
||||
}
|
||||
|
||||
// NewClient creates a new containerd client connected to the given socket path.
|
||||
func NewClient(sockPath string) (*Client, error) {
|
||||
if sockPath == "" {
|
||||
return nil, fmt.Errorf("containerd socket path is required")
|
||||
}
|
||||
|
||||
c, err := client.New(
|
||||
sockPath,
|
||||
client.WithDefaultNamespace("moby"),
|
||||
client.WithTimeout(60*time.Second),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Client{Client: c}, nil
|
||||
}
|
||||
|
||||
// Close closes the containerd client connection.
|
||||
func (c *Client) Close() error {
|
||||
if c.Client != nil {
|
||||
return c.Client.Close()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user