Class: Shipit::Job

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/shipit/job.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.enable_mock!Object

Mocks cloning and deploying



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/shipit/job.rb', line 53

def self.enable_mock!
  self.class_eval do
    def clone
      Kernel.system "      rm -rf \#{dir}\n      mkdir -p \#{File.dirname(dir)}\n      cp -r \#{File.expand_path('../../../spec/fixtures/repo', __FILE__)} \#{dir}\n      SHELL\n    end\n  end\nend\n"

.start(params) ⇒ Object



8
9
10
11
12
# File 'lib/shipit/job.rb', line 8

def self.start(params)
  repo = Repository.find_by_name(params[:name])
  env  = Environment.find_or_create(repo, (params[:env] || "production"))
  new(:environment => env).tap { |job| job.save }.run
end

Instance Method Details

#branchObject

TODO: Make configurable



44
45
46
# File 'lib/shipit/job.rb', line 44

def branch
  "master"
end

#cloneObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/shipit/job.rb', line 20

def clone
  Kernel.system "  mkdir -p \#{dir}\n  cd \#{dir}\n  if [ ! -d './.git' ]; then\n    git init\n    git remote add origin \#{repository.uri}\n  fi\n  git fetch -q origin\n  git reset -q --hard origin/\#{branch}\n  SHELL\nend\n"

#commandObject



48
49
50
# File 'lib/shipit/job.rb', line 48

def command
  "cd #{dir}; #{environment.command}"
end

#deployObject



33
34
35
36
37
38
39
40
41
# File 'lib/shipit/job.rb', line 33

def deploy
  self.output = ""
  Bundler.with_clean_env do
    IO.popen(command, :err => [:child, :out]) do |io|
      io.each { |line| self.output << line }
    end
  end
  self.save
end

#runObject

Runs the deploy



15
16
17
18
# File 'lib/shipit/job.rb', line 15

def run
  self.clone
  self.deploy
end