Class: Dply::Release

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/dply/release.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helper

#cmd, #error, #git, #logger, #sh, #symlink

Constructor Details

#initialize(revision:, app_name:, branch:, url:) ⇒ Release

Returns a new instance of Release.



30
31
32
33
34
35
# File 'lib/dply/release.rb', line 30

def initialize(revision:, app_name:, branch:, url:)
  @revision = revision
  @branch = branch.to_s.tr('-/', '__')
  @app_name = app_name.to_s.tr('-/', '__')
  @url = url
end

Instance Attribute Details

#nameObject



43
44
45
# File 'lib/dply/release.rb', line 43

def name
  @name ||= "#{@revision}-#{@app_name}-#{@branch}-#{timestamp}"
end

#urlObject

Returns the value of attribute url.



10
11
12
# File 'lib/dply/release.rb', line 10

def url
  @url
end

#verify_checksumObject

Returns the value of attribute verify_checksum.



10
11
12
# File 'lib/dply/release.rb', line 10

def verify_checksum
  @verify_checksum
end

Class Method Details

.find_installed_name(**kwargs) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/dply/release.rb', line 20

def self.find_installed_name(**kwargs)
  branch = kwargs.fetch(:branch).to_s.tr('-/', '__')
  app_name = kwargs.fetch(:app_name).to_s.tr('-/', '__')
  revision = kwargs.fetch(:revision)

  name_without_ts = "#{revision}-#{app_name}-#{branch}-"
  latest = Dir["releases/#{name_without_ts}*"].sort_by { |x, y| File.mtime(x) }.first
  latest ? File.basename(latest) : nil
end

.find_or_create(**kwargs) ⇒ Object



13
14
15
16
17
18
# File 'lib/dply/release.rb', line 13

def self.find_or_create(**kwargs)
  release = new(**kwargs)
  name = find_installed_name(**kwargs)
  release.name = name if name
  return release
end

Instance Method Details

#already_deployed?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/dply/release.rb', line 65

def already_deployed?
  File.exist? "#{path}/.deployed"
end

#current?Boolean

Returns:

  • (Boolean)


69
70
71
72
# File 'lib/dply/release.rb', line 69

def current?
  return false if not File.symlink? "current"
  File.basename(File.readlink "current") == name
end

#installObject



47
48
49
50
51
52
53
54
55
# File 'lib/dply/release.rb', line 47

def install
  if installed?
    logger.debug "release #{name} already installed"
    return
  end
  archive.extract do |path|
    FileUtils.mv path, "releases/#{name}"
  end
end

#make_currentObject



37
38
39
40
41
# File 'lib/dply/release.rb', line 37

def make_current
  error "cannot make not installed release current" if not installed?
  error "release path #{path} doesn't exist"  if not File.directory? path
  symlink path, "current"
end

#pathObject



57
58
59
# File 'lib/dply/release.rb', line 57

def path
  @path ||= "releases/#{name}"
end

#record_deploymentObject



61
62
63
# File 'lib/dply/release.rb', line 61

def record_deployment
  FileUtils.touch "#{path}/.deployed"
end