Sha256: 9ced5da75d1c49605c9b9a4bcfedbb124d8e7b7c548c9130d5fbc6200187879c

Contents?: true

Size: 1009 Bytes

Versions: 2

Compression:

Stored size: 1009 Bytes

Contents

require "yaml"

module Yads
  class Deployer

    def initialize(logger = STDOUT)
      @logger = logger
    end

    def setup
      command = "mkdir -p #{config["path"]} && cd #{config["path"]} && git clone --depth 1 #{config['repository']} ."
      @logger.puts("> #{command}")
      @logger.puts(connection.execute(command))
    end

    def deploy
      commands = config["commands"].values
      commands.unshift("cd #{config["path"]}")
      commands = commands.join(" && ")

      @logger.puts("> #{commands}")
      connection.execute(commands) do |output|
        @logger.print(output)
      end
    end

    private

      def config
        @config ||= begin
          YAML.load(File.open("config/deploy.yml"))
        rescue Errno::ENOENT
          raise Yads::ConfigNotFound, "config/deploy.yml not found"
        end
      end

      def connection
        @connection ||= SSH.new(:host => config["host"], :user => config["user"], :forward_agent => config["forward_agent"])
      end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
yads-0.1.1 lib/yads/deployer.rb
yads-0.1.0 lib/yads/deployer.rb