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// PruneReport represents the result of an image prune operation.
45type PruneReport struct {
46 // DeletedIDs contains runtime-provided image identifiers removed by prune.
47 DeletedIDs []string
48 // SpaceReclaimed is the number of bytes reclaimed by prune.
49 SpaceReclaimed int64
50}
51
52// ImageDetail represents detailed metadata for an image.
53type ImageDetail struct {
54 // ID is the runtime image identifier (for example, image ID/digest).
55 ID string
56 // RepoTags contains repository:tag references known for the image.
57 RepoTags []string
58 // Size is the image size in bytes.
59 Size int64
60 // Created is the image creation timestamp as reported by the runtime.
61 Created time.Time
62}
63
64// Runtime interface defines the contract for container runtime implementations
65type Runtime interface {
66 // Container lifecycle
67 CreateContainer(ctx context.Context, config *ContainerConfig) (*Container, error)
68 StartContainer(ctx context.Context, containerID string) error
69 StopContainer(ctx context.Context, containerID string) error
70 WaitForContainer(ctx context.Context, containerID string) error
71 RestartContainer(ctx context.Context, containerID string) error
72 RemoveContainer(ctx context.Context, containerID string, force bool) error
73
74 // Container inspection
75 ListContainers(ctx context.Context, all bool) ([]*Container, error)
76 InspectContainer(ctx context.Context, containerID string) (*Container, error)
77 GetContainerLogs(ctx context.Context, containerID string, follow bool) (io.ReadCloser, error)
78
79 // Image operations
80 PullImage(ctx context.Context, image string) error
81 PullImageWithAuth(ctx context.Context, image, username, password string) error
82 RemoveImage(ctx context.Context, image string, force bool) error
83 ListImages(ctx context.Context) ([]string, error)
84 // ListImagesDetailed returns metadata for all images visible to the runtime.
85 ListImagesDetailed(ctx context.Context) ([]ImageDetail, error)
86 // PruneImages removes images eligible for prune; when danglingOnly is true,
87 // only dangling images are pruned.
88 PruneImages(ctx context.Context, danglingOnly bool) (PruneReport, error)
89
90 // Runtime information
91 Ping(ctx context.Context) error
92 Version(ctx context.Context) (string, error)
93
94 // Health and status
95 IsContainerRunning(ctx context.Context, containerID string) (bool, error)
96 GetContainerPort(ctx context.Context, containerID string, internalPort int) (int, error)
97
98 // Image and port inspection
99 GetImageExposedPorts(ctx context.Context, imageRef string) ([]int, error)
100 GetContainerExposedPorts(ctx context.Context, containerID string) ([]int, error)
101 GetContainerNetworkInfo(ctx context.Context, containerID string) (string, int, error)
102
103 // Volume management
104 InspectImageVolumes(ctx context.Context, imageRef string) ([]string, error)
105 VolumeExists(ctx context.Context, volumeName string) (bool, error)
106 CreateVolume(ctx context.Context, volumeName string) error
107 RemoveVolume(ctx context.Context, volumeName string, force bool) error
108
109 // Environment inspection
110 InspectImageEnv(ctx context.Context, imageRef string) ([]string, error)
111
112 // Network management
113 CreateNetwork(ctx context.Context, name string, options map[string]string) error
114 RemoveNetwork(ctx context.Context, name string) error
115 ListNetworks(ctx context.Context) ([]*NetworkInfo, error)
116 NetworkExists(ctx context.Context, name string) (bool, error)
117 ConnectContainerToNetwork(ctx context.Context, containerName, networkName string) error
118 DisconnectContainerFromNetwork(ctx context.Context, containerName, networkName string) error
119}