Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
simskij authored Dec 25, 2019
2 parents fa1b8d5 + 7c2e509 commit 39d6ca1
Show file tree
Hide file tree
Showing 13 changed files with 176 additions and 74 deletions.
33 changes: 31 additions & 2 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@
"avatar_url": "https://avatars0.githubusercontent.com/u/21138205?v=4",
"profile": "https://github.com/zoispag",
"contributions": [
"code"
"code",
"review"
]
},
{
Expand Down Expand Up @@ -375,12 +376,40 @@
"contributions": [
"code"
]
},
{
"login": "8ear",
"name": "Max H.",
"avatar_url": "https://avatars0.githubusercontent.com/u/10329648?v=4",
"profile": "https://github.com/8ear",
"contributions": [
"code"
]
},
{
"login": "pjknkda",
"name": "Jungkook Park",
"avatar_url": "https://avatars0.githubusercontent.com/u/4986524?v=4",
"profile": "https://pjknkda.github.io",
"contributions": [
"doc"
]
},
{
"login": "jnidzwetzki",
"name": "Jan Kristof Nidzwetzki",
"avatar_url": "https://avatars1.githubusercontent.com/u/5753622?v=4",
"profile": "https://achfrag.net",
"contributions": [
"doc"
]
}
],
"contributorsPerLine": 7,
"projectName": "watchtower",
"projectOwner": "containrrr",
"repoType": "github",
"repoHost": "https://github.com",
"commitConvention": "none"
"commitConvention": "none",
"skipCi": true
}
11 changes: 0 additions & 11 deletions .github/config.yml

This file was deleted.

18 changes: 18 additions & 0 deletions .github/workflows/greetings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Greetings

on: [pull_request, issues]

jobs:
greeting:
runs-on: ubuntu-latest
steps:
- uses: actions/first-interaction@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
issue-message: >
Hi there! 👋🏼
As you're new to this repo, we'd like to suggest that you read our [code of conduct](https://github.com/containrrr/watchtower/blob/master/CODE_OF_CONDUCT.md)
as well as our [contribution guidelines](https://github.com/containrrr/watchtower/blob/master/CONTRIBUTING.md).
Thanks a bunch for opening your first issue! 🙏
pr-message: >
Congratulations on opening your first pull request! We'll get back to you as soon as possible. In the meantime, please make sure you've updated the documentation to reflect your changes and have added test automation as needed. Thanks! 🙏🏼
90 changes: 49 additions & 41 deletions README.md

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,13 @@ func PreRun(cmd *cobra.Command, args []string) {

noPull, _ := f.GetBool("no-pull")
includeStopped, _ := f.GetBool("include-stopped")
reviveStopped, _ := f.GetBool("revive-stopped")
removeVolumes, _ := f.GetBool("remove-volumes")

client = container.NewClient(
!noPull,
includeStopped,
reviveStopped,
removeVolumes,
)

Expand Down
22 changes: 21 additions & 1 deletion docs/arguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Enable debug mode with verbose logging.

```
Argument: --debug
Environment Variable: N/A
Environment Variable: WATCHTOWER_DEBUG
Type: Boolean
Default: false
```
Expand Down Expand Up @@ -97,6 +97,16 @@ Environment Variable: WATCHTOWER_INCLUDE_STOPPED
Default: false
```

## Revive stopped
Start any stopped containers that have had their image updated. This argument is only usable with the `--include-stopped` argument.

```
Argument: --revive-stopped
Environment Variable: WATCHTOWER_REVIVE_STOPPED
Type: Boolean
Default: false
```

## Poll interval
Poll interval (in seconds). This value controls how frequently watchtower will poll for new images.

Expand Down Expand Up @@ -127,6 +137,16 @@ Environment Variable: WATCHTOWER_MONITOR_ONLY
Default: false
```

## Without restarting containers
Do not restart containers after updating. This option can be useful when the start of the containers
is managed by an external system such as systemd.
```
Argument: --no-restart
Environment Variable: WATCHTOWER_NO_RESTART
Type: Boolean
Default: false
```

## Without pulling new images
Do not pull new images. When this flag is specified, watchtower will not attempt to pull
new images from the registry. Instead it will only monitor the local image cache for changes.
Expand Down
12 changes: 7 additions & 5 deletions docs/credential-helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,22 @@ volumes:
helper: {}
```
and for `.docker/config.yml`:
```yaml
and for `<PATH_TO_HOME_DIR>/.docker/config.json`:
```json
{
"HttpHeaders" : {
"User-Agent" : "Docker-Client/19.03.1 (XXXXXX)"
},
"credsStore" : "osxkeychain", // ...or your prefered helper
"credsStore" : "osxkeychain",
"auths" : {
"xyzxyzxyz.dkr.ecr.eu-north-1.amazonaws.com" : {},
"https://index.docker.io/v1/": {}
},
"credHelpers": {
"xyzxyzxyz.dkr.ecr.eu-north-1.amazonaws.com" : "ecr-login",
"index.docker.io": "osxkeychain" // ...or your prefered helper
"index.docker.io": "osxkeychain"
}
}
```
```

*Note:* `osxkeychain` can be changed to your prefered credentials helper.
9 changes: 8 additions & 1 deletion docs/notifications.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@
# Notifications

Watchtower can send notifications when containers are updated. Notifications are sent via hooks in the logging system, [logrus](http://github.com/sirupsen/logrus).
The types of notifications to send are passed via the comma-separated option `--notifications` (or corresponding environment variable `WATCHTOWER_NOTIFICATIONS`), which has the following valid values:
The types of notifications to send are set by passing a comma-separated list of values to the `--notifications` option (or corresponding environment variable `WATCHTOWER_NOTIFICATIONS`), which has the following valid values:

- `email` to send notifications via e-mail
- `slack` to send notifications through a Slack webhook
- `msteams` to send notifications via MSTeams webhook
- `gotify` to send notifications via Gotify

> There is currently a [bug](https://github.com/spf13/viper/issues/380) in Viper, which prevents comma-separated slices to be used when using the environment variable. A workaround is available where we instead put quotes around the environment variable value and replace the commas with spaces, as `WATCHTOWER_NOTIFICATIONS="slack msteams"`
> If you're a `docker-compose` user, make sure to specify environment variables' values in your `.yml` file without double quotes (`"`).
>
> This prevents unexpected errors when watchtower starts.
## Settings

- `--notifications-level` (env. `WATCHTOWER_NOTIFICATIONS_LEVEL`): Controls the log level which is used for the notifications. If omitted, the default log level is `info`. Possible values are: `panic`, `fatal`, `error`, `warn`, `info` or `debug`.
Expand All @@ -27,6 +33,7 @@ To receive notifications by email, the following command-line options, or their
- `--notification-email-server-user` (env. `WATCHTOWER_NOTIFICATION_EMAIL_SERVER_USER`): The username to authenticate with the SMTP server with.
- `--notification-email-server-password` (env. `WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PASSWORD`): The password to authenticate with the SMTP server with.
- `--notification-email-delay` (env. `WATCHTOWER_NOTIFICATION_EMAIL_DELAY`): Delay before sending notifications expressed in seconds.
- `--notification-email-subjecttag` (env. `WATCHTOWER_NOTIFICATION_EMAIL_SUBJECTTAG`): Prefix to include in the subject tag. Useful when running multiple watchtowers.

Example:

Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,8 @@ require (
gopkg.in/dancannon/gorethink.v3 v3.0.5 // indirect
gopkg.in/fatih/pool.v2 v2.0.0 // indirect
gopkg.in/gorethink/gorethink.v3 v3.0.5 // indirect
golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e
google.golang.org/genproto v0.0.0-20190401181712-f467c93bbac2
google.golang.org/grpc v1.21.0
gotest.tools v2.2.0+incompatible // indirect
)
15 changes: 14 additions & 1 deletion internal/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ func RegisterSystemFlags(rootCmd *cobra.Command) {
viper.GetBool("WATCHTOWER_INCLUDE_STOPPED"),
"Will also include created and exited containers")

flags.BoolP(
"revive-stopped",
"",
viper.GetBool("WATCHTOWER_REVIVE_STOPPED"),
"Will also start stopped containers that were updated, if include-stopped is active")

flags.BoolP(
"enable-lifecycle-hooks",
"",
Expand Down Expand Up @@ -128,7 +134,7 @@ func RegisterNotificationFlags(rootCmd *cobra.Command) {
"",
viper.GetString("WATCHTOWER_NOTIFICATION_EMAIL_TO"),
"Address to send notification emails to")

flags.IntP(
"notification-email-delay",
"",
Expand Down Expand Up @@ -168,6 +174,12 @@ Should only be used for testing.
viper.GetString("WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PASSWORD"),
"SMTP server password for sending notifications")

flags.StringP(
"notification-email-subjecttag",
"",
viper.GetString("WATCHTOWER_NOTIFICATION_EMAIL_SUBJECTTAG"),
"Subject prefix tag for notifications via mail")

flags.StringP(
"notification-slack-hook-url",
"",
Expand Down Expand Up @@ -232,6 +244,7 @@ func SetDefaults() {
viper.SetDefault("WATCHTOWER_NOTIFICATIONS", []string{})
viper.SetDefault("WATCHTOWER_NOTIFICATIONS_LEVEL", "info")
viper.SetDefault("WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PORT", 25)
viper.SetDefault("WATCHTOWER_NOTIFICATION_EMAIL_SUBJECTTAG", "")
viper.SetDefault("WATCHTOWER_NOTIFICATION_SLACK_IDENTIFIER", "watchtower")
}

Expand Down
3 changes: 2 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ nav:
- 'Remote hosts': 'remote-hosts.md'
- 'Secure connections': 'secure-connections.md'
- 'Stop signals': 'stop-signals.md'
- 'Lifecycle hooks': 'lifecycle-hooks.md'
plugins:
- search
- search
6 changes: 4 additions & 2 deletions pkg/container/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type Client interface {
// * DOCKER_HOST the docker-engine host to send api requests to
// * DOCKER_TLS_VERIFY whether to verify tls certificates
// * DOCKER_API_VERSION the minimum docker api version to work with
func NewClient(pullImages bool, includeStopped bool, removeVolumes bool) Client {
func NewClient(pullImages bool, includeStopped bool, reviveStopped bool, removeVolumes bool) Client {
cli, err := dockerclient.NewClientWithOpts(dockerclient.FromEnv)

if err != nil {
Expand All @@ -50,6 +50,7 @@ func NewClient(pullImages bool, includeStopped bool, removeVolumes bool) Client
pullImages: pullImages,
removeVolumes: removeVolumes,
includeStopped: includeStopped,
reviveStopped: reviveStopped,
}
}

Expand All @@ -58,6 +59,7 @@ type dockerClient struct {
pullImages bool
removeVolumes bool
includeStopped bool
reviveStopped bool
}

func (client dockerClient) ListContainers(fn t.Filter) ([]Container, error) {
Expand Down Expand Up @@ -203,7 +205,7 @@ func (client dockerClient) StartContainer(c Container) (string, error) {

}

if !c.IsRunning() {
if !c.IsRunning() && !client.reviveStopped {
return createdContainer.ID, nil
}

Expand Down
26 changes: 17 additions & 9 deletions pkg/notifications/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ const (
// - It would only send errors
// We work around that by holding on to log entries until the update cycle is done.
type emailTypeNotifier struct {
From, To string
Server, User, Password string
Port int
tlsSkipVerify bool
entries []*log.Entry
logLevels []log.Level
delay time.Duration
From, To string
Server, User, Password, SubjectTag string
Port int
tlsSkipVerify bool
entries []*log.Entry
logLevels []log.Level
delay time.Duration
}

func newEmailNotifier(c *cobra.Command, acceptedLogLevels []log.Level) t.Notifier {
Expand All @@ -43,6 +43,7 @@ func newEmailNotifier(c *cobra.Command, acceptedLogLevels []log.Level) t.Notifie
port, _ := flags.GetInt("notification-email-server-port")
tlsSkipVerify, _ := flags.GetBool("notification-email-server-tls-skip-verify")
delay, _ := flags.GetInt("notification-email-delay")
subjecttag, _ := flags.GetString("notification-email-subjecttag")

n := &emailTypeNotifier{
From: from,
Expand All @@ -54,6 +55,7 @@ func newEmailNotifier(c *cobra.Command, acceptedLogLevels []log.Level) t.Notifie
tlsSkipVerify: tlsSkipVerify,
logLevels: acceptedLogLevels,
delay: time.Duration(delay) * time.Second,
SubjectTag: subjecttag,
}

log.AddHook(n)
Expand All @@ -62,7 +64,13 @@ func newEmailNotifier(c *cobra.Command, acceptedLogLevels []log.Level) t.Notifie
}

func (e *emailTypeNotifier) buildMessage(entries []*log.Entry) []byte {
emailSubject := "Watchtower updates"
var emailSubject string

if e.SubjectTag == "" {
emailSubject = "Watchtower updates"
} else {
emailSubject = e.SubjectTag + " Watchtower updates"
}
if hostname, err := os.Hostname(); err == nil {
emailSubject += " on " + hostname
}
Expand Down Expand Up @@ -128,7 +136,7 @@ func (e *emailTypeNotifier) SendNotification() {
time.Sleep(e.delay)
}

e.sendEntries(e.entries)
e.sendEntries(e.entries)
e.entries = nil
}

Expand Down

0 comments on commit 39d6ca1

Please sign in to comment.