Class: Shuttle::Deploy

Inherits:
Object
  • Object
show all
Includes:
Helpers, PathHelpers
Defined in:
lib/shuttle/deploy.rb

Direct Known Subclasses

Strategy

Constant Summary

Constants included from Helpers

Helpers::LEVEL_COLORS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PathHelpers

#current_path, #deploy_path, #release_path, #scm_path, #shared_path, #version_path

Methods included from Helpers

#deployer_hostname, #error, #git_installed?, #git_remote, #log, #release_exists?, #stream_output, #svn_installed?, #warn

Constructor Details

#initialize(config, ssh, target, environment) ⇒ Deploy

Returns a new instance of Deploy.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/shuttle/deploy.rb', line 12

def initialize(config, ssh, target, environment)
  @config      = config
  @target      = target
  @ssh         = ssh
  @environment = environment

  if ssh.file_exists?(version_path)
    res = ssh.capture("cat #{version_path}")
    @version = (res.empty? ? 1 : Integer(res) + 1).to_s
  else
    @version = 1
  end
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



10
11
12
# File 'lib/shuttle/deploy.rb', line 10

def config
  @config
end

#environmentObject (readonly)

Returns the value of attribute environment.



8
9
10
# File 'lib/shuttle/deploy.rb', line 8

def environment
  @environment
end

#sshObject (readonly)

Returns the value of attribute ssh.



6
7
8
# File 'lib/shuttle/deploy.rb', line 6

def ssh
  @ssh
end

#targetObject (readonly)

Returns the value of attribute target.



7
8
9
# File 'lib/shuttle/deploy.rb', line 7

def target
  @target
end

#versionObject (readonly)

Returns the value of attribute version.



9
10
11
# File 'lib/shuttle/deploy.rb', line 9

def version
  @version
end

Instance Method Details

#available_releasesArray<Integer>

Get list of all existing releases

Returns:

  • (Array<Integer>)


34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/shuttle/deploy.rb', line 34

def available_releases
  if ssh.directory_exists?(deploy_path('releases'))
    releases = ssh.capture("ls --color=never #{deploy_path}/releases")

    releases.
      scan(/[\d]+/).
      map { |s| s.strip.to_i }.
      sort
  else
    []
  end
end

#last_versionInteger

Get current deploy version

Returns:

  • (Integer)


28
29
30
# File 'lib/shuttle/deploy.rb', line 28

def last_version
  @last_version ||= ssh.read_file(version_path).to_i
end