Compare commits
2 Commits
ccd3bfadb4
...
aab6711d06
| Author | SHA1 | Date | |
|---|---|---|---|
| aab6711d06 | |||
| a2123612c7 |
7
LICENSE
Normal file
7
LICENSE
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
Copyright © 2026 Aurélie DELHAIE
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
174
README.md
Normal file
174
README.md
Normal file
@@ -0,0 +1,174 @@
|
|||||||
|
# docker-updater
|
||||||
|
|
||||||
|
`docker-updater` is a small Go daemon that monitors **running Docker containers** and automatically **updates their images** on a configurable cron schedule.
|
||||||
|
|
||||||
|
At a glance:
|
||||||
|
- Schedules update jobs using cron
|
||||||
|
- Compares **local image digest** vs **remote registry digest**
|
||||||
|
- If the image changed: **stop → pull → start** the container
|
||||||
|
|
||||||
|
> ⚠️ This tool does **not recreate containers** (no `docker compose up -d` behavior).
|
||||||
|
> It operates on the existing container ID. (for now)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- Cron-based image update scheduling
|
||||||
|
- Per-container configuration using Docker labels
|
||||||
|
- Digest-based update detection (safe and deterministic)
|
||||||
|
- Simple daemon, no database, no state persistence
|
||||||
|
- Written in Go, minimal dependencies
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
- Docker installed and running
|
||||||
|
- Access to Docker socket (`/var/run/docker.sock`)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
### Build locally
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make build
|
||||||
|
```
|
||||||
|
|
||||||
|
Binary will be available at:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./build/dockerupdater
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./dockerupdater -config ./config.json
|
||||||
|
```
|
||||||
|
|
||||||
|
### CLI options
|
||||||
|
|
||||||
|
| Flag | Description | Default |
|
||||||
|
| ---------- | ------------------- | --------------- |
|
||||||
|
| `-config` | Path to config file | `./config.json` |
|
||||||
|
| `-verbose` | Enable debug logs | `false` |
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
If the config file does not exist, default values are used.
|
||||||
|
|
||||||
|
### Example config.json
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"containers": {
|
||||||
|
"enabled": false,
|
||||||
|
"schedule": "* * * * *"
|
||||||
|
},
|
||||||
|
"daemon": {
|
||||||
|
"pull_interval": 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Configuration fields
|
||||||
|
|
||||||
|
```containers```
|
||||||
|
|
||||||
|
Global default configuration applied to all containers
|
||||||
|
(unless overridden by labels).
|
||||||
|
|
||||||
|
```containers.enabled``` (bool)
|
||||||
|
Enables or disables image updates by default.
|
||||||
|
|
||||||
|
```containers.schedule``` (string)
|
||||||
|
Cron expression (5-field format).
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
*/5 * * * * → every 5 minutes
|
||||||
|
|
||||||
|
0 3 * * * → every day at 03:00
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
```daemon.pull_interval``` (uint)
|
||||||
|
|
||||||
|
Interval in seconds between daemon scans.
|
||||||
|
|
||||||
|
Used to detect:
|
||||||
|
|
||||||
|
- New containers
|
||||||
|
- Removed containers
|
||||||
|
- Container ID changes
|
||||||
|
|
||||||
|
> This does not control update frequency.
|
||||||
|
> Actual updates are triggered by cron schedules.
|
||||||
|
|
||||||
|
### Per-container configuration (Docker labels)
|
||||||
|
|
||||||
|
Containers can override global settings using Docker labels.
|
||||||
|
|
||||||
|
#### Supported labels
|
||||||
|
|
||||||
|
| Label | Description |
|
||||||
|
| -------------------------------------- | --------------------- |
|
||||||
|
| `com.thelilfrog.image.update.enable` | `"true"` or `"false"` |
|
||||||
|
| `com.thelilfrog.image.update.schedule` | Cron expression |
|
||||||
|
|
||||||
|
#### Example (```docker-compose.yml```)
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
services:
|
||||||
|
myapp:
|
||||||
|
image: ghcr.io/acme/myapp:latest
|
||||||
|
labels:
|
||||||
|
com.thelilfrog.image.update.enable: "true"
|
||||||
|
com.thelilfrog.image.update.schedule: "*/10 * * * *"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Running with Docker Compose
|
||||||
|
|
||||||
|
A minimal docker-compose.yml is provided:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
services:
|
||||||
|
runner:
|
||||||
|
build: ./
|
||||||
|
volumes:
|
||||||
|
- "/var/run/docker.sock:/var/run/docker.sock:ro"
|
||||||
|
```
|
||||||
|
|
||||||
|
## How updates work
|
||||||
|
|
||||||
|
1. Container is selected (enabled + valid digest)
|
||||||
|
2. Cron job triggers
|
||||||
|
3. Remote registry is queried
|
||||||
|
4. Digest comparison:
|
||||||
|
- Same → nothing happens
|
||||||
|
- Different → update
|
||||||
|
5. Update process:
|
||||||
|
- ```docker stop```
|
||||||
|
- ```docker pull```
|
||||||
|
- ```docker start```
|
||||||
|
|
||||||
|
## Known limitations
|
||||||
|
|
||||||
|
- Containers without RepoDigests are ignored
|
||||||
|
- Containers with multiple RepoDigests are ignored
|
||||||
|
- No container recreation
|
||||||
|
- No rollback mechanism
|
||||||
|
- Requires registry access for digest checks
|
||||||
|
|
||||||
|
## Logging
|
||||||
|
|
||||||
|
Uses structured JSON logs via slog.
|
||||||
|
|
||||||
|
Enable debug logs with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
-verbose
|
||||||
|
```
|
||||||
@@ -13,8 +13,6 @@ type (
|
|||||||
Configuration struct {
|
Configuration struct {
|
||||||
GlobalContainerConfiguration ContainerConfiguration `json:"containers"`
|
GlobalContainerConfiguration ContainerConfiguration `json:"containers"`
|
||||||
DaemonConfiguration DaemonConfiguration `json:"daemon"`
|
DaemonConfiguration DaemonConfiguration `json:"daemon"`
|
||||||
IgnoreRunningUnspecifiedContainers bool `json:"ignore_running_unspecified_containers"`
|
|
||||||
StrictValidation bool `json:"strict_validation"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DaemonConfiguration struct {
|
DaemonConfiguration struct {
|
||||||
@@ -53,8 +51,6 @@ func Default() Configuration {
|
|||||||
DaemonConfiguration: DaemonConfiguration{
|
DaemonConfiguration: DaemonConfiguration{
|
||||||
PullInterval: 2,
|
PullInterval: 2,
|
||||||
},
|
},
|
||||||
IgnoreRunningUnspecifiedContainers: true,
|
|
||||||
StrictValidation: false,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,22 +92,6 @@ func parseConfiguration(currentConfig map[string]any) (Configuration, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ignoreRunningUnspecifiedContainers, ok := currentConfig["ignore_running_unspecified_containers"]; ok {
|
|
||||||
if data, ok := ignoreRunningUnspecifiedContainers.(bool); ok {
|
|
||||||
c.IgnoreRunningUnspecifiedContainers = data
|
|
||||||
} else {
|
|
||||||
return Configuration{}, fmt.Errorf("configuration parsing: invalid ignore_running_unspecified_containers value, expected a bool")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if strictValidation, ok := currentConfig["strict_validation"]; ok {
|
|
||||||
if data, ok := strictValidation.(bool); ok {
|
|
||||||
c.StrictValidation = data
|
|
||||||
} else {
|
|
||||||
return Configuration{}, fmt.Errorf("configuration parsing: invalid strict_validation value, expected a bool")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user