2022-03-07 21:45:54 +00:00
|
|
|
# Fresh: Keeping your docker stacks up to date
|
|
|
|
|
2022-03-08 23:38:57 +00:00
|
|
|
Fresh was written to scratch an itch. It works by querying the respective repositories
|
2022-03-19 22:22:08 +00:00
|
|
|
for the various manifests in order to determine if the images have been changed. If so
|
|
|
|
it can do a combination of things:
|
|
|
|
|
|
|
|
- Set the exitcode to indicate the freshness, `0` means up-to-date and `1` outdated.
|
|
|
|
- Pull the updated images with docker-compose, and optionally recreate the containers
|
|
|
|
with `docker-compose up`.
|
|
|
|
- Run a script before and after updating, f.ex. to enable maintenance mode or update
|
|
|
|
permission on volumes.
|
|
|
|
- Notify webhooks when updating. Currently only Slack and Mattermost are supported.
|
|
|
|
|
|
|
|
Fresh is designed to be invoked using cron or systemd timers, and as such provides
|
|
|
|
a light-weight easy-to-use alternative to more complex toolkits.
|
2022-03-08 23:38:57 +00:00
|
|
|
|
2022-03-20 23:48:19 +00:00
|
|
|
## How to install
|
|
|
|
|
|
|
|
Fresh requires **PHP 8.0** or later.
|
|
|
|
|
|
|
|
Download the latest version (or build it yourself) and move it into `/usr/bin`.
|
2022-07-05 20:46:11 +00:00
|
|
|
You can grab it at [https://dev.noccylabs.info/noccy/fresh/releases](https://dev.noccylabs.info/noccy/fresh/releases)
|
|
|
|
or [https://files.noccylabs.info/fresh](https://files.noccylabs.info/fresh)
|
2022-03-20 23:48:19 +00:00
|
|
|
|
|
|
|
### Building
|
2022-03-07 21:45:54 +00:00
|
|
|
|
2022-03-20 00:02:19 +00:00
|
|
|
Build using NoccyLabs Pharlite, included in the tools directory. Don't forget to run
|
2022-03-20 23:48:19 +00:00
|
|
|
composer to install dependencies first. In order to properly generate or update the
|
|
|
|
version file, use the `build.sh` script:
|
2022-03-07 21:45:54 +00:00
|
|
|
|
2022-03-20 00:02:19 +00:00
|
|
|
$ composer install
|
2022-03-20 23:48:19 +00:00
|
|
|
$ tools/build.sh
|
2022-03-10 01:32:47 +00:00
|
|
|
|
2022-03-20 23:48:19 +00:00
|
|
|
The generated .phar can be found as `fresh.phar` and `dist/fresh-VERSION.phar`.
|
2022-03-19 22:22:08 +00:00
|
|
|
|
2022-03-07 21:45:54 +00:00
|
|
|
## Usage
|
|
|
|
|
2022-03-08 23:38:57 +00:00
|
|
|
To check for updates, pull updated images and recreate any containers defined in the
|
|
|
|
`docker-compose.yml` in the current directory:
|
2022-03-07 21:45:54 +00:00
|
|
|
|
2022-03-10 01:32:47 +00:00
|
|
|
$ fresh.phar
|
2022-03-07 21:45:54 +00:00
|
|
|
|
2022-03-19 22:22:08 +00:00
|
|
|
Specify a directory to chdir into; very useful with cron:
|
|
|
|
|
|
|
|
$ fresh.phar --dir /srv/docker/mystack
|
|
|
|
|
|
|
|
To invoke scripts or webhooks:
|
|
|
|
|
|
|
|
$ fresh.phar --before scripts/sitedown.sh --after scripts/siteup.sh \
|
|
|
|
--slack https://my.slack.or/mattermost/webhook
|
|
|
|
|
2022-03-20 00:02:19 +00:00
|
|
|
Check a specific image:
|
|
|
|
|
|
|
|
$ fresh.phar --image my.private.repo/name/package:latest --check -w
|
|
|
|
$ echo $? # if 1, a newer version is available
|
|
|
|
|
2022-03-21 00:00:00 +00:00
|
|
|
Check images defined in a custom configuration file:
|
|
|
|
|
|
|
|
$ cat freshdocker.conf
|
|
|
|
check:
|
2022-03-21 00:07:24 +00:00
|
|
|
- my.docker.repo/vendor/image:latest
|
2022-03-21 00:00:00 +00:00
|
|
|
$ bin/freshdocker -C fresh --check -v
|
|
|
|
# ..or..
|
|
|
|
$ bin/freshdocker -c freshdocker.conf --check -v
|
|
|
|
|
2022-03-08 23:38:57 +00:00
|
|
|
For all available options, use the `--help` flag.
|
2022-03-07 21:45:54 +00:00
|
|
|
|
2022-03-20 23:48:19 +00:00
|
|
|
Some of the options can be read from environment variables, for example `FRESH_AFER`
|
|
|
|
or `FRESH_SLACK`. See `--help` for supported variables.
|
|
|
|
|
2022-03-08 23:38:57 +00:00
|
|
|
## Known Issues
|
2022-03-07 21:45:54 +00:00
|
|
|
|
2022-03-08 23:38:57 +00:00
|
|
|
- Only checks authenticated registries for new versions. But if you are using
|
|
|
|
this you probably aren't using DockerHub anyway.
|
|
|
|
|
|
|
|
## FAQ
|
|
|
|
|
|
|
|
- **How does Fresh remember the last seen hash?** The container hashes are stored
|
|
|
|
in the same directory as the `docker-compose.yml` file in a file named `fresh.yml`.
|
|
|
|
Remove this file to force trigger an update.
|
2022-03-10 01:32:47 +00:00
|
|
|
- **What are these hashes?** Fresh grabs the manifest for the image from the registry
|
|
|
|
and proceeds to hash a concatenation of all the various build layer hashes. This
|
|
|
|
should mean if the image is new but the layers are the same nothing will be updated.
|
2022-03-20 00:02:19 +00:00
|
|
|
- **How do I notify a Mattermost webhook?** Mattermost webhooks are compatible with
|
2022-03-19 22:22:08 +00:00
|
|
|
Slack webhooks, so simply use the `--slack` flag.
|
2022-03-08 23:38:57 +00:00
|
|
|
|
2022-03-20 00:02:19 +00:00
|
|
|
## Thank you?
|
|
|
|
|
2022-03-20 23:48:19 +00:00
|
|
|
You can show your appreciation by sending me a donation via Paypal.me:
|
|
|
|
[https://paypal.me/noccy](paypal.me/noccy).
|
|
|
|
|