From 1ab88105d7947ab18edf5e9795c2cacb27f479f3 Mon Sep 17 00:00:00 2001 From: Grant Slater Date: Wed, 20 Dec 2023 01:22:41 +0000 Subject: [PATCH] podman: add environment variable support --- cookbooks/podman/resources/service.rb | 9 ++++++++- cookbooks/podman/resources/site.rb | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/cookbooks/podman/resources/service.rb b/cookbooks/podman/resources/service.rb index b48e04ce1..d2ee90705 100644 --- a/cookbooks/podman/resources/service.rb +++ b/cookbooks/podman/resources/service.rb @@ -25,6 +25,7 @@ property :service, String, :name_property => true property :description, String, :required => true property :image, String, :required => true property :ports, Hash +property :environment, Hash, :default => {} action :create do systemd_service new_resource.service do @@ -33,7 +34,7 @@ action :create do notify_access "all" environment "PODMAN_SYSTEMD_UNIT" => "%n" exec_start_pre "/bin/rm --force %t/%n.ctr-id" - exec_start "/usr/bin/podman run --cidfile=%t/%n.ctr-id --cgroups=no-conmon --userns=auto --label=io.containers.autoupdate=registry --network=slirp4netns:mtu=1500 #{publish_options} --rm --sdnotify=conmon --detach --replace --name=%N #{new_resource.image}" + exec_start "/usr/bin/podman run --cidfile=%t/%n.ctr-id --cgroups=no-conmon --userns=auto --label=io.containers.autoupdate=registry --network=slirp4netns:mtu=1500 #{publish_options} #{environment_options} --rm --sdnotify=conmon --detach --replace --name=%N #{new_resource.image}" exec_stop "/usr/bin/podman stop --ignore --time=10 --cidfile=%t/%n.ctr-id" exec_stop_post "/usr/bin/podman rm --force --ignore --cidfile=%t/%n.ctr-id" timeout_start_sec 180 @@ -73,4 +74,10 @@ action_class do "--publish=127.0.0.1:#{host}:#{guest}" end.join(" ") end + + def environment_options + new_resource.environment.collect do |key, value| + "-e '#{key}=#{value}'" + end.join(" ") + end end diff --git a/cookbooks/podman/resources/site.rb b/cookbooks/podman/resources/site.rb index e0b0f8ce2..7cab5a5d2 100644 --- a/cookbooks/podman/resources/site.rb +++ b/cookbooks/podman/resources/site.rb @@ -27,12 +27,14 @@ property :site, String, :name_property => true property :image, String, :required => true property :port, Integer, :default => 8080 property :aliases, :kind_of => Array, :default => [] +property :environment, Hash, :default => {} action :create do podman_service new_resource.site do description "Container service for #{new_resource.site}" image new_resource.image ports external_port => new_resource.port + environment new_resource.environment end ssl_certificate new_resource.site do -- 2.39.5