1package runtime
2
3import (
4 "context"
5 "io"
6 "time"
7)
8
9// Container represents a running container
10type Container struct {
11 ID string
12 Image string
13 Name string
14 Status string
15 Ports []int
16 Labels map[string]string
17}
18
19// NetworkInfo represents a network
20type NetworkInfo struct {
21 ID string
22 Name string
23 Driver string
24 Containers []string
25 Labels map[string]string
26}
27
28// ContainerConfig holds configuration for creating a container
29type ContainerConfig struct {
30 Image string
31 Name string
32 Env []string
33 Ports []int
34 Labels map[string]string
35 WorkingDir string
36 Cmd []string
37 AutoRemove bool
38 Volumes map[string]string // map[containerPath]volumeName
39 NetworkMode string // Network to join
40 Hostname string // Container hostname for DNS
41 Aliases []string // Additional network aliases
42}
43
44// ImageDetail represents detailed metadata for an image.
45type ImageDetail struct {
46 // ID is the runtime image identifier (for example, image ID/digest).
47 ID string
48 // RepoTags contains repository:tag references known for the image.
49 RepoTags []string
50 // Size is the image size in bytes.
51 Size int64
52 // Created is the image creation timestamp as reported by the runtime.
53 Created time.Time
54}
55
56// Runtime interface defines the contract for container runtime implementations
57type Runtime interface {
58 // Container lifecycle
59 CreateContainer(ctx context.Context, config *ContainerConfig) (*Container, error)
60 StartContainer(ctx context.Context, containerID string) error
61 WaitForContainer(ctx context.Context, containerID string) error
62 RemoveContainer(ctx context.Context, containerID string, force bool) error
63
64 // Container inspection
65 ListContainers(ctx context.Context, all bool) ([]*Container, error)
66 InspectContainer(ctx context.Context, containerID string) (*Container, error)
67 GetContainerLogs(ctx context.Context, containerID string, follow bool) (io.ReadCloser, error)
68
69 // Image operations
70 PullImage(ctx context.Context, image string) error
71 PullImageWithAuth(ctx context.Context, image, username, password string) error
72 RemoveImage(ctx context.Context, image string, force bool) error
73 ListImages(ctx context.Context) ([]string, error)
74 // ListImagesDetailed returns metadata for all images visible to the runtime.
75 ListImagesDetailed(ctx context.Context) ([]ImageDetail, error)
76
77 // Runtime information
78 Ping(ctx context.Context) error
79 Version(ctx context.Context) (string, error)
80
81 // Health and status
82 IsContainerRunning(ctx context.Context, containerID string) (bool, error)
83 GetContainerPort(ctx context.Context, containerID string, internalPort int) (int, error)
84
85 // Image and port inspection
86 GetImageExposedPorts(ctx context.Context, imageRef string) ([]int, error)
87 GetContainerExposedPorts(ctx context.Context, containerID string) ([]int, error)
88 GetContainerNetworkInfo(ctx context.Context, containerID string) (string, int, error)
89
90 // Volume management
91 InspectImageVolumes(ctx context.Context, imageRef string) ([]string, error)
92 VolumeExists(ctx context.Context, volumeName string) (bool, error)
93 // CreateVolume creates one named volume with the given labels.
94 // Labels carry ownership provenance; a caller that omits them
95 // creates an unmanaged volume that prune never adopts.
96 CreateVolume(ctx context.Context, volumeName string, labels map[string]string) error
97 RemoveVolume(ctx context.Context, volumeName string, force bool) error
98
99 // Environment inspection
100 InspectImageEnv(ctx context.Context, imageRef string) ([]string, error)
101
102 // Network management
103 CreateNetwork(ctx context.Context, name string, options map[string]string) error
104 RemoveNetwork(ctx context.Context, name string) error
105 ListNetworks(ctx context.Context) ([]*NetworkInfo, error)
106 NetworkExists(ctx context.Context, name string) (bool, error)
107 ConnectContainerToNetwork(ctx context.Context, containerName, networkName string) error
108 DisconnectContainerFromNetwork(ctx context.Context, containerName, networkName string) error
109}