mirror of
https://github.com/containrrr/watchtower.git
synced 2025-09-22 05:40:50 +02:00
Add more accessors to Container struct
This commit is contained in:
parent
bfed95ecaf
commit
4275d1cd3d
3 changed files with 97 additions and 23 deletions
|
@ -7,6 +7,11 @@ import (
|
|||
"github.com/samalba/dockerclient"
|
||||
)
|
||||
|
||||
const (
|
||||
watchtowerLabel = "com.centurylinklabs.watchtower"
|
||||
signalLabel = "com.centurylinklabs.watchtower.stop-signal"
|
||||
)
|
||||
|
||||
func NewContainer(containerInfo *dockerclient.ContainerInfo, imageInfo *dockerclient.ImageInfo) *Container {
|
||||
return &Container{
|
||||
containerInfo: containerInfo,
|
||||
|
@ -21,10 +26,24 @@ type Container struct {
|
|||
imageInfo *dockerclient.ImageInfo
|
||||
}
|
||||
|
||||
func (c Container) ID() string {
|
||||
return c.containerInfo.Id
|
||||
}
|
||||
|
||||
func (c Container) Name() string {
|
||||
return c.containerInfo.Name
|
||||
}
|
||||
|
||||
func (c Container) ImageName() string {
|
||||
imageName := c.containerInfo.Config.Image
|
||||
|
||||
if !strings.Contains(imageName, ":") {
|
||||
imageName = fmt.Sprintf("%s:latest", imageName)
|
||||
}
|
||||
|
||||
return imageName
|
||||
}
|
||||
|
||||
func (c Container) Links() []string {
|
||||
var links []string
|
||||
|
||||
|
@ -39,10 +58,18 @@ func (c Container) Links() []string {
|
|||
}
|
||||
|
||||
func (c Container) IsWatchtower() bool {
|
||||
val, ok := c.containerInfo.Config.Labels["com.centurylinklabs.watchtower"]
|
||||
val, ok := c.containerInfo.Config.Labels[watchtowerLabel]
|
||||
return ok && val == "true"
|
||||
}
|
||||
|
||||
func (c Container) StopSignal() string {
|
||||
if val, ok := c.containerInfo.Config.Labels[signalLabel]; ok {
|
||||
return val
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
// Ideally, we'd just be able to take the ContainerConfig from the old container
|
||||
// and use it as the starting point for creating the new container; however,
|
||||
// the ContainerConfig that comes back from the Inspect call merges the default
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue