mirror of
https://github.com/containrrr/watchtower.git
synced 2024-12-15 09:14:13 +02:00
parameterize repo auth
This commit is contained in:
parent
337db1d458
commit
d36899dd7c
@ -3,6 +3,7 @@ package container
|
|||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
@ -13,11 +14,9 @@ const (
|
|||||||
defaultStopSignal = "SIGTERM"
|
defaultStopSignal = "SIGTERM"
|
||||||
)
|
)
|
||||||
|
|
||||||
var auth = dockerclient.AuthConfig{
|
var username = os.Getenv("REPO_USER")
|
||||||
Username: "",
|
var password = os.Getenv("REPO_PASS")
|
||||||
Password: "",
|
var email = os.Getenv("REPO_EMAIL")
|
||||||
Email: "",
|
|
||||||
}
|
|
||||||
|
|
||||||
// A Filter is a prototype for a function that can be used to filter the
|
// A Filter is a prototype for a function that can be used to filter the
|
||||||
// results from a call to the ListContainers() method on the Client.
|
// results from a call to the ListContainers() method on the Client.
|
||||||
@ -117,7 +116,18 @@ func (client dockerClient) StartContainer(c Container) error {
|
|||||||
|
|
||||||
log.Infof("Starting %s", name)
|
log.Infof("Starting %s", name)
|
||||||
|
|
||||||
newContainerID, err := client.api.CreateContainer(config, name, &auth)
|
var err error
|
||||||
|
var newContainerID string
|
||||||
|
if username != "" && password != "" && email != "" {
|
||||||
|
auth := dockerclient.AuthConfig{
|
||||||
|
Username: username,
|
||||||
|
Password: password,
|
||||||
|
Email: email,
|
||||||
|
}
|
||||||
|
newContainerID, err = client.api.CreateContainer(config, name, &auth)
|
||||||
|
} else {
|
||||||
|
newContainerID, err = client.api.CreateContainer(config, name, nil)
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -139,9 +149,22 @@ func (client dockerClient) IsContainerStale(c Container) (bool, error) {
|
|||||||
|
|
||||||
if client.pullImages {
|
if client.pullImages {
|
||||||
log.Debugf("Pulling %s for %s", imageName, c.Name())
|
log.Debugf("Pulling %s for %s", imageName, c.Name())
|
||||||
if err := client.api.PullImage(imageName, &auth); err != nil {
|
|
||||||
return false, err
|
if username != "" && password != "" && email != "" {
|
||||||
|
auth := dockerclient.AuthConfig{
|
||||||
|
Username: username,
|
||||||
|
Password: password,
|
||||||
|
Email: email,
|
||||||
|
}
|
||||||
|
if err := client.api.PullImage(imageName, &auth); err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if err := client.api.PullImage(imageName, nil); err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
newImageInfo, err := client.api.InspectImage(imageName)
|
newImageInfo, err := client.api.InspectImage(imageName)
|
||||||
|
Loading…
Reference in New Issue
Block a user