Added mapping auto_update to set the label for watchtower or pyouroboros or whatever.

This commit is contained in:
Fabian Schlenz 2020-09-04 06:17:46 +02:00
parent 1eb3a8ded7
commit 18eb80ebf6

26
dup.rb
View File

@ -31,7 +31,7 @@ MAPPINGS = [
['working_dir', '--workdir', lambda{|c,i| (wd=c.Config.WorkingDir) == i.Config.WorkingDir ? nil : wd}], ['working_dir', '--workdir', lambda{|c,i| (wd=c.Config.WorkingDir) == i.Config.WorkingDir ? nil : wd}],
['init', '--init', lambda{|c,i| c.Config.Init}, {:type=>:switch}], ['init', '--init', lambda{|c,i| c.Config.Init}, {:type=>:switch}],
['image', nil, lambda{|c,i| c.Config.Image}], ['image', nil, lambda{|c,i| c.Config.Image}],
['command', nil, lambda{|c,i| (cmd=c.Config.Cmd.join(" ") rescue nil) == (i.Config.Cmd.join(" ") rescue nil)? nil : cmd}, {:escape=>false}] ['auto_update', nil, nil, {type: :hidden}]
] ]
@ -225,22 +225,30 @@ class Container
def filename; "%s/%s.yml" % [$base_dir, @name]; end def filename; "%s/%s.yml" % [$base_dir, @name]; end
def add_label(key, value)
if @data["labels"].is_a? Array
@data["labels"] << "#{key}=#{value}"
elsif @data["labels"].is_a? Hash
@data["labels"][key] = value
else
raise "data['labels'] is of an unexpected type: #{@data["labels"].class}"
end
end
def build_run_command def build_run_command
$net_host = true if @data["net"]=="host" $net_host = true if @data["net"]=="host"
cmd = ["docker", "create"] cmd = ["docker", "create"]
cmd << "--net" << @data["networks"][0] if @data["networks"] && @data["networks"].count>0 && !$net_host cmd << "--net" << @data["networks"][0] if @data["networks"] && @data["networks"].count>0 && !$net_host
cmd << "--net" << "host" if $net_host cmd << "--net" << "host" if $net_host
@data["labels"] ||= []
if !@data["test"] if !@data["test"]
if @data["labels"]==nil add_label("de.fabianonline.dup", "true")
@data["labels"] = ["de.fabianonline.dup=true"]
elsif @data["labels"].is_a? Array
@data["labels"] << "de.fabianonline.dup=true"
elsif @data["labels"].is_a? Hash
@data["labels"]["de.fabianonline.dup"] = "true"
else
raise "data['labels'] is of an unexpected type: #{@data["labels"].class}"
end end
if @data["auto_update"]
add_label("com.centurylinklabs.watchtower.enable", "true")
end end
MAPPINGS.each do |mapping| MAPPINGS.each do |mapping|