mirror of
https://github.com/containrrr/watchtower.git
synced 2025-09-21 21:30:48 +02:00
Support for --cleanup flag
The --cleanup flag will cause watchtower to automatically remove the old image after a container is restart with a new image.
This commit is contained in:
parent
b8ba80df2d
commit
dd80aa4a0d
10 changed files with 117 additions and 7 deletions
10
main.go
10
main.go
|
@ -22,6 +22,7 @@ var (
|
|||
wg sync.WaitGroup
|
||||
client container.Client
|
||||
pollInterval time.Duration
|
||||
cleanup bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -56,6 +57,10 @@ func main() {
|
|||
Name: "no-pull",
|
||||
Usage: "do not pull new images",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "cleanup",
|
||||
Usage: "remove old images after updating",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "tls",
|
||||
Usage: "use TLS; implied by --tlsverify",
|
||||
|
@ -97,6 +102,7 @@ func before(c *cli.Context) error {
|
|||
}
|
||||
|
||||
pollInterval = time.Duration(c.Int("interval")) * time.Second
|
||||
cleanup = c.GlobalBool("cleanup")
|
||||
|
||||
// Set-up container client
|
||||
tls, err := tlsConfig(c)
|
||||
|
@ -111,13 +117,13 @@ func before(c *cli.Context) error {
|
|||
}
|
||||
|
||||
func start(*cli.Context) {
|
||||
if err := actions.CheckPrereqs(client); err != nil {
|
||||
if err := actions.CheckPrereqs(client, cleanup); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
for {
|
||||
wg.Add(1)
|
||||
if err := actions.Update(client); err != nil {
|
||||
if err := actions.Update(client, cleanup); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
wg.Done()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue