<?xml version="1.0" encoding="utf-8" standalone="yes"?><?xml-stylesheet href="/rss.xsl" type="text/xsl" ?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Diun | Bacardi55&#39;s Web Cave</title>
    <link>https://bacardi55.io/tags/diun/</link>
    <description>Recent content in Diun on Bacardi55&#39;s Web Cave</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <managingEditor>bac@rdi55.pl (bacardi55)</managingEditor>
    <webMaster>bac@rdi55.pl (bacardi55)</webMaster>
    <copyright>2010-2025 bacardi55</copyright>
    <lastBuildDate>Tue, 05 May 2020 00:00:00 +0200</lastBuildDate>
    <atom:link href="https://bacardi55.io/tags/diun/index.xml" rel="self" type="application/rss+xml" />
    <item>
      
      <title>Receive alerts when new images are available for your docker swarm cluster with Diun</title><link>https://bacardi55.io/2020/05/05/receive-alerts-when-new-images-are-available-for-your-docker-swarm-cluster-with-diun/</link><pubDate>Tue, 05 May 2020 00:00:00 +0200</pubDate><author>bac@rdi55.pl (bacardi55)</author><guid>https://bacardi55.io/2020/05/05/receive-alerts-when-new-images-are-available-for-your-docker-swarm-cluster-with-diun/</guid><description>&lt;h2 id=&#34;context&#34;&gt;Context&lt;/h2&gt;&#xA;&lt;p&gt;Today, a quick post about &lt;a href=&#34;https://github.com/crazy-max/diun&#34;&gt;Diun&lt;/a&gt;, a&#xA;nice tool that alerts you when new docker images are available for your&#xA;services. It works with docker hub (obviously) but also with alternate /&#xA;private docker registry (eg: if you have automation for building&#xA;images).&lt;/p&gt;&#xA;&lt;p&gt;I&amp;rsquo;m in a middle of a bigger article about keeping your cluster up to&#xA;date that will talk about my usage of&#xA;&lt;a href=&#34;https://github.com/crazy-max/diun&#34;&gt;Diun&lt;/a&gt;, but I thought I would first&#xA;write about the installation and usage before going into the bigger&#xA;picture of having an up to date cluster.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Nota&lt;/strong&gt;: I know there are great tools like&#xA;&lt;a href=&#34;https://containrrr.github.io/watchtower/&#34;&gt;WatchTower&lt;/a&gt; that will not&#xA;only check for new version of containers&amp;rsquo; images but also update them&#xA;automatically. But I don&amp;rsquo;t like this solution as I prefer choosing&#xA;myself when and how to upgrade (and what to backup first :)). That also&#xA;allows me to potentially test on another environment first before&#xA;running it on my production.&lt;/p&gt;&#xA;&lt;h2 id=&#34;diun&#34;&gt;Diun&lt;/h2&gt;&#xA;&lt;p&gt;As stated above, Diun is a simple yet powerful tool that will check&#xA;every defined period (configurable) if new versions of the images you&#xA;are using exist and then alert you in a lot of possible way.&lt;/p&gt;&#xA;&lt;h3 id=&#34;docker-swarm-service&#34;&gt;Docker swarm service&lt;/h3&gt;&#xA;&lt;p&gt;Diun can work in a docker container too and is compatible with bare&#xA;docker or docker swarm :-). So as usual, we&amp;rsquo;re going to create a docker&#xA;swarm service for it. First, create the directory structure. If you&#xA;follow mine&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    mkdir /mnt/cluster-data/&lt;span style=&#34;color:#f92672&#34;&gt;{&lt;/span&gt;services-config,containers-data&lt;span style=&#34;color:#f92672&#34;&gt;}&lt;/span&gt;/diun/&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    mkdir /mnt/cluster-data/containers-data/diun/data&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then, create the service definition file&#xA;&lt;code&gt;/mnt/cluster-data/services-config/diun/docker-compose.yml&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    version: &amp;#34;3.2&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    services:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      diun:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        image: crazymax/diun:latest&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        volumes:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          - &amp;#34;/mnt/cluster-data/containers-data/diun/data:/data&amp;#34; # Adapt if needed.&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          - &amp;#34;/mnt/cluster-data/containers-data/diun/diun.yml:/diun.yml:ro&amp;#34; # Read Only on config file.&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          - &amp;#34;/var/run/docker.sock:/var/run/docker.sock&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        environment:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          - &amp;#34;TZ=Europe/Paris&amp;#34; # Adapt.&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          - &amp;#34;LOG_LEVEL=info&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          - &amp;#34;LOG_JSON=false&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        deploy:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          placement:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            constraints:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              - node.role == manager&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;em&gt;Nota&lt;/em&gt;: Usual warning: When using containers, you should either build&#xA;your own or at least have a very good understanding of how the public&#xA;image you use is built and what it does before using it. Using unknown&#xA;containers on your platform is a security risk!&lt;/p&gt;&#xA;&lt;h3 id=&#34;configuration&#34;&gt;Configuration&lt;/h3&gt;&#xA;&lt;p&gt;Before actually running the service, we need to create the configuration&#xA;file. If you didn&amp;rsquo;t change the above &lt;code&gt;docker-compose.yml&lt;/code&gt;, create the&#xA;file &lt;code&gt;/mnt/cluster-data/containers-data/diun/diun.yml&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    db:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      path: diun.db&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    watch:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      workers: 4&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      schedule: &amp;#34;0 * * * *&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      first_check_notif: true&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    notif:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    #  mail:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    #    enable: false&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    #    host: localhost&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    #    port: 25&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    #    ssl: false&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    #    insecure_skip_verify: false&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    #    username:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    #    password:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    #    from:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    #    to:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      webhook:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        enable: true&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        endpoint: http://&amp;lt;IPNodeRed&amp;gt;:&amp;lt;PortNodered&amp;gt;/api/cluster/update&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        method: GET&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        headers:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          Content-Type: application/json&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        timeout: 10&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    providers:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      swarm:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        # Watch all services on local Swarm cluster&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        swarm55:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          watch_by_default: true&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;a href=&#34;https://github.com/crazy-max/diun/blob/master/doc/configuration.md&#34;&gt;Look&#xA;at the documentation&lt;/a&gt; for additional details, but in a nutshell:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;code&gt;db&lt;/code&gt;: indicate the path to diun.db (in the end will be in the data&#xA;containers we created above)&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;watch&lt;/code&gt;: define how many workers can run at the same time (here 4) and&#xA;when to run the checks. It is a&#xA;&lt;a href=&#34;https://godoc.org/github.com/robfig/cron#hdr-CRON_Expression_Format&#34;&gt;cron&#xA;expression&lt;/a&gt; so should be easy to understand :). In this example, it&#xA;runs every hours.&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;notif&lt;/code&gt;: Tell diun how to tell you a new image is ready. The simplest&#xA;way is to use emails or telegram, that&amp;rsquo;s why I left the email config&#xA;part here. I use the webhook system only, as part of my&#xA;&lt;a href=&#34;https://bacardi55.io/pages/home-lab/&#34;&gt;home automation&lt;/a&gt; so that diun send an alert to&#xA;&lt;a href=&#34;https://nodered.org/&#34;&gt;NodeRed&lt;/a&gt; that will then include that in my&#xA;more global flow of releases check, but more on that in the next post&#xA;:).&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;providers&lt;/code&gt;: This is where you tell diun to listen to the swarm&#xA;cluster and look at all images updates (&lt;code&gt;watch_by_default: true&lt;/code&gt;). If&#xA;you want to explicitly tell diun which images to check, set the&#xA;watch_by_default to false and then use labels in service definition&#xA;(docker-compose.yml) as described&#xA;&lt;a href=&#34;https://github.com/crazy-max/diun/blob/master/doc/providers/docker.md#configuration&#34;&gt;here&lt;/a&gt;.&#xA;I&amp;rsquo;m lazy so I just check everything.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Again, I strongly recommend to look at the&#xA;&lt;a href=&#34;https://github.com/crazy-max/diun/blob/master/doc/configuration.md&#34;&gt;configuration&#xA;documentation&lt;/a&gt; for additional details, as all options are explained&#xA;explicitly :).&lt;/p&gt;&#xA;&lt;h3 id=&#34;start-the-service&#34;&gt;Start the service&lt;/h3&gt;&#xA;&lt;p&gt;As usual, quite simple:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    docker stack deploy diun -c /mnt/cluster-data/services-config/diun/docker-compose.yml&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If you kept the &lt;code&gt;first_check_notif: true&lt;/code&gt;, you should receive&#xA;notification if any services is not using the latest images available.&#xA;If you didn&amp;rsquo;t get any alert, check the logs, maybe everything is up to&#xA;date:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    docker service logs -f diun_diun &lt;span style=&#34;color:#75715e&#34;&gt;# Adapt service name if needed.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;And to stop the service:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    docker stack rm diun&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h2&gt;&#xA;&lt;p&gt;That&amp;rsquo;s it for now, we&amp;rsquo;ll see in the next post how I use Diun and other&#xA;tools to stay alerted of new version of the software I use.&lt;/p&gt;&#xA;&lt;p&gt;You can follow all posts about my Home Lab on the&#xA;&lt;a href=&#34;https://bacardi55.io/pages/home-lab/&#34;&gt;dedicated page&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;div class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;&#xA;&lt;hr&gt;&#xA;&lt;ol&gt;&#xA;&lt;li id=&#34;fn:1&#34;&gt;&#xA;&lt;p&gt;See &lt;a href=&#34;https://bacardi55.io/posts/2020/03/27/my-home-lab-2020-part-3-docker-swarm-setup/&#34;&gt;this post&lt;/a&gt;.&amp;#160;&lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/div&gt;&#xA;</description></item>
  </channel>
</rss>
