Skip to content

Commit

Permalink
Merge pull request #96 from pyouroboros/documentation
Browse files Browse the repository at this point in the history
Documentation
  • Loading branch information
dirtycajunrice authored Jan 14, 2019
2 parents fcc955d + ed17b48 commit d2a961e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 305 deletions.
326 changes: 25 additions & 301 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,32 @@
![alt text](https://i.imgur.com/kYbI9Hi.png)

[![Discord](https://img.shields.io/badge/Discord-Ouroboros-7289DA.svg?logo=discord&style=flat-square)](https://discord.gg/qHNByUW)
[![BuyUsCoffee](https://img.shields.io/badge/BuyMeACoffee-Donate-ff813f.svg?logo=CoffeeScript&style=flat-square)](https://buymeacoff.ee/ouroboros)
[![Travis](https://img.shields.io/travis/pyouroboros/ouroboros/master.svg?style=flat-square)](https://travis-ci.org/pyouroboros/ouroboros)
[![Docker Pulls](https://img.shields.io/docker/pulls/pyouroboros/ouroboros.svg?style=flat-square)](https://hub.docker.com/r/pyouroboros/ouroboros/)
[![Layers](https://images.microbadger.com/badges/image/pyouroboros/ouroboros.svg)](https://microbadger.com/images/pyouroboros/ouroboros)
[![Image Version](https://images.microbadger.com/badges/version/pyouroboros/ouroboros.svg)](https://hub.docker.com/r/pyouroboros/ouroboros/)
[![Pypi Version](https://img.shields.io/pypi/v/ouroboros-cli.svg?style=flat-square)](https://pypi.org/project/ouroboros-cli/)
[![Pypi Downloads](https://img.shields.io/pypi/dm/ouroboros-cli.svg?style=flat-square)](https://pypi.org/project/ouroboros-cli/)
[![Python Version](https://img.shields.io/pypi/pyversions/ouroboros-cli.svg?style=flat-square)](https://pypi.org/project/ouroboros-cli/)
[![Docker Pulls](https://img.shields.io/docker/pulls/pyouroboros/ouroboros.svg?style=flat-square)](https://hub.docker.com/r/pyouroboros/ouroboros/)
[![Layers](https://images.microbadger.com/badges/image/pyouroboros/ouroboros.svg)](https://microbadger.com/images/pyouroboros/ouroboros)

Automatically update your running Docker containers to the latest available image.

A python-based alternative to [watchtower](https://github.com/v2tec/watchtower)

## Table of Contents

- [Overview](#overview)
- [Changelog](doc/CHANGELOG.md)
- [Usage](#usage)
- [Docker](#docker)
- [Pip](#pip)
- [Options](#options)
- [Config File](#config-file)
- [Private Registries](#private-registries)
- [Scheduling](#scheduling)
- [Timezone Configuration](#timezone-configuration)
- [Notifications](#notifications)
- [Examples](#examples)
- [Monitor for updates for original tag](#monitor-for-updates-for-original-tag)
- [Update containers on a remote host](#update-containers-on-a-remote-host)
- [Change update frequency](#change-update-frequency)
- [Change loglevel](#change-loglevel)
- [Update all containers and quit ouroboros](#update-all-containers-and-quit-ouroboros)
- [Remove old docker images](#remove-old-docker-images)
- [Webhook Notifications](#webhook-notifications)
- [Prometheus metrics](#prometheus-metrics)
- [Contributing](#contributing)

## Overview

Ouroboros will monitor all running docker containers or those you specify and update said containers to the latest available image in the remote registry using the `latest` tag with the same parameters that were used when the container was first created such as volume/bind mounts, docker network connections, environment variables, restart policies, entrypoints, commands, etc. While ouroboros updates images to `latest` by default, that can be [overridden](#Options) to only monitor updates of a specific tag. Similar to [watchtower](https://github.com/v2tec/watchtower).
Ouroboros will monitor (all or specified) running docker containers and update them to the (latest or tagged) available image in the remote registry. The updated container uses the same tag and parameters that were used when the container was first created such as volume/bind mounts, docker network connections, environment variables, restart policies, entrypoints, commands, etc.

- Push your image to your registry and simply wait a couple of minutes for ouroboros to find the new image and redeploy your container autonomously.
- Push your image to your registry and simply wait your defined interval for ouroboros to find the new image and redeploy your container autonomously.
- Notify you via email or platform customized webhooks. (Currently: Discord/Slack/Pushover/HealthChecks/Generic)
- Serve metrics for trend monitoring (Currently: Prometheus/Influxdb)
- Limit your server ssh access
- `ssh -i key server.domainname "docker pull ... && docker run ..."` is for scrubs
- `docker-compose pull && docker-compose up -d` is for fancier scrubs

## Getting Started

## Usage
More detailed usage and configuration can be found on [the wiki](https://github.com/pyouroboros/ouroboros/wiki).

### Docker

Expand Down Expand Up @@ -72,21 +55,10 @@ docker run -d --name ouroboros \

or via `docker-compose`:

```yaml
version: '3'
services:
nginx:
image: nginx:1.14-alpine
ports:
- 80:80
ouroboros:
image: pyouroboros/ouroboros
volumes:
- /var/run/docker.sock:/var/run/docker.sock
command: --interval 60 --loglevel debug
```
[Official Example](https://github.com/pyouroboros/ouroboros/blob/master/docker-compose.yml)

### Pip

Ouroboros can also be installed via `pip`:

```bash
Expand All @@ -96,152 +68,22 @@ pip install ouroboros-cli
And can then be invoked using the `ouroboros` command:

```bash
$ ouroboros --interval 5 --loglevel debug
$ ouroboros --interval 300 --loglevel debug
```

> This can be useful if you would like to create a `systemd` service or similar daemon that doesn't run in a container
### Options

> All arguments can be ran together without confliction

> All arguments can be supplemented with environment variables, but command line arguments will take priority

```
docker run --rm pyouroboros/ouroboros --help
```
- `--url`, `-u` Monitor and update containers on a remote system by providing the `url` argument.
- Default is `unix://var/run/docker.sock`.
- Environment variable: `URL=tcp://localhost:2375`.
- `--interval`, `-i` Change how often ouroboros checks the remote docker registry for image updates (in seconds).
- Default is `300`.
- Environment variable: `INTERVAL=60`.
- `--monitor`, `-m` Only monitor select containers which supports an infinite amount of container names.
- Default is all containers.
- Environment variable: `MONITOR=container_1`
- `--ignore`, `-n` Ignore the listed container names.
- Default is none.
- Environment variable: `IGNORE=container_1`
- If a container name is specified to monitor and ignore, ignore takes precedent.
- `--loglevel`, `-l` The amount of logging details can be supressed or increased.
- Default is `info`.
- Environment variable: `LOGLEVEL=debug`.
- `--runonce`, `-r` Update all your running containers in one go and terminate ouroboros.
- Default is `False`.
- Environment variable: `RUNONCE=true`.
- `--cleanup`, `-c` Remove the older docker image if a new one is found and updated.
- Default is `False`.
- Environment variable: `CLEANUP=true`
- `--keep-tag`, `-k` Only monitor if updates are made to the tag of the image that the container was created with instead of using `latest`. This will enable [watchtower](https://github.com/v2tec/watchtower)-like functionality.
- Default is `False`.
- Environment variable: `KEEPTAG=true`
- `--metrics-addr` What address for the prometheus endpoint to bind to. This arg is best suited for `ouroboros-cli`.
- Default is `0.0.0.0`.
- Environment variable: `METRICS_ADDR=0.0.0.0`
- `--metrics-port` What port to run prometheus endpoint on. Running on port `8000` by default if `--metrics-port` is not supplied.
- Default is `8000`.
- Environment variable: `METRICS_PORT=8000`
- `-w, --webhook-urls` What URLs for ouroboros to POST when a container is updated.
- Default is `None`.
- Environment variable: `WEBHOOK_URLS=http://my-webhook-1`
### Config File
You can provide a [docker env file](https://docs.docker.com/engine/reference/commandline/run/#set-environment-variables--e---env---env-file) to supplement a config file with all the above listed arguments by utilizing the supported environment variables.
```bash
docker run -d --name ouroboros \
--env-file env.list \
-v /var/run/docker.sock:/var/run/docker.sock \
pyouroboros/ouroboros
```

**Sample env.list**

```
URL=tcp://localhost:2375
INTERVAL=60
KEEPTAG=true
MONITOR='["container_1", "container_2"]'
```
### Private Registries

If your running containers' docker images are stored in a secure registry that requires a username and password, simply run ouroboros with 2 environment variables(`REPO_USER` and `REPO_PASS`).

```bash
docker run -d --name ouroboros \
-e REPO_USER=myUser -e REPO_PASS=myPassword \
-v /var/run/docker.sock:/var/run/docker.sock \
pyouroboros/ouroboros
```

You can alternatively bind mount `~/.docker/config.json` which won't require the above environment variables.

```bash
docker run -d --name ouroboros \
-v $HOME/.docker/config.json:/root/.docker/config.json \
-v /var/run/docker.sock:/var/run/docker.sock \
pyouroboros/ouroboros
```
### Scheduling

Ouroboros does not have a native scheduling implementation other than using `--interval`. This is due to there being more robust/customizable job schedulers being available such as:

- Cron
- [Cron Tutorial](https://www.ostechnix.com/a-beginners-guide-to-cron-jobs/)
- [Cron Expression Creator](https://crontab.guru/)
- Systemd Timers
- [Documentation](https://wiki.archlinux.org/index.php/Systemd/Timers)

Example using ouroboros to update containers every Monday at 5AM:

**Docker**

```bash
* 5 * * 1 docker run --rm -d --name ouroboros -v /var/run/docker.sock:/var/run/docker.sock pyouroboros/ouroboros --interval 1 --runonce
```

**Pip installed CLI**

```bash
* 5 * * 1 ouroboros --interval 1 --runonce
```

Using the [`--runonce`](#update-all-containers-and-quit-ouroboros) arg tells ouroboros to make one pass updating all/specified containers and then exit.

### Timezone Configuration

To more closely monitor ouroboros' actions and for accurate log ingestion, you can change the timezone of the container from UTC by setting the [`TZ`](http://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html) environment variable like so:

```
docker run -d --name ouroboros \
-e TZ=America/Chicago \
-v /var/run/docker.sock:/var/run/docker.sock \
pyouroboros/ouroboros
```

## Notifications

### Webhooks

Ourboros has the ability to trigger multiple webhooks for slack integration or other automation. Detailed request information can be seen by [enabling the debug loglevel](#change-loglevel). If the appropriate [args/environment variables](#options) are supplied, a POST request will be sent to specified URLs with a slack-compatible JSON payload like so:


```
{"text": "Container: alpine updated from sha256:34ea7509dcad10aa92310f2b41e3afbabed0811ee3a902d6d49cb90f075fe444 to sha256:3f53bb00af943dfdf815650be70c0fa7b426e56a66f5e3362b47a129d57d5991"}
```

## Examples

### Monitor for updates for original tag
Instead of always updating to `latest` you can specify if you would like Ouroboros to only check for updates for your original container's image tag.
e.g. If your container was started with `nginx:1.14-alpine` using `--keep-tag` will poll the docker registry and compare digests. If there is a new image for `nginx:1.14-alpine`, ouroboros will update your container using the newly patched version.
> Default is `False`
### Monitor for updates for latest tag
Instead of updating to your original image tag you can specify if you would like Ouroboros to update all containers to `latest`.
e.g. If your container was started with `nginx:1.14-alpine` using `LATEST=true` will poll the docker registry and compare digests. If there is a new image for `nginx:latest`, ouroboros will update your container using the newly patched version.
> Default is `false`
```bash
docker run -d --name ouroboros \
-v /var/run/docker.sock:/var/run/docker.sock \
pyouroboros/ouroboros --keep-tag
-e LATEST=true \
pyouroboros/ouroboros
```

### Update containers on a remote host
Expand All @@ -253,129 +95,11 @@ Ouroboros can monitor things other than just local, pass the `--url` argument to
```bash
docker run -d --name ouroboros \
-v /var/run/docker.sock:/var/run/docker.sock \
pyouroboros/ouroboros --url tcp://my-remote-docker-server:2375
```

### Change update frequency

An `interval` argument can be supplied to change how often ouroboros checks the remote docker registry for image updates (in seconds).

> Default is 300s
```bash
docker run -d --name ouroboros \
-v /var/run/docker.sock:/var/run/docker.sock \
pyouroboros/ouroboros --interval 600
```

### Monitor select containers

By default, ouroboros will monitor all running docker containers, but can be overridden to only monitor select containers by passing a `monitor` argument which supports an infinite amount of container names.

> Default is all
```bash
docker run -d --name ouroboros \
-v /var/run/docker.sock:/var/run/docker.sock \
pyouroboros/ouroboros --monitor container_1 container_2 container_3
```

### Change loglevel

The amount of logging details can be supressed by providing a `loglevel` argument.

> Default is info
```bash
docker run -d --name ouroboros \
-v /var/run/docker.sock:/var/run/docker.sock \
pyouroboros/ouroboros --loglevel debug
```

### Update all containers and quit ouroboros

If you prefer ouroboros didn't run all the time and only update all of your running containers in one go, provide the `runonce` argument and ouroboros will terminate itself after updating all your containers one time.

> Default is `False`
```bash
docker run -d --name ouroboros \
-v /var/run/docker.sock:/var/run/docker.sock \
pyouroboros/ouroboros --runonce
```

### Remove old docker images

Ouroboros has the option to remove the older docker image if a new one is found and the container is then updated. To tidy up after updates, pass the `cleanup` argument.

> Default is `False`
```bash
docker run -d --name ouroboros \
-v /var/run/docker.sock:/var/run/docker.sock \
pyouroboros/ouroboros --cleanup
```

### Prometheus metrics

Ouroboros keeps track of containers being updated and how many are being monitored. Said metrics are exported using [prometheus](https://prometheus.io/). Metrics are collected by ouroboros with or without this flag, it is up to you if you would like to expose the port or not. You can also bind the http server to a different interface for systems using multiple networks. `--metrics-port` and `--metrics-addr` can run independently of each other without issue.

#### Port

> Default is `8000`
```bash
docker run -d --name ouroboros \ ://my-webhook-1 https://my-webhook-2
-p 5000:5000 \ ://my-webhook-1 https://my-webhook-2
-v /var/run/docker.sock:/var/run/docker.sock \ ://my-webhook-1 https://my-webhook-2
pyouroboros/ouroboros --metrics-port 5000 ://my-webhook-1 https://my-webhook-2
```

You should then be able to see the metrics at http://localhost:5000/

#### Bind Address

Ouroboros allows you to bind the exporter to a different interface using the `--metrics-addr` argument. This works better for the CLI since docker networks always use `172.*.*.*` addresses, unless you have a very specific config.

> Default is `0.0.0.0`
```bash
docker run -d --name ouroboros \
-p 8000:8000 \
-v /var/run/docker.sock:/var/run/docker.sock \
pyouroboros/ouroboros --metrics-addr 10.0.0.1
```

Then access via http://10.0.0.1:8000/

**Example text from endpoint:**

```
# HELP containers_updated_total Count of containers updated
# TYPE containers_updated_total counter
containers_updated_total{container="all"} 2.0
containers_updated_total{container="alpine"} 1.0
containers_updated_total{container="busybox"} 1.0
# TYPE containers_updated_created gauge
containers_updated_created{container="all"} 1542152615.625264
containers_updated_created{container="alpine"} 1542152615.6252713
containers_updated_created{container="busybox"} 1542152627.7476819
# HELP containers_being_monitored Count of containers being monitored
# TYPE containers_being_monitored gauge
containers_being_monitored 2.0
-e DOCKER_SOCKETS=tcp://my-remote-docker-server:2376 \
pyouroboros/ouroboros
```

### Webhook Notifications

See [notifications](#notifications)

> Default is `None`
```bash
docker run -d --name ouroboros \
-v /var/run/docker.sock:/var/run/docker.sock \
pyouroboros/ouroboros --webhook-urls http://my-webhook-1 https://my-webhook-2
```
Many more examples are located in our wiki on the [usage page](https://github.com/pyouroboros/ouroboros/wiki/Usage)

## Contributing

Expand Down
4 changes: 2 additions & 2 deletions pyouroboros/ouroboros.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ def main():
help='Check for latest image instead of pulling current tag')

docker_group.add_argument('-r', '--repo-user', default=None, dest='REPO_USER',
help='Private docker repository username\n'
help='Private docker registry username\n'
'EXAMPLE: foo@bar.baz')

docker_group.add_argument('-R', '--repo-pass', default=None, dest='REPO_PASS',
help='Private docker repository password\n'
help='Private docker registry password\n'
'EXAMPLE: MyPa$$w0rd')

data_group = parser.add_argument_group('Data Export', 'Configuration of data export functionality')
Expand Down
Loading

0 comments on commit d2a961e

Please sign in to comment.