Class: Luban::Deployment::Application::Repository

Inherits:
Worker::Base
  • Object
show all
Includes:
Worker::Paths::Local
Defined in:
lib/luban/deployment/cli/application/scm/git.rb,
lib/luban/deployment/cli/application/scm/rsync.rb,
lib/luban/deployment/cli/application/repository.rb

Defined Under Namespace

Modules: SCM

Constant Summary collapse

DefaultRevisionSize =
12

Constants included from Parameters::Application

Parameters::Application::DefaultLogrotateInterval, Parameters::Application::DefaultLogrotateMaxAge

Constants included from Parameters::General

Parameters::General::DefaultLubanRootPath

Constants included from Helpers::Utils

Helpers::Utils::LogLevels

Instance Attribute Summary collapse

Attributes inherited from Worker::Base

#task

Attributes included from Helpers::Utils

#backend

Attributes included from Helpers::Configuration

#config

Instance Method Summary collapse

Methods included from Worker::Paths::Local

#app_path, #apps_path, #project_path

Methods inherited from Worker::Base

#dry_run?, #force?, #initialize, #linux?, #method_missing, #osx?, #packages, #run, #target_full_name, #target_major_version, #target_name, #target_patch_level, #target_version

Methods included from Parameters::Application

#env_name, #logrotate_count, #monitor_itself?, #monitorable?

Methods included from Parameters::Base

#parameter

Methods included from Parameters::Project

#monitor_defined?, #process_monitor_via

Methods included from Parameters::General

included

Methods included from Helpers::Utils

#assure, #assure_dirs, #assure_symlink, #capture, #check_pass?, #chmod, #cp, #directory?, #exists?, #file?, #hardware_name, #host, #hostname, #ln, #match?, #md5_for, #md5_for_dir, #md5_for_file, #md5_matched?, #mkdir, #mv, #now, #os_name, #os_release, #readlink, #render_template, #revision_match?, #rm, #rmdir, #sudo, #symlink?, #touch, #truncate, #upload_by_template, #url_exists?, #user_home

Methods included from Helpers::Configuration

#ask, #fetch, #find_template_file, #load_configuration_file, #primary, #release_roles, #role, #roles, #server, #set, #set_default, #syntax_error?

Constructor Details

This class inherits a constructor from Luban::Deployment::Worker::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Luban::Deployment::Worker::Base

Instance Attribute Details

#fromObject (readonly)

Returns the value of attribute from.



11
12
13
# File 'lib/luban/deployment/cli/application/repository.rb', line 11

def from
  @from
end

#rev_sizeObject (readonly)

Returns the value of attribute rev_size.



14
15
16
# File 'lib/luban/deployment/cli/application/repository.rb', line 14

def rev_size
  @rev_size
end

#revisionObject (readonly)

Returns the value of attribute revision.



13
14
15
# File 'lib/luban/deployment/cli/application/repository.rb', line 13

def revision
  @revision
end

#scmObject (readonly)

Returns the value of attribute scm.



12
13
14
# File 'lib/luban/deployment/cli/application/repository.rb', line 12

def scm
  @scm
end

#typeObject (readonly)

Returns the value of attribute type.



10
11
12
# File 'lib/luban/deployment/cli/application/repository.rb', line 10

def type
  @type
end

#versionObject (readonly)

Returns the value of attribute version.



15
16
17
# File 'lib/luban/deployment/cli/application/repository.rb', line 15

def version
  @version
end

Instance Method Details

#buildObject



92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/luban/deployment/cli/application/repository.rb', line 92

def build
  assure_dirs(clone_path, releases_path)
  if cloned? and !force?
    update_result "Skipped! Local #{type} repository has been built ALREADY.", status: :skipped
  else
    abort "Aborted! Remote #{type} repository is NOT available." unless available?
    if build!
      update_result "Successfully built local #{type} repository."
    else
      abort "FAILED to build local #{type} repository!"
    end
  end
end

#bundle_cmdObject



66
67
68
69
70
71
72
73
# File 'lib/luban/deployment/cli/application/repository.rb', line 66

def bundle_cmd
  return @bundle_cmd unless @bundle_cmd.nil?
  @bundle_cmd = fetch(:bundle_via, :bundle).tap do |cmd|
    if cmd.is_a?(Pathname) and !file?(cmd)
      abort "Aborted! Bundler command is NOT found: #{cmd}"
    end
  end
end

#bundle_withoutObject



75
76
77
# File 'lib/luban/deployment/cli/application/repository.rb', line 75

def bundle_without
  @bundle_without ||= %w(development test)
end

#clone_pathObject



30
31
32
# File 'lib/luban/deployment/cli/application/repository.rb', line 30

def clone_path
  @clone_path ||= workspace_path.join('repositories', type)
end

#deprecateObject



137
138
139
140
141
142
143
144
145
# File 'lib/luban/deployment/cli/application/repository.rb', line 137

def deprecate
  abort "Aborted! Local #{type} repository is NOT built yet!" unless cloned?
  abort "Aborted! Version to deprecate is MISSING!" if version.nil?
  if file?(release_package_path)
    rm(release_package_path)
    update_result "Successfully deprecated packaged release #{release_name}."
  end
  update_result release_pack: { type: type, version: version, tag: release_tag }
end

#gems_pathObject



26
27
28
# File 'lib/luban/deployment/cli/application/repository.rb', line 26

def gems_path
  @gems_path ||= workspace_path.join('gems')
end

#packageObject



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/luban/deployment/cli/application/repository.rb', line 108

def package
  abort "Aborted! Local #{type} repository is NOT built yet!" unless cloned?
  abort "Aborted! FAILED to update local #{type} repository!" unless update
  update_revision
  abort "Aborted! Version to package is MISSING!" if version.nil?
  release_package = ->{ { type: type, version: version, tag: release_tag,
                          path: release_package_path, 
                          md5: md5_for_file(release_package_path),
                          bundled_gems: bundle_gems } }
  if packaged?
      if force?
        release
      else
        update_result "Skipped! ALREADY packaged #{release_name}.", status: :skipped,
                      release_pack: release_package.call
      end
  else
    release
    cleanup_releases
  end

  if packaged?
    update_result "Successfully packaged #{release_name} to #{release_package_path}."
  else
    abort "Aborted! FAILED to package #{release_name}!"
  end
  update_result release_pack: release_package.call
end

#packaged?Boolean

Returns:

  • (Boolean)


106
# File 'lib/luban/deployment/cli/application/repository.rb', line 106

def packaged?; file?(release_package_path); end

#release_nameObject



62
63
64
# File 'lib/luban/deployment/cli/application/repository.rb', line 62

def release_name
  @release_name ||= "#{application}:#{type}:#{release_tag}"
end

#release_package_extnameObject



50
51
52
# File 'lib/luban/deployment/cli/application/repository.rb', line 50

def release_package_extname
  @release_package_extname ||= 'tgz'
end

#release_package_file_nameObject



42
43
44
# File 'lib/luban/deployment/cli/application/repository.rb', line 42

def release_package_file_name
  @release_package_file_name ||= "#{release_package_name}.#{release_package_extname}"
end

#release_package_nameObject



46
47
48
# File 'lib/luban/deployment/cli/application/repository.rb', line 46

def release_package_name
  @release_package_name ||= "#{release_prefix}-#{release_tag}"
end

#release_package_pathObject



38
39
40
# File 'lib/luban/deployment/cli/application/repository.rb', line 38

def release_package_path
  @release_package_path ||= releases_path.join(release_package_file_name)
end

#release_prefixObject



54
55
56
# File 'lib/luban/deployment/cli/application/repository.rb', line 54

def release_prefix
  @release_prefix ||= "#{stage}-#{project}-#{application}-#{type}"
end

#release_tagObject



58
59
60
# File 'lib/luban/deployment/cli/application/repository.rb', line 58

def release_tag
  @release_tag ||= "#{version}-#{revision}"
end

#releases_pathObject



34
35
36
# File 'lib/luban/deployment/cli/application/repository.rb', line 34

def releases_path
  @releases_path ||= workspace_path.join('releases', type)
end

#scm_moduleObject



17
18
19
20
# File 'lib/luban/deployment/cli/application/repository.rb', line 17

def scm_module
  require_relative "scm/#{scm}"
  @scm_module ||= SCM.const_get(scm.camelcase)
end

#workspace_pathObject



22
23
24
# File 'lib/luban/deployment/cli/application/repository.rb', line 22

def workspace_path
  @workspace_path ||= app_path.join('.luban')
end