Skip to content

Instantly share code, notes, and snippets.

@PaulCampbell
Created October 25, 2010 13:50
Show Gist options
  • Save PaulCampbell/644979 to your computer and use it in GitHub Desktop.
Save PaulCampbell/644979 to your computer and use it in GitHub Desktop.
Basic rake script for configuring .net projects with yaml and configatron
require 'rake'
require 'configatron'
require 'pp'
task :setEnvironmentVariables do
$env = ENV['environment']
if $env.nil?
puts "Please enter an environment to deploy this build to."
fail
elsif !File.exist?($env + ".yaml")
puts "Cannot find configuration for #{$env} environment."
puts "Try one of " + Dir.glob("*.yaml").collect {|f| f[0...f.index('.')]}.to_s
fail
else
configatron.configure_from_yaml($env + ".yaml")
puts "Releasing build to #{$env} environment."
end
end
desc 'Config CWS Web application to environment'
task :config_all_projects => :setEnvironmentVariables do
puts "Config ALL applications to environment"
Dir.glob("**/*.configatron") do |filename|
str = File.read(filename)
str = str.gsub(/#\{(configatron\..*)\}/) do |v|
c = eval($1)
#puts $1, c
if c.nil?
puts "The config parameter #{$1} in #{filename} is missing from #{$env}.yaml"
puts "Check your configuration files and re-run this task."
fail
end
c
end
# delete file?
filename["configatron"] = "config"
File.open(filename, 'w') { |f| f.write(str) }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment