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 RestartContainer(ctx context.Context, containerID string) error
71 RemoveContainer(ctx context.Context, containerID string, force bool) error
72
73 // Container inspection
74 ListContainers(ctx context.Context, all bool) ([]*Container, error)
75 InspectContainer(ctx context.Context, containerID string) (*Container, error)
76 GetContainerLogs(ctx context.Context, containerID string, follow bool) (io.ReadCloser, error)
77
78 // Image operations
79 PullImage(ctx context.Context, image string) error
80 PullImageWithAuth(ctx context.Context, image, username, password string) error
81 RemoveImage(ctx context.Context, image string, force bool) error
82 ListImages(ctx context.Context) ([]string, error)
83 // ListImagesDetailed returns metadata for all images visible to the runtime.
84 ListImagesDetailed(ctx context.Context) ([]ImageDetail, error)
85 // PruneImages removes images eligible for prune; when danglingOnly is true,
86 // only dangling images are pruned.
87 PruneImages(ctx context.Context, danglingOnly bool) (PruneReport, error)
88
89 // Runtime information
90 Ping(ctx context.Context) error
91 Version(ctx context.Context) (string, error)
92
93 // Health and status
94 IsContainerRunning(ctx context.Context, containerID string) (bool, error)
95 GetContainerPort(ctx context.Context, containerID string, internalPort int) (int, error)
96
97 // Image and port inspection
98 GetImageExposedPorts(ctx context.Context, imageRef string) ([]int, error)
99 GetContainerExposedPorts(ctx context.Context, containerID string) ([]int, error)
100 GetContainerNetworkInfo(ctx context.Context, containerID string) (string, int, error)
101
102 // Volume management
103 InspectImageVolumes(ctx context.Context, imageRef string) ([]string, error)
104 VolumeExists(ctx context.Context, volumeName string) (bool, error)
105 CreateVolume(ctx context.Context, volumeName string) error
106 RemoveVolume(ctx context.Context, volumeName string, force bool) error
107
108 // Environment inspection
109 InspectImageEnv(ctx context.Context, imageRef string) ([]string, error)
110
111 // Network management
112 CreateNetwork(ctx context.Context, name string, options map[string]string) error
113 RemoveNetwork(ctx context.Context, name string) error
114 ListNetworks(ctx context.Context) ([]*NetworkInfo, error)
115 NetworkExists(ctx context.Context, name string) (bool, error)
116 ConnectContainerToNetwork(ctx context.Context, containerName, networkName string) error
117 DisconnectContainerFromNetwork(ctx context.Context, containerName, networkName string) error
118}