Class: Bard
- Inherits:
-
Thor
- Object
- Thor
- Bard
- Defined in:
- lib/bard.rb,
lib/bard/check.rb,
lib/bard/error.rb,
lib/bard/ssh_delegation.rb
Constant Summary collapse
- VERSION =
File.read(File.(File.dirname(__FILE__) + "../../VERSION")).chomp
Instance Method Summary collapse
- #check(project_path = nil) ⇒ Object
- #delegate(key) ⇒ Object
- #deploy ⇒ Object
- #install_authorized_keys(source_user, dest_user) ⇒ Object
- #pull ⇒ Object
- #push ⇒ Object
- #stage ⇒ Object
Instance Method Details
#check(project_path = nil) ⇒ Object
25 26 27 28 29 |
# File 'lib/bard.rb', line 25 def check(project_path = nil) project_path = "." if project_path.nil? and File.directory? ".git" and File.exist? "config/environment.rb" check_dependencies check_project project_path if project_path end |
#delegate(key) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/bard/ssh_delegation.rb', line 14 def delegate(key) command = ENV['SSH_ORIGINAL_COMMAND'] case command when /^scp -f (\w+)\.sql\.gz$/ project = $1 `#{command_for("staging", "cd #{project} && rake db:dump RAILS_ENV=staging && gzip -9f db/data.sql")}` command = "scp -f ~/#{project}/db/data.sql.gz" end exec command_for("staging", command) end |
#deploy ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/bard.rb', line 56 def deploy invoke :push run_crucial "git fetch origin" run_crucial "git checkout master" run_crucial "git pull --rebase origin master" raise MasterNonFastForwardError if not fast_forward_merge? "master", "integration" run_crucial "git merge integration" run_crucial "git push origin master" run_crucial "git checkout integration" "cap deploy" end |
#install_authorized_keys(source_user, dest_user) ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'lib/bard/ssh_delegation.rb', line 3 def (source_user, dest_user) source = "/home/#{source_user}/.ssh/authorized_keys" dest = "/home/#{dest_user}/.ssh/authorized_keys" file = File.read(source) file.gsub! /gitosis-serve/, "bard delegate" File.open(dest, "w") { |f| f.write(file) } end |
#pull ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/bard.rb', line 32 def pull ensure_sanity! warn NonFastForwardError unless fast_forward_merge? run_crucial "git pull --rebase origin integration" prepare_environment changed_files(@common_ancestor, "origin/integration") end |
#push ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/bard.rb', line 43 def push ensure_sanity! raise SubmoduleDirtyError if submodule_dirty? raise SubmoduleUnpushedError if submodule_unpushed? raise NonFastForwardError unless fast_forward_merge? run_crucial "git push origin integration", true "bard stage" end |
#stage ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/bard.rb', line 72 def stage check_dependencies ENV['RAILS_ENV'] = "staging" run_crucial "git fetch" run_crucial "git reset --hard origin/integration" prepare_environment end |