mirror of
https://github.com/containrrr/watchtower.git
synced 2025-12-13 21:56:38 +01:00
Session report collection and report templates (#981)
* wip: notification stats * make report notifications optional * linting/documentation fixes * linting/documentation fixes * merge types.Container and container.Interface * smaller naming/format fixes * use typed image/container IDs * simplify notifier and update tests * add missed doc comments * lint fixes * remove unused constructors * rename old/new current/latest
This commit is contained in:
parent
d0ecc23d72
commit
e3dd8d688a
32 changed files with 853 additions and 598 deletions
|
|
@ -1,14 +1,53 @@
|
|||
package types
|
||||
|
||||
import "github.com/docker/docker/api/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() string
|
||||
ID() ContainerID
|
||||
IsRunning() bool
|
||||
Name() string
|
||||
ImageID() string
|
||||
ImageID() ImageID
|
||||
SafeImageID() ImageID
|
||||
ImageName() string
|
||||
Enabled() (bool, bool)
|
||||
IsMonitorOnly() bool
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue