octopusci 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +132 -0
- data/bin/octopusci-reset-redis +26 -0
- data/bin/octopusci-skel +2 -7
- data/bin/octopusci-tentacles +2 -2
- data/config.ru +1 -1
- data/lib/octopusci.rb +3 -7
- data/lib/octopusci/config.rb +63 -49
- data/lib/octopusci/errors.rb +2 -0
- data/lib/octopusci/helpers.rb +16 -15
- data/lib/octopusci/io.rb +70 -0
- data/lib/octopusci/job.rb +145 -34
- data/lib/octopusci/job_store.rb +67 -0
- data/lib/octopusci/notifier.rb +7 -17
- data/lib/octopusci/notifier/job_complete.html.erb +76 -3
- data/lib/octopusci/queue.rb +14 -10
- data/lib/octopusci/server.rb +17 -20
- data/lib/octopusci/server/views/index.erb +3 -4
- data/lib/octopusci/server/views/job.erb +3 -3
- data/lib/octopusci/server/views/job_summary.erb +18 -18
- data/lib/octopusci/server/views/layout.erb +6 -5
- data/lib/octopusci/stage_locker.rb +11 -7
- data/lib/octopusci/version.rb +1 -1
- data/lib/octopusci/worker_launcher.rb +1 -1
- data/spec/lib/octopusci/config_spec.rb +195 -0
- data/spec/lib/octopusci/io_spec.rb +64 -0
- data/spec/lib/octopusci/job_spec.rb +122 -0
- data/spec/lib/octopusci/job_store_spec.rb +155 -0
- data/spec/lib/octopusci/notifier_spec.rb +0 -15
- data/spec/lib/octopusci/queue_spec.rb +122 -0
- data/spec/lib/octopusci/server_spec.rb +92 -1
- data/spec/lib/octopusci/stage_locker_spec.rb +94 -0
- data/spec/spec_helper.rb +8 -0
- metadata +39 -58
- data/README +0 -63
- data/bin/octopusci-db-migrate +0 -10
- data/db/migrate/0001_init.rb +0 -29
- data/db/migrate/0002_add_status_job.rb +0 -19
- data/lib/octopusci/notifier/job_complete.text.erb +0 -5
- data/lib/octopusci/schema.rb +0 -140
@@ -1,19 +0,0 @@
|
|
1
|
-
class AddStatusJob < ActiveRecord::Migration
|
2
|
-
def self.up
|
3
|
-
add_column(:jobs, :status, :string)
|
4
|
-
add_column(:jobs, :stage, :string)
|
5
|
-
add_column(:jobs, :output_file_path, :string)
|
6
|
-
remove_column(:jobs, :output)
|
7
|
-
remove_column(:jobs, :successful)
|
8
|
-
remove_column(:jobs, :running)
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.down
|
12
|
-
add_column(:jobs, :running, :boolean)
|
13
|
-
add_column(:jobs, :successful, :boolean)
|
14
|
-
add_column(:jobs, :output, :text)
|
15
|
-
remove_column(:jobs, :output_file_path)
|
16
|
-
remove_column(:jobs, :stage)
|
17
|
-
remove_column(:jobs, :status)
|
18
|
-
end
|
19
|
-
end
|
data/lib/octopusci/schema.rb
DELETED
@@ -1,140 +0,0 @@
|
|
1
|
-
require 'active_record'
|
2
|
-
|
3
|
-
class Job < ActiveRecord::Base
|
4
|
-
STATUS = {
|
5
|
-
'pending' => 'Pending...',
|
6
|
-
'running' => 'Running...',
|
7
|
-
'successful' => 'Successful',
|
8
|
-
'failed' => 'Failed',
|
9
|
-
'error' => 'Error'
|
10
|
-
}
|
11
|
-
|
12
|
-
serialize :payload
|
13
|
-
|
14
|
-
after_create :set_output_file_path
|
15
|
-
|
16
|
-
def branch_name
|
17
|
-
self.ref.gsub(/refs\/heads\//, '')
|
18
|
-
end
|
19
|
-
|
20
|
-
def display_status
|
21
|
-
return STATUS[self.status]
|
22
|
-
end
|
23
|
-
|
24
|
-
def successful?
|
25
|
-
return self.status == 'successful'
|
26
|
-
end
|
27
|
-
|
28
|
-
def failed?
|
29
|
-
return self.status == 'failed'
|
30
|
-
end
|
31
|
-
|
32
|
-
def finished?
|
33
|
-
return ['successful', 'failed', 'error'].include?(self.status)
|
34
|
-
end
|
35
|
-
|
36
|
-
def output
|
37
|
-
if File.exists?(self.abs_output_file_path)
|
38
|
-
return File.open(self.abs_output_file_path, 'r').read()
|
39
|
-
else
|
40
|
-
return ""
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def silent_output
|
45
|
-
if File.exists?(self.abs_silent_output_file_path)
|
46
|
-
return File.open(self.abs_silent_output_file_path, 'r').read()
|
47
|
-
else
|
48
|
-
return ""
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def workspace_path
|
53
|
-
return "#{Octopusci::CONFIG['general']['workspace_base_path']}/#{self.stage}"
|
54
|
-
end
|
55
|
-
|
56
|
-
# Relative path of the output file to the workspace base path.
|
57
|
-
def rel_output_file_path
|
58
|
-
"/jobs/#{self.id}/output.txt"
|
59
|
-
end
|
60
|
-
|
61
|
-
def abs_output_file_path
|
62
|
-
return "#{Octopusci::CONFIG['general']['workspace_base_path']}#{self.rel_output_file_path}"
|
63
|
-
end
|
64
|
-
|
65
|
-
def abs_silent_output_file_path
|
66
|
-
return "#{self.abs_output_path}/silent_output.txt"
|
67
|
-
end
|
68
|
-
|
69
|
-
def repository_path
|
70
|
-
return "#{self.workspace_path}/#{self.repo_name}"
|
71
|
-
end
|
72
|
-
|
73
|
-
def abs_output_path
|
74
|
-
return "#{Octopusci::CONFIG['general']['workspace_base_path']}/jobs/#{self.id}"
|
75
|
-
end
|
76
|
-
|
77
|
-
def code_cloned?
|
78
|
-
return File.directory?(self.repository_path)
|
79
|
-
end
|
80
|
-
|
81
|
-
def clone_code(job_conf)
|
82
|
-
if self.code_cloned?
|
83
|
-
return 0
|
84
|
-
else
|
85
|
-
if !Dir.exists?(self.workspace_path)
|
86
|
-
FileUtils.mkdir_p(self.workspace_path)
|
87
|
-
end
|
88
|
-
return self.run_command("cd #{self.workspace_path} 2>&1 && git clone #{job_conf['repo_uri']} #{self.repo_name} 2>&1", true)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def checkout_branch(job_conf)
|
93
|
-
if !self.code_cloned?
|
94
|
-
self.clone_code(job_conf)
|
95
|
-
end
|
96
|
-
|
97
|
-
return self.run_command("cd #{self.repository_path} 2>&1 && git fetch --all -p 2>&1 && git checkout #{self.branch_name} 2>&1 && git pull -f origin #{self.branch_name}:#{self.branch_name} 2>&1", true)
|
98
|
-
end
|
99
|
-
|
100
|
-
# Runs a command and logs it standard output to the job's associated
|
101
|
-
# output file. It also returns the exit status of the command that was
|
102
|
-
# run as the integer exit status of the commands on the command line.
|
103
|
-
def run_command(cmd_str, silently=false)
|
104
|
-
# Make sure that the directory structure is in place for the job output.
|
105
|
-
if !File.directory?(self.abs_output_path)
|
106
|
-
FileUtils.mkdir_p(self.abs_output_path)
|
107
|
-
end
|
108
|
-
|
109
|
-
out_f = nil
|
110
|
-
|
111
|
-
# Run the command and output the output to the job file
|
112
|
-
if silently
|
113
|
-
out_f = File.open(self.abs_silent_output_file_path, 'a')
|
114
|
-
else
|
115
|
-
out_f = File.open(self.abs_output_file_path, 'a')
|
116
|
-
end
|
117
|
-
out_f << "\n\nRunning: #{cmd_str}\n"
|
118
|
-
out_f << "-"*30
|
119
|
-
out_f << "\n"
|
120
|
-
out_f.flush
|
121
|
-
|
122
|
-
f = IO.popen(cmd_str)
|
123
|
-
while(cur_line = f.gets) do
|
124
|
-
out_f << cur_line
|
125
|
-
out_f.flush
|
126
|
-
end
|
127
|
-
|
128
|
-
out_f.close
|
129
|
-
f.close
|
130
|
-
|
131
|
-
return $?.exitstatus.to_i
|
132
|
-
end
|
133
|
-
|
134
|
-
private
|
135
|
-
|
136
|
-
def set_output_file_path
|
137
|
-
self.output_file_path = self.rel_output_file_path()
|
138
|
-
self.save!
|
139
|
-
end
|
140
|
-
end
|