runtime.go (1649B)
1 package jci 2 3 import "time" 4 5 // ContainerRuntime is the minimal interface the runner needs from a container 6 // backend. Implementations exist for Docker (via Unix socket); future backends 7 // (Podman, containerd, …) only need to satisfy this interface — runner.go is 8 // not touched. 9 type ContainerRuntime interface { 10 // StartContainer creates and starts a container according to spec and 11 // returns its full container ID. 12 StartContainer(spec ContainerSpec) (id string, err error) 13 14 // ListContainers returns running containers that carry the given label 15 // (format "key=value" or just "key"). 16 ListContainers(labelFilter string) ([]ContainerInfo, error) 17 18 // InspectStartedAt returns the time the container with the given ID was 19 // started. 20 InspectStartedAt(id string) (time.Time, error) 21 22 // RemoveContainer forcefully removes (stops + deletes) the container. 23 RemoveContainer(id string) error 24 } 25 26 // ContainerSpec describes a container to be started. 27 type ContainerSpec struct { 28 // Image is the OCI image reference, e.g. "alpine:3". 29 Image string 30 31 // Command is the entrypoint command, e.g. ["/bin/sh", "-c", "echo hi"]. 32 Command []string 33 34 // Env is a list of "KEY=VALUE" environment variables. 35 Env []string 36 37 // Binds is a list of volume bind-mounts in "host:container[:options]" form. 38 Binds []string 39 40 // Labels is a map of container labels. 41 Labels map[string]string 42 43 // AutoRemove mirrors docker run --rm: remove the container on exit. 44 AutoRemove bool 45 } 46 47 // ContainerInfo is the subset of container state the runner needs when 48 // listing running containers. 49 type ContainerInfo struct { 50 ID string 51 Labels map[string]string 52 }