Skip to content

Commit

Permalink
Refactor OpentofuWorker Environment Variables
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Sep 20, 2024
1 parent 5021cc4 commit ccbec98
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions app/models/opentofu_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,31 +71,33 @@ def enable_systemd_unit
create_podman_secret
end

def environment_variables
super.merge(
"LOG4JS_LEVEL" => ::Settings.log.level_embedded_terraform,
"TF_OFFLINE" => worker_settings[:opentofu_offline]
)
end

def unit_environment_variables
{
"DATABASE_HOSTNAME" => database_configuration[:host],
"DATABASE_NAME" => database_configuration[:database],
"DATABASE_USERNAME" => database_configuration[:username],
"MEMCACHE_SERVERS" => ::Settings.session.memcache_server,
"PORT" => container_port,
"OPENTOFU_RUNNER_IMAGE" => container_image,
"LOG4JS_LEVEL" => ::Settings.log.level_embedded_terraform,
"TF_OFFLINE" => worker_settings[:opentofu_offline]
"OPENTOFU_RUNNER_IMAGE" => container_image
}
end

def container_environment_variables
super.merge("HOME" => "/home/node")
end

def configure_service_worker_deployment(definition)
super
# overwriting container port to be same as opentofu-runner service port i.e. in this case 6000
definition[:spec][:template][:spec][:containers].first[:ports] = [{:containerPort => container_port}]

# ovewriting home directory to terraform home dir
env_var_array = definition[:spec][:template][:spec][:containers][0][:env]
env_var_array.detect { |env| env[:name] == "HOME" }&.[]=(:value, "/home/node")

definition[:spec][:template][:spec][:containers][0][:env] << {:name => "LOG4JS_LEVEL", :value => Settings.log.level_embedded_terraform}
definition[:spec][:template][:spec][:containers][0][:env] << {:name => "TF_OFFLINE", :value => worker_settings[:opentofu_offline].to_s}

# these volume mounts are require by terraform runner to create the stack, mentioned it as {} so that it can be writable
definition[:spec][:template][:spec][:containers].first[:volumeMounts] << {:name => "terraform-bin-empty", :mountPath => "/home/node/terraform/bin"}
definition[:spec][:template][:spec][:volumes] << {:name => "stacks-empty", :emptyDir => {}}
Expand Down

0 comments on commit ccbec98

Please sign in to comment.