Module: Rigup::CliMethods
- Included in:
- Cli
- Defined in:
- lib/rigup/cli.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#release_path ⇒ Object
readonly
Returns the value of attribute release_path.
-
#site_dir ⇒ Object
readonly
Returns the value of attribute site_dir.
Instance Method Summary collapse
-
#cache_dir ⇒ Object
remove_command :shared_path.
- #call_release_command(aCommand) ⇒ Object
-
#checkout_branch_commit ⇒ Object
Switches @repo to given branch and/or commit Should call prepare_cache first to create @repo requires params: branch and/or commit.
- #cleanup ⇒ Object
-
#config ⇒ Object
remove_command :logger.
-
#init(aPath = nil, aConfig = {}) ⇒ Object
remove_command :config.
- #link_live ⇒ Object
- #logger ⇒ Object
-
#prepare_cache ⇒ Object
Prepares repo in cache dir for site requires params: repo_url,site.
- #release ⇒ Object
- #repo ⇒ Object
- #shared_path ⇒ Object
- #update_cache(aPath = nil) ⇒ Object
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
34 35 36 |
# File 'lib/rigup/cli.rb', line 34 def context @context end |
#release_path ⇒ Object (readonly)
Returns the value of attribute release_path.
34 35 36 |
# File 'lib/rigup/cli.rb', line 34 def release_path @release_path end |
#site_dir ⇒ Object (readonly)
Returns the value of attribute site_dir.
34 35 36 |
# File 'lib/rigup/cli.rb', line 34 def site_dir @site_dir end |
Instance Method Details
#cache_dir ⇒ Object
remove_command :shared_path
41 42 43 |
# File 'lib/rigup/cli.rb', line 41 def cache_dir ::File.join(site_dir,'shared','cached-copy') end |
#call_release_command(aCommand) ⇒ Object
126 127 128 129 130 131 |
# File 'lib/rigup/cli.rb', line 126 def call_release_command(aCommand) return unless cmdline = config["#{aCommand}_command".to_sym].to_s.strip.to_nil cd release_path do run cmdline end end |
#checkout_branch_commit ⇒ Object
Switches @repo to given branch and/or commit Should call prepare_cache first to create @repo requires params: branch and/or commit
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/rigup/cli.rb', line 76 def checkout_branch_commit branch = config[:branch] || 'master' commit = config[:commit] repo.open(cache_dir) repo.checkout(commit,branch) #perhaps use reset --hard here if (commit) repo.merge(commit,['--ff-only']) else repo.merge('origin/'+branch,['--ff-only']) end end |
#cleanup ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/rigup/cli.rb', line 110 def cleanup @releases = run("ls -x #{@releases_path}").split.sort count = (@keep_releases || 3).to_i if count >= @releases.length logger.info "no old releases to clean up" else logger.info "keeping #{count} of #{@releases.length} deployed releases" directories = (@releases - @releases.last(count)).map { |r| File.join(@releases_path, r) }.join(" ") run "rm -rf #{directories}" end end |
#config ⇒ Object
remove_command :logger
9 10 11 |
# File 'lib/rigup/cli.rb', line 9 def config @context.config end |
#init(aPath = nil, aConfig = {}) ⇒ Object
remove_command :config
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rigup/cli.rb', line 14 def init(aPath=nil,aConfig={}) return if @initialised @initialised = true aPath ||= aConfig[:site_dir] || ::Dir.pwd @site_dir = ::Rigup::Utils::File.real_path(aPath) rescue ::File.(aPath) @releases_path = ::File.join(@site_dir,'releases') if ::File.exists?(f=::File.join(@site_dir,'rigup.yml')) file_config = ::YAML.load(String.from_file(f)) aConfig.merge!(file_config) end aConfig = aConfig.merge(:site_dir => @site_dir) aConfig[:user] ||= ENV['USER'] config = ::Rigup::Config.new(aConfig) @context = ::Rigup::Context.new({ :config => config, :logger => ::Logger.new(STDOUT), :pwd => ::Dir.pwd }) end |
#link_live ⇒ Object
106 107 108 |
# File 'lib/rigup/cli.rb', line 106 def link_live ensure_link(release_path,::File.(::File.join(site_dir,'current')),"#{config[:user]}:#{config[:group]}") end |
#logger ⇒ Object
4 5 6 |
# File 'lib/rigup/cli.rb', line 4 def logger @logger ||= ::Logger.new(STDOUT) end |
#prepare_cache ⇒ Object
Prepares repo in cache dir for site requires params: repo_url,site
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/rigup/cli.rb', line 51 def prepare_cache # {:url=>'git://github.com/ddssda', :branch=>'master', :commit=>'ad452bcd'} url = config[:git_url] wd = cache_dir suitable = if ::File.exists?(wd) repo.open wd repo.origin.url==url else false end if suitable repo.fetch else if ::File.exists? wd #raise RuntimeError.new('almost did bad delete') if [email protected]_dir || @core.cache_dir.length<3 || !wd.begins_with?(@core.cache_dir) ::FileUtils.rm_rf wd end repo.clone(url, wd) end end |
#release ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/rigup/cli.rb', line 94 def release release = ::Time.now.strftime('%Y%m%d%H%M%S') @release_path = ::File.(release,@releases_path) repo.open(cache_dir) repo.export(@release_path) release_config = context.config.to_hash release_config[:commit] = repo.head.sha release_config[:branch] = repo.branch release_config.to_yaml.to_file(::File.join(@release_path,'rigup.yml')) return @release_path end |
#repo ⇒ Object
45 46 47 |
# File 'lib/rigup/cli.rb', line 45 def repo @repo ||= ::Rigup::GitRepo.new(context) end |
#shared_path ⇒ Object
36 37 38 |
# File 'lib/rigup/cli.rb', line 36 def shared_path @shared_path ||= ::File.('shared',site_dir) end |
#update_cache(aPath = nil) ⇒ Object
89 90 91 92 |
# File 'lib/rigup/cli.rb', line 89 def update_cache(aPath=nil) prepare_cache checkout_branch_commit end |