Skip to content

Commit

Permalink
Create a podman secret when starting systemd unit
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Mar 20, 2024
1 parent e5b0a0d commit 5dd21af
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/models/opentofu_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ def container_image
ENV["OPENTOFU_RUNNER_IMAGE"] || default_image
end

def enable_systemd_unit
super
create_podman_secret
end

def unit_config_file
# Override this in a sub-class if the specific instance needs
# any additional config
Expand All @@ -55,4 +60,13 @@ def unit_environment_variables
"MEMCACHED_SERVER=#{::Settings.session.memcache_server}"
]
end

def create_podman_secret
return if AwesomeSpawn.run("podman", :params => %w[secret exists opentofu-runner-secret]).success?

database_password = ActiveRecord::Base.connection_db_config.configuration_hash[:password]
secret = {"DATABASE_PASSWORD" => database_password}

AwesomeSpawn.run!("podman", :params => %w[secret create opentofu-runner-secret -], :in_data => secret.to_json)
end
end

0 comments on commit 5dd21af

Please sign in to comment.