Sha256: cfc41375d0eb7d150e1e2a45c17bdc7f6916b8e58ee0e1d7610c6c31559ee6ac

Contents?: true

Size: 1.42 KB

Versions: 2

Compression:

Stored size: 1.42 KB

Contents

module Conan
  class Deployment
    module Helpers
      def with_user(new_user, &blk)
        old_user = user
        return if old_user == new_user
        set :user, new_user
        close_sessions
        yield
        set :user, old_user
        close_sessions
      end

      def close_sessions
        sessions.values.each { |session| session.close }
        sessions.clear
      end

      def git_tag(source, dest)
        system "git fetch origin --tags"
        sha1 = `git rev-parse "#{source}"`
        system %{git update-ref "refs/tags/#{dest}" #{sha1}}
        system %{git push -f origin tag #{dest}}
      end

      def add_role(*roles)
        roles = Hash.new{ |h,k| h[k] = [] }

        server_config.each do |s, c|
          c["roles"].each do |r|
            roles[r.to_sym] << s
          end
        end

        roles.each do |r, ss|
          next unless roles.include?(r)
          ss.each_with_index do |s, i|
            role r, s, :primary => (i == 0)
          end
        end
      end
    end

    class <<self
      def define_tasks(context)
        load_script(context, "deploy")
        load_script(context, "chef")
        load_script(context, "git")
      end

      def load_script(context, fragment)
        path = File.expand_path("../deployment/#{fragment}.rb", __FILE__)
        code = File.read(path)
        context.instance_eval(code, path)
      end
    end
  end
end

include Conan::Deployment::Helpers

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
conan-0.2.1 lib/conan/deployment.rb
conan-0.2.0 lib/conan/deployment.rb