Skip to content
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

Add Watchtower option for updating containers selectively #548

Open
HitLuca opened this issue Jul 22, 2022 · 2 comments
Open

Add Watchtower option for updating containers selectively #548

HitLuca opened this issue Jul 22, 2022 · 2 comments

Comments

@HitLuca
Copy link
Contributor

HitLuca commented Jul 22, 2022

I had some issues in the past when watchtower was enabled and started updating specific containers, which broke functionality. To me allowing the user to specify selected containers for updating (as well as updating everything as it is now) would be a nice addition, and I implemented it on my own ansible-nas fork.

What you basically need to do is:
add a variable in watchtower like watchtower_label_enable (false by default), which would be a boolean and would enable updating only selected containers. Now the watchtower task becomes

- name: Watchtower Docker Container
  docker_container:
    name: watchtower
    ...
    env:
      ...
      WATCHTOWER_LABEL_ENABLE: "{{ watchtower_label_enable | ternary('1', '0') }}" #<- important, as watchtower expects 1 or 0, not true/false
    ...

Now every application needs a new variable, which I called *_watchtower_update_enabled which is also a boolean and set to false by default. Each app receives a new docker label in the form of

com.centurylinklabs.watchtower.enable: "{{ (watchtower_enabled and watchtower_label_enable) | ternary(*_watchtower_update_enabled, omit) | string }}"

The reasoning is the following:

  • watchtower_enabled: false: no containers are updated as usual
  • watchtower_enabled: true and watchtower_label_enable: false: all containers are updated, regardless of individual preferences
  • watchtower_enabled: true and watchtower_label_enable: true: a label is added for watchtower to monitor only if *_watchtower_update_enabled: true, otherwise the label is not added and the container doesn't get updated.

The setup has been tested on my two ansible-nas machines and works as expected.

Side note: you need to add recreate: true to each application task if not there already, as labels don't get updated without a container being recreated

@HitLuca
Copy link
Contributor Author

HitLuca commented Jul 22, 2022

Let me know if it would be interesting and I can make a PR for it

@anarion80
Copy link
Contributor

I agree with this approach and would like to see this added one way or another. On my Ansible-nas machine I have added a label per container:
com.centurylinklabs.watchtower.enable: "{{ vaultwarden_watchtower_enable }}"
to decide if I want this particular container getting updated or not. I works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants