You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.5 KiB
Go
66 lines
1.5 KiB
Go
package types
|
|
|
|
import (
|
|
"github.com/docker/docker/api/types"
|
|
"strings"
|
|
)
|
|
|
|
// ImageID is a hash string representing a container image
|
|
type ImageID string
|
|
|
|
// ContainerID is a hash string representing a container instance
|
|
type ContainerID string
|
|
|
|
// ShortID returns the 12-character (hex) short version of an image ID hash, removing any "sha256:" prefix if present
|
|
func (id ImageID) ShortID() (short string) {
|
|
return shortID(string(id))
|
|
}
|
|
|
|
// ShortID returns the 12-character (hex) short version of a container ID hash, removing any "sha256:" prefix if present
|
|
func (id ContainerID) ShortID() (short string) {
|
|
return shortID(string(id))
|
|
}
|
|
|
|
func shortID(longID string) string {
|
|
prefixSep := strings.IndexRune(longID, ':')
|
|
offset := 0
|
|
length := 12
|
|
if prefixSep >= 0 {
|
|
if longID[0:prefixSep] == "sha256" {
|
|
offset = prefixSep + 1
|
|
} else {
|
|
length += prefixSep + 1
|
|
}
|
|
}
|
|
|
|
if len(longID) >= offset+length {
|
|
return longID[offset : offset+length]
|
|
}
|
|
|
|
return longID
|
|
}
|
|
|
|
// Container is a docker container running an image
|
|
type Container interface {
|
|
ContainerInfo() *types.ContainerJSON
|
|
ID() ContainerID
|
|
IsRunning() bool
|
|
Name() string
|
|
ImageID() ImageID
|
|
SafeImageID() ImageID
|
|
ImageName() string
|
|
Enabled() (bool, bool)
|
|
IsMonitorOnly() bool
|
|
Scope() (string, bool)
|
|
Links() []string
|
|
ToRestart() bool
|
|
IsWatchtower() bool
|
|
StopSignal() string
|
|
HasImageInfo() bool
|
|
ImageInfo() *types.ImageInspect
|
|
GetLifecyclePreCheckCommand() string
|
|
GetLifecyclePostCheckCommand() string
|
|
GetLifecyclePreUpdateCommand() string
|
|
GetLifecyclePostUpdateCommand() string
|
|
}
|