Sha256: 8725f69cafc8fb382043cd48cdc9b4803dfbd494225571582d0f524ac089d387

Contents?: true

Size: 1.21 KB

Versions: 25

Compression:

Stored size: 1.21 KB

Contents

module Shuttle
  class Session
    attr_reader :config, :target

    # Initialize a new session
    # @param [Hashr] deploy config
    # @param [String] deploy target
    def initialize(config, target)
      @config = config
      @target = target
    end

    def validate
      if config.app.strategy.nil?
        raise ConfigError, "Deployment strategy is required"
      end

      if config.targets[target].nil?
        raise ConfigError, "Target does not exist"
      end
    end

    def run(command)
      strategy = config.app.strategy
      server = config.targets[target]

      ssh = Net::SSH::Session.new(server.host, server.user, server.password)
      ssh.open

      klass = Shuttle.const_get(strategy.capitalize)
      integration = klass.new(config, ssh, server, target)

      if integration.deploy_running?
        raise DeployError, "Another deployment is running"
      end

      begin
        integration.write_lock
        integration.send(command.to_sym)
        integration.write_revision
      rescue DeployError => err
        integration.cleanup_release
      rescue Exception => err
        integration.cleanup_release
      ensure
        integration.release_lock
      end

      ssh.close
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
shuttle-deploy-0.4.0 lib/shuttle/session.rb
shuttle-deploy-0.3.3 lib/shuttle/session.rb
shuttle-deploy-0.3.2 lib/shuttle/session.rb
shuttle-deploy-0.3.1 lib/shuttle/session.rb
shuttle-deploy-0.3.0 lib/shuttle/session.rb
shuttle-deploy-0.3.0.beta1 lib/shuttle/session.rb
shuttle-deploy-0.2.3 lib/shuttle/session.rb
shuttle-deploy-0.2.2 lib/shuttle/session.rb
shuttle-deploy-0.2.1 lib/shuttle/session.rb
shuttle-deploy-0.2.0 lib/shuttle/session.rb
shuttle-deploy-0.2.0.beta16 lib/shuttle/session.rb
shuttle-deploy-0.2.0.beta15 lib/shuttle/session.rb
shuttle-deploy-0.2.0.beta14 lib/shuttle/session.rb
shuttle-deploy-0.2.0.beta13 lib/shuttle/session.rb
shuttle-deploy-0.2.0.beta12 lib/shuttle/session.rb
shuttle-deploy-0.2.0.beta11 lib/shuttle/session.rb
shuttle-deploy-0.2.0.beta10 lib/shuttle/session.rb
shuttle-deploy-0.2.0.beta9 lib/shuttle/session.rb
shuttle-deploy-0.2.0.beta7 lib/shuttle/session.rb
shuttle-deploy-0.2.0.beta6 lib/shuttle/session.rb