-
Notifications
You must be signed in to change notification settings - Fork 883
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow running periodic updates with enabled HTTP API #916
Allow running periodic updates with enabled HTTP API #916
Conversation
Codecov Report
@@ Coverage Diff @@
## main #916 +/- ##
===========================================
+ Coverage 40.14% 53.73% +13.59%
===========================================
Files 25 25
Lines 1415 1407 -8
===========================================
+ Hits 568 756 +188
+ Misses 785 585 -200
- Partials 62 66 +4
Continue to review full report at Codecov.
|
69ee23e
to
d089a08
Compare
I just noticed that the locks are all local and not shared between HTTP API and the scheduler, so I'll take a stab at trying to create a global lock we can pass to both to avoid running scheduled and API-triggered polls at the same time. Also looking at the logs of the |
Yeah. This is fixed in |
ff81a7e
to
dda9eeb
Compare
Just a thought, wouldn't manually specifying a schedule or interval warrant the enabling of the periodic updates as well? It should probably also write a startup message when running in "manual" mode, with |
Your thought is definitely valid and warranted. I'll go ahead and fork it off into a separate issue though. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree that this should have tests, but lets get this into the code base. @DasSkelett, if you've got time to add some tests, that would be greatly appreciated, but we can keep that as a separate PR in that case.
Thank you for your great contribution! 🎉
@all-contributors add @DasSkelett for code |
I've put up a pull request to add @DasSkelett! 🎉 |
Testing But I could copy the relevant parts from |
Edit by @simskij: closes #897
Motivation
I'd like to run Watchtower both with infrequent periodic updates for images I don't build myself, and have the option to quickly redeploy custom images when they're rebuilt using the HTTP API.
Currently this is not possible, because enabling the HTTP Update API disables scheduled runs.
In theory this would also be possible using multiple Watchtower instances with two scopes, one for "public" images and one for self-built images; however now you need to deal with labels and make sure every container has the correct scope label, which adds unwanted complexity to the setup.
Alternatively you could set up a Cron job to curl
/v1/update
periodically, but this also gets ugly fast given that we're in Docker, and it also splits the "configuration" of Watchtower into two locations. Also the primary purpose for Watchtower is to replace hacky cron jobs to update Docker containers.Instead, it would be very handy if Watchtower allows running periodic updates and the HTTP API for updates at the same time.
Changes
Add a new
--http-api-periodic-polls
option with theWATCHTOWER_HTTP_API_PERIODIC_POLLS
environment variable, defaulting to false.It has only an effect if the HTTP API mode (
--http-api-update
) is enabled.If
--http-api-periodic-polls
is passed, the HTTP API doesn't block, and thus allows periodic polls as well (with whatever--interval
or--schedule
is given, defaulting to every 24 hours).I'm open for suggestions to rename this option if you've got something better in mind. I'm not entirely happy with the word "periodic" since it isn't used anywhere else so far. I've considered "scheduled", but it might mislead to think it only affects the
--schedule
option and not--interval
.The HTTP API and
runUpgradesOnSchedule()
had separate locks to prevent multiple updates running at the same time.Since there's the possibility that the schedule triggers while an HTTP API poll is running, or the other way around, I needed to add a global lock. The channel is passed to
runUpgradesOnSchedule()
andapi.update.New()
, which now use this channel for locking instead of making their own.Both functions still create a new channel if the argument is
nil
, which might simplify future unit testing or other changes.I've also extended the docs accordingly. If I should clarify or reword something, please do tell.
Further considerations
I also thought about enabling this behaviour by default (inverting the option and renaming it to
--http-api-only
), since this might be what most people expect, but this could be a "breaking" change, since it differs from the current behaviour.But if you say it's worth it, I would be happy to do that.