containrrr / watchtower

A process for automating Docker container base image updates.
https://containrrr.dev/watchtower/
Apache License 2.0
19.71k stars 869 forks source link

Schedule issue #2036

Open jmaffie opened 1 month ago

jmaffie commented 1 month ago

Describe the bug

WATCHTOWER_SCHEDULE 0 0 20 1-7 * FRI is interpreted as 20:00 every friday and every 1-7th of the month. I believe this expression should be interpreted as 20:00 the first friday of the month.

Steps to reproduce

set the env variable WATCHTOWER_SCHEDULE to "0 0 20 1-7 * FRI"

Expected behavior

run at 20:00 the first friday of the month

Screenshots

No response

Environment

up to date docker and container as of this date. running on Ubuntu LTS 20.04

Your logs

INFO[0001] Watchtower 1.7.1                             

INFO[0001] Using no notifications                       

INFO[0001] Checking all containers (except explicitly disabled with label) 

INFO[0001] Scheduling first run: 2024-10-11 20:00:00 -0400 EDT 

INFO[0001] Note that the first check will be performed in 142 hours, 47 minutes, 18 seconds

Additional context

No response

github-actions[bot] commented 1 month ago

Hi there! 👋🏼 As you're new to this repo, we'd like to suggest that you read our code of conduct as well as our contribution guidelines. Thanks a bunch for opening your first issue! 🙏

reynaldichernando commented 1 month ago

I can confirm that the above cron expression 0 0 20 1-7 * FRI runs every Friday, not only on the first Friday of the month. Looking at the crontab, the next schedules will happen on every other Fridays.

image

However, I think this is more about the cron expression rather than a bug in watchtower. This cron expression 0 0 20 */100,1-7 * FRI will achieve the first Friday of the month schedule (crontab).

image

Reference for why the second cron expression works: https://blog.healthchecks.io/2022/09/schedule-cron-job-the-funky-way/

reynaldichernando commented 1 month ago

Testing it out on watchtower

docker run \        
    --name watchtower \
    --volume /var/run/docker.sock:/var/run/docker.sock \
    containrrr/watchtower \
    --schedule "0 0 20 */100,1-7 * FRI"

Output

time="2024-10-14T17:19:36Z" level=info msg="Watchtower 1.7.1"
time="2024-10-14T17:19:36Z" level=info msg="Using no notifications"
time="2024-10-14T17:19:36Z" level=info msg="Checking all containers (except explicitly disabled with label)"
time="2024-10-14T17:19:36Z" level=info msg="Scheduling first run: 2024-11-01 20:00:00 +0000 UTC"
time="2024-10-14T17:19:36Z" level=info msg="Note that the first check will be performed in 434 hours, 40 minutes, 23 seconds"