class Luban::Deployment::Application::Repository
Constants
- DefaultBundleJobs
- DefaultRevisionSize
Attributes
from[R]
rev_size[R]
revision[R]
scm[R]
type[R]
version[R]
Public Instance Methods
build()
click to toggle source
# File lib/luban/deployment/cli/application/repository.rb, line 97 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_cmd()
click to toggle source
# File lib/luban/deployment/cli/application/repository.rb, line 67 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_jobs()
click to toggle source
# File lib/luban/deployment/cli/application/repository.rb, line 80 def bundle_jobs @bundle_jobs ||= DefaultBundleJobs end
bundle_without()
click to toggle source
# File lib/luban/deployment/cli/application/repository.rb, line 76 def bundle_without @bundle_without ||= %w(development test) end
clone_path()
click to toggle source
# File lib/luban/deployment/cli/application/repository.rb, line 31 def clone_path @clone_path ||= workspace_path.join('repositories', type) end
deprecate()
click to toggle source
# File lib/luban/deployment/cli/application/repository.rb, line 142 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_path()
click to toggle source
# File lib/luban/deployment/cli/application/repository.rb, line 27 def gems_path @gems_path ||= workspace_path.join('gems') end
package()
click to toggle source
# File lib/luban/deployment/cli/application/repository.rb, line 113 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?()
click to toggle source
# File lib/luban/deployment/cli/application/repository.rb, line 111 def packaged?; file?(release_package_path); end
release_name()
click to toggle source
# File lib/luban/deployment/cli/application/repository.rb, line 63 def release_name @release_name ||= "#{application}:#{type}:#{release_tag}" end
release_package_extname()
click to toggle source
# File lib/luban/deployment/cli/application/repository.rb, line 51 def release_package_extname @release_package_extname ||= 'tgz' end
release_package_file_name()
click to toggle source
# File lib/luban/deployment/cli/application/repository.rb, line 43 def release_package_file_name @release_package_file_name ||= "#{release_package_name}.#{release_package_extname}" end
release_package_name()
click to toggle source
# File lib/luban/deployment/cli/application/repository.rb, line 47 def release_package_name @release_package_name ||= "#{release_prefix}-#{release_tag}" end
release_package_path()
click to toggle source
# File lib/luban/deployment/cli/application/repository.rb, line 39 def release_package_path @release_package_path ||= releases_path.join(release_package_file_name) end
release_prefix()
click to toggle source
# File lib/luban/deployment/cli/application/repository.rb, line 55 def release_prefix @release_prefix ||= "#{stage}-#{project}-#{application}-#{type}" end
release_tag()
click to toggle source
# File lib/luban/deployment/cli/application/repository.rb, line 59 def release_tag @release_tag ||= "#{version}-#{revision}" end
releases_path()
click to toggle source
# File lib/luban/deployment/cli/application/repository.rb, line 35 def releases_path @releases_path ||= workspace_path.join('releases', type) end
scm_module()
click to toggle source
# File lib/luban/deployment/cli/application/repository.rb, line 18 def scm_module require_relative "scm/#{scm}" @scm_module ||= SCM.const_get(scm.camelcase) end
workspace_path()
click to toggle source
# File lib/luban/deployment/cli/application/repository.rb, line 23 def workspace_path @workspace_path ||= app_path.join('.luban') end
Protected Instance Methods
build!()
click to toggle source
# File lib/luban/deployment/cli/application/repository.rb, line 165 def build! rmdir(clone_path) clone end
bundle_gems()
click to toggle source
# File lib/luban/deployment/cli/application/repository.rb, line 183 def bundle_gems gemfile_path = Pathname.new(release_tag).join('Gemfile') gems_cache = Pathname.new('vendor').join('cache') bundle_path = Pathname.new('vendor').join('bundle') if release_with_gemfile?(gemfile_path) assure_dirs(gems_path) bundle_gems!(gemfile_path, gems_cache, bundle_path) else {} end end
bundle_gems!(gemfile_path, gems_cache, bundle_path)
click to toggle source
# File lib/luban/deployment/cli/application/repository.rb, line 195 def bundle_gems!(gemfile_path, gems_cache, bundle_path) bundled_gems = {} gems = bundled_gems[:gems] = {} within(gems_path) do paths_to_extract = [gemfile_path, "#{gemfile_path}.lock", "#{release_tag}/vendor/gems"] execute(:tar, "--strip-components=1 -xzf #{release_package_path} #{paths_to_extract.join(' ')} > /dev/null 2>&1; true") options = [] options << "--path #{bundle_path}" unless test(bundle_cmd, :check, *options) unless bundle_without.include?(stage.to_s) options << "--without #{bundle_without.join(' ')}" end options << "--jobs #{bundle_jobs} --quiet" if (output = capture(bundle_cmd, :install, *options)).empty? info "Successfully bundled gems in Gemfile" else abort "FAILED to bundle gems in Gemfile: #{output}" end if (output = capture(bundle_cmd, :package, "--all --quiet")).empty? info "Successfully packaged gems in Gemfile" else abort "Aborted! FAILED to package gems in Gemfile: #{output}" end end gem_files = capture(:ls, '-xtd', "#{gems_cache.join('*')} | grep -v \"md5$\"").split gem_files.each do |gem_file| gem_name = File.basename(gem_file) md5_file = gems_path.join("#{gem_file}.md5") gems[gem_name] = if file?(md5_file) capture(:cat, md5_file) else md5_for(gem_file).tap { |md5| execute(:echo, "#{md5} > #{md5_file}") } end end end gems_path.join(gems_cache).tap do |p| bundled_gems[:gems_cache] = { path: p, md5: md5_for_dir(p) } end gems_path.join('Gemfile.lock').tap do |p| bundled_gems[:locked_gemfile] = { path: p, md5: md5_for_file(p) } end bundled_gems end
cleanup_releases(keep_releases = 1)
click to toggle source
# File lib/luban/deployment/cli/application/repository.rb, line 174 def cleanup_releases(keep_releases = 1) cleanup_files(releases_path.join("#{release_prefix}-#{version}-*.#{release_package_extname}"), keep_copies: keep_releases) end
init()
click to toggle source
# File lib/luban/deployment/cli/application/repository.rb, line 154 def init @rev_size = DefaultRevisionSize task.opts.repository.each_pair { |k, v| instance_variable_set("@#{k}", v) } load_scm update_revision if cloned? and !version.nil? end
load_scm()
click to toggle source
# File lib/luban/deployment/cli/application/repository.rb, line 161 def load_scm singleton_class.send(:prepend, scm_module) end
release_with_gemfile?(gemfile_path)
click to toggle source
# File lib/luban/deployment/cli/application/repository.rb, line 179 def release_with_gemfile?(gemfile_path) test(:tar, "-tzf #{release_package_path} #{gemfile_path} > /dev/null 2>&1") end
update_revision()
click to toggle source
# File lib/luban/deployment/cli/application/repository.rb, line 170 def update_revision @revision = fetch_revision end