From 3879c208140982717b034abc564b17944080028e Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Tue, 20 Apr 2021 11:57:52 +0200 Subject: [PATCH] Added ofelia functionality. --- dup.rb | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/dup.rb b/dup.rb index 360cd9c..26a3eaa 100755 --- a/dup.rb +++ b/dup.rb @@ -44,7 +44,8 @@ MAPPINGS = [ ['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}], ['test', nil, nil, {type: :hidden}], - ['auto_update', nil, nil, {type: :hidden}] + ['auto_update', nil, nil, {type: :hidden}], + ['ofelia', nil, nil, {type: :hidden}] ] @@ -111,6 +112,15 @@ def get_sample(name="container") devices: - "/dev/ttyUSB0:/dev/ttyUSB0" + + ofelia: + - name: update # No spaces! + schedule: "@every 4h" # go cron format! See https://pkg.go.dev/github.com/robfig/cron?utm_source=godoc + command: uname -a + user: foo + tty: false + no-overlap: true + - name: Test 2 HEREDOC end @@ -263,6 +273,25 @@ class Container add_label("com.centurylinklabs.watchtower.enable", "true") end + if @data["ofelia"] && @data["ofelia"].count > 0 + add_label("ofelia.enabled", "true") + + @data["ofelia"].each_with_index do |job, index| + name = job["name"] || "job-#{index}" + name = name.downcase.gsub(/[^a-z0-9\-]/, "-").gsub(/-+/, "-") + schedule = job["schedule"] + next unless schedule + command = job["command"] + next unless command + add_label("ofelia.job-exec.#{name}.schedule", schedule) + add_label("ofelia.job-exec.#{name}.command", command) + add_label("ofelia.job-exec.#{name}.user", job["user"]) if job["user"] + add_label("ofelia.job-exec.#{name}.tty", job["tty"].to_s) if job["tty"]!=nil + ol = job["no-overlap"] + add_label("ofelia.job-exec.#{name}.no-overlap", ol!=nil ? ol.to_s : "true") + end + end + MAPPINGS.each do |mapping| yml_name, cmd_name, reverse_lambda, options = *mapping next if $net_host && %w(links net ports).include?(yml_name)