Added ofelia functionality.

This commit is contained in:
Fabian Schlenz 2021-04-20 11:57:52 +02:00
parent f7b9535089
commit 3879c20814

31
dup.rb
View File

@ -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)