Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Commit

Permalink
Write pem file every time regardless of if berks config has been gene…
Browse files Browse the repository at this point in the history
…rated in berks:setup task
  • Loading branch information
pturley committed Jul 23, 2018
1 parent 3b9d976 commit 0448205
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions lib/cookbook_release/tasks/berkshelf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,17 @@ def setup
desc "Setup berkshelf using env variables"
task "setup" do
berkshelf_config = ENV["BERKSHELF_CONFIG"] || File.join(ENV["HOME"], ".berkshelf", "config.json")
if File.exist?(berkshelf_config)
puts "Berkshelf config file already exists"
next
end

sh "mkdir -p #{File.dirname(berkshelf_config)}"

chef_server = ENV["CHEF_SERVER"] || "https://chef.tablexi.com/organizations/tablexi"
node_name = ENV["NODE_NAME"] || "ci"
client_key = ENV["CLIENT_KEY"] || "/ci.pem"
pem_contents = ENV["CHEF_CLIENT_PEM"]

unless File.exist?(client_key)
# On CI, also convert ENV variable to pem file
if ENV["CHEF_CLIENT_PEM"]
if pem_contents
sh "mkdir -p #{File.dirname(client_key)}"
# Make sure EOL isn't getting escaped
File.write(File.expand_path(client_key), ENV["CHEF_CLIENT_PEM"].gsub('\n',"\n"))
File.write(File.expand_path(client_key), pem_contents.gsub('\n',"\n"))
else
raise "Chef client key missing #{client_key}"
end
Expand All @@ -56,9 +50,13 @@ def setup
},
}

require "json"

File.write(File.expand_path(berkshelf_config), config.to_json)
if File.exist?(berkshelf_config)
puts "Berkshelf config file already exists"
else
sh "mkdir -p #{File.dirname(berkshelf_config)}"
require "json"
File.write(File.expand_path(berkshelf_config), config.to_json)
end
end
end

Expand Down

0 comments on commit 0448205

Please # to comment.