Permalink
Browse files

Adds config tasks

  • Loading branch information...
jeroenj committed Apr 26, 2012
1 parent 6f748ce commit 8cb1c6dae0cfd65ad7d6e76072eae5f1f21612c9
Showing with 50 additions and 0 deletions.
  1. +21 −0 README.md
  2. +29 −0 lib/openminds_deploy/configs.rb
View
@@ -103,3 +103,24 @@ avoid that:
### openminds_deploy/rails3
* sets up bundling tasks with Bundler and does a basic check to see if the server you're on supports Rails 3.
* only precompiles assets if there are changes detected in your assets or Gemfile
+
+### openminds_deploy/configs
+* gives you some tasks to copy and symlink config files to the server
+
+#### Example ####
+To set up [Faye](http://faye.jcoglan.com/) you might have different configs for each environment (development, staging, production, ...). For doing so you might create the following config in `config/faye.yml`
+
+ development:
+ server_url: https://example.dev:9292/faye
+
+ staging:
+ server_url: https://staging.example.com:9292/faye
+
+ production:
+ server_url: https://example.com:9292/faye
+
+Once you have that set up, you'll want to create the config during the first deploy and symlink the configs after each deploy. To set that up you'll have to set the `configs` variable in your `Capfile`:
+
+ set :configs, %w[faye]
+
+Don't forget to require `openminds_deploy/configs` **after** setting the variable. That's it, now your configs will be copied and symlinked automatically.
@@ -0,0 +1,29 @@
+configuration = Capistrano::Configuration.respond_to?(:instance) ? Capistrano::Configuration.instance(:must_exist) : Capistrano.configuration(:must_exist)
+
+configuration.load do
+ unless exists?(:configs)
+ set :configs, [:database]
+ end
+
+ configs.each do |name|
+ namespace :configs do
+ namespace name do
+ desc "Create #{name}.yml in shared/config"
+ task :copy do
+ run "mkdir -p #{shared_path}/config"
+
+ CONFIG = YAML.load_file(%Q{./config/#{name}.yml})[stage.to_s]
+ put CONFIG.map{|key, value| "#{key}: #{value}\n"}.join, "#{shared_path}/config/#{name}.yml"
+ end
+
+ desc "Link the #{name}.yml"
+ task :link do
+ run "ln -nfs #{shared_path}/config/#{name}.yml #{release_path}/config/#{name}.yml"
+ end
+ end
+
+ after 'deploy:setup', "configs:#{name}:copy"
+ after 'deploy:finalize_update', "configs:#{name}:link"
+ end
+ end
+end

0 comments on commit 8cb1c6d

Please sign in to comment.