shipit-engine 0.5.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (274) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/concerns/shipit/api/cacheable.rb +13 -0
  3. data/app/controllers/concerns/shipit/api/paginable.rb +37 -0
  4. data/app/controllers/concerns/shipit/api/rendering.rb +25 -0
  5. data/app/controllers/concerns/{api/paginable.rb → shipit/pagination.rb} +5 -13
  6. data/app/controllers/shipit/api/base_controller.rb +68 -0
  7. data/app/controllers/shipit/api/deploys_controller.rb +17 -0
  8. data/app/controllers/shipit/api/hooks_controller.rb +53 -0
  9. data/app/controllers/shipit/api/locks_controller.rb +32 -0
  10. data/app/controllers/shipit/api/outputs_controller.rb +17 -0
  11. data/app/controllers/shipit/api/stacks_controller.rb +21 -0
  12. data/app/controllers/shipit/api/tasks_controller.rb +20 -0
  13. data/app/controllers/shipit/commit_checks_controller.rb +26 -0
  14. data/app/controllers/shipit/deploys_controller.rb +47 -0
  15. data/app/controllers/shipit/github_authentication_controller.rb +27 -0
  16. data/app/controllers/shipit/rollbacks_controller.rb +26 -0
  17. data/app/controllers/shipit/shipit_controller.rb +62 -0
  18. data/app/controllers/shipit/stacks_controller.rb +81 -0
  19. data/app/controllers/shipit/status_controller.rb +7 -0
  20. data/app/controllers/shipit/tasks_controller.rb +48 -0
  21. data/app/controllers/shipit/webhooks_controller.rb +101 -0
  22. data/app/helpers/shipit/chunks_helper.rb +8 -0
  23. data/app/helpers/shipit/deploys_helper.rb +28 -0
  24. data/app/helpers/shipit/github_url_helper.rb +48 -0
  25. data/app/helpers/shipit/shipit_helper.rb +64 -0
  26. data/app/helpers/shipit/stacks_helper.rb +78 -0
  27. data/app/helpers/shipit/tasks_helper.rb +11 -0
  28. data/app/jobs/shipit/background_job.rb +24 -0
  29. data/app/jobs/shipit/background_job/unique.rb +28 -0
  30. data/app/jobs/shipit/cache_deploy_spec_job.rb +12 -0
  31. data/app/jobs/shipit/chunk_rollup_job.rb +21 -0
  32. data/app/jobs/shipit/clear_git_cache_job.rb +9 -0
  33. data/app/jobs/shipit/deliver_hook_job.rb +9 -0
  34. data/app/jobs/shipit/destroy_stack_job.rb +9 -0
  35. data/app/jobs/shipit/emit_event_job.rb +10 -0
  36. data/app/jobs/shipit/fetch_commit_stats_job.rb +9 -0
  37. data/app/jobs/shipit/fetch_deployed_revision_job.rb +23 -0
  38. data/app/jobs/shipit/git_mirror_update_job.rb +12 -0
  39. data/app/jobs/shipit/github_sync_job.rb +55 -0
  40. data/app/jobs/shipit/perform_commit_checks_job.rb +7 -0
  41. data/app/jobs/shipit/perform_task_job.rb +57 -0
  42. data/app/jobs/shipit/refresh_github_user_job.rb +9 -0
  43. data/app/jobs/shipit/refresh_statuses_job.rb +14 -0
  44. data/app/jobs/shipit/setup_github_hook_job.rb +11 -0
  45. data/app/models/shipit/anonymous_user.rb +43 -0
  46. data/app/models/shipit/api_client.rb +44 -0
  47. data/app/models/shipit/commit.rb +209 -0
  48. data/app/models/shipit/commit_checks.rb +90 -0
  49. data/app/models/shipit/delivery.rb +47 -0
  50. data/app/models/shipit/deploy.rb +153 -0
  51. data/app/models/shipit/deploy_spec.rb +150 -0
  52. data/app/models/shipit/deploy_spec/bundler_discovery.rb +61 -0
  53. data/app/models/shipit/deploy_spec/capistrano_discovery.rb +29 -0
  54. data/app/models/shipit/deploy_spec/file_system.rb +64 -0
  55. data/app/models/shipit/deploy_spec/pypi_discovery.rb +34 -0
  56. data/app/models/shipit/deploy_spec/rubygems_discovery.rb +34 -0
  57. data/app/models/shipit/github_hook.rb +148 -0
  58. data/app/models/shipit/hook.rb +86 -0
  59. data/app/models/shipit/membership.rb +8 -0
  60. data/app/models/shipit/missing_status.rb +21 -0
  61. data/app/models/shipit/output_chunk.rb +11 -0
  62. data/app/models/shipit/rollback.rb +31 -0
  63. data/app/models/shipit/stack.rb +308 -0
  64. data/app/models/shipit/status.rb +44 -0
  65. data/app/models/shipit/status_group.rb +35 -0
  66. data/app/models/shipit/task.rb +201 -0
  67. data/app/models/shipit/task_definition.rb +38 -0
  68. data/app/models/shipit/team.rb +69 -0
  69. data/app/models/shipit/unknown_status.rb +43 -0
  70. data/app/models/shipit/user.rb +83 -0
  71. data/app/models/shipit/variable_definition.rb +21 -0
  72. data/app/serializers/concerns/shipit/conditional_attributes.rb +22 -0
  73. data/app/serializers/shipit/anonymous_user_serializer.rb +4 -0
  74. data/app/serializers/shipit/commit_serializer.rb +8 -0
  75. data/app/serializers/shipit/deploy_serializer.rb +15 -0
  76. data/app/serializers/shipit/hook_serializer.rb +12 -0
  77. data/app/serializers/shipit/rollback_serializer.rb +7 -0
  78. data/app/serializers/shipit/short_commit_serializer.rb +9 -0
  79. data/app/serializers/shipit/stack_serializer.rb +33 -0
  80. data/app/serializers/shipit/tail_task_serializer.rb +39 -0
  81. data/app/serializers/shipit/task_serializer.rb +30 -0
  82. data/app/serializers/shipit/user_serializer.rb +5 -0
  83. data/app/views/{commits → shipit/commits}/_commit.html.erb +1 -1
  84. data/app/views/{commits → shipit/commits}/_commit_author.html.erb +0 -0
  85. data/app/views/{deploys → shipit/deploys}/_checklist.html.erb +0 -0
  86. data/app/views/{deploys → shipit/deploys}/_checks.html.erb +0 -0
  87. data/app/views/{deploys → shipit/deploys}/_concurrent_deploy_warning.html.erb +0 -0
  88. data/app/views/{deploys → shipit/deploys}/_deploy.html.erb +1 -1
  89. data/app/views/{deploys → shipit/deploys}/_monitoring.html.erb +0 -0
  90. data/app/views/{deploys → shipit/deploys}/_summary.html.erb +0 -0
  91. data/app/views/{deploys → shipit/deploys}/new.html.erb +3 -3
  92. data/app/views/{deploys → shipit/deploys}/rollback.html.erb +2 -2
  93. data/app/views/{deploys → shipit/deploys}/show.html.erb +1 -1
  94. data/app/views/{github_authentication → shipit/github_authentication}/failed.html.erb +0 -0
  95. data/app/views/{stacks → shipit/stacks}/_header.html.erb +0 -0
  96. data/app/views/{stacks → shipit/stacks}/index.html.erb +0 -0
  97. data/app/views/{stacks → shipit/stacks}/new.html.erb +0 -0
  98. data/app/views/{stacks → shipit/stacks}/settings.html.erb +1 -1
  99. data/app/views/{stacks → shipit/stacks}/show.html.erb +2 -2
  100. data/app/views/{statuses → shipit/statuses}/_group.html.erb +1 -1
  101. data/app/views/{statuses → shipit/statuses}/_status.html.erb +0 -0
  102. data/app/views/{tasks → shipit/tasks}/_task.html.erb +1 -1
  103. data/app/views/{tasks → shipit/tasks}/_task_output.html.erb +1 -1
  104. data/app/views/{tasks → shipit/tasks}/index.html.erb +1 -1
  105. data/app/views/{tasks → shipit/tasks}/new.html.erb +1 -1
  106. data/app/views/{tasks → shipit/tasks}/show.html.erb +1 -1
  107. data/db/migrate/20160104151742_increase_tasks_type_size_back.rb +5 -0
  108. data/db/migrate/20160104151833_convert_sti_columns.rb +10 -0
  109. data/lib/shipit.rb +11 -10
  110. data/lib/shipit/command.rb +171 -0
  111. data/lib/shipit/commands.rb +25 -0
  112. data/lib/shipit/deploy_commands.rb +21 -0
  113. data/lib/shipit/engine.rb +3 -0
  114. data/lib/shipit/rollback_commands.rb +7 -0
  115. data/lib/shipit/stack_commands.rb +60 -0
  116. data/lib/shipit/task_commands.rb +68 -0
  117. data/lib/shipit/version.rb +1 -1
  118. data/lib/tasks/cron.rake +3 -3
  119. data/test/controllers/api/base_controller_test.rb +18 -14
  120. data/test/controllers/api/deploys_controller_test.rb +56 -52
  121. data/test/controllers/api/hooks_controller_test.rb +62 -58
  122. data/test/controllers/api/locks_controller_test.rb +38 -34
  123. data/test/controllers/api/outputs_controller_test.rb +15 -11
  124. data/test/controllers/api/stacks_controller_test.rb +56 -52
  125. data/test/controllers/api/tasks_controller_test.rb +30 -26
  126. data/test/controllers/commit_checks_controller_test.rb +29 -27
  127. data/test/controllers/deploys_controller_test.rb +68 -66
  128. data/test/controllers/github_authentication_controller_test.rb +9 -7
  129. data/test/controllers/rollbacks_controller_test.rb +43 -41
  130. data/test/controllers/stacks_controller_test.rb +131 -128
  131. data/test/controllers/status_controller_test.rb +8 -6
  132. data/test/controllers/tasks_controller_test.rb +70 -68
  133. data/test/controllers/webhooks_controller_test.rb +127 -125
  134. data/test/dummy/db/development.sqlite3 +0 -0
  135. data/test/dummy/db/schema.rb +2 -2
  136. data/test/dummy/db/seeds.rb +133 -131
  137. data/test/dummy/db/test.sqlite3 +0 -0
  138. data/test/fixtures/{api_clients.yml → shipit/api_clients.yml} +0 -0
  139. data/test/fixtures/{commits.yml → shipit/commits.yml} +0 -0
  140. data/test/fixtures/{deliveries.yml → shipit/deliveries.yml} +0 -0
  141. data/test/fixtures/{github_hooks.yml → shipit/github_hooks.yml} +4 -4
  142. data/test/fixtures/{hooks.yml → shipit/hooks.yml} +0 -0
  143. data/test/fixtures/{memberships.yml → shipit/memberships.yml} +0 -0
  144. data/test/fixtures/{output_chunks.yml → shipit/output_chunks.yml} +0 -0
  145. data/test/fixtures/{stacks.yml → shipit/stacks.yml} +0 -0
  146. data/test/fixtures/{statuses.yml → shipit/statuses.yml} +0 -0
  147. data/test/fixtures/{tasks.yml → shipit/tasks.yml} +8 -8
  148. data/test/fixtures/{teams.yml → shipit/teams.yml} +0 -0
  149. data/test/fixtures/{users.yml → shipit/users.yml} +0 -0
  150. data/test/helpers/api_helper.rb +1 -1
  151. data/test/helpers/fixture_aliases_helper.rb +4 -4
  152. data/test/jobs/cache_deploy_spec_job_test.rb +15 -13
  153. data/test/jobs/chunk_rollup_job_test.rb +30 -28
  154. data/test/jobs/deliver_hook_job_test.rb +11 -9
  155. data/test/jobs/destroy_stack_job_test.rb +11 -9
  156. data/test/jobs/emit_event_job_test.rb +10 -8
  157. data/test/jobs/fetch_commit_stats_job_test.rb +10 -8
  158. data/test/jobs/fetch_deployed_revision_job_test.rb +24 -22
  159. data/test/jobs/github_sync_job_test.rb +51 -49
  160. data/test/jobs/perform_task_job_test.rb +78 -76
  161. data/test/jobs/refresh_github_user_job_test.rb +10 -8
  162. data/test/jobs/refresh_status_job_test.rb +14 -12
  163. data/test/jobs/unique_job_test.rb +18 -15
  164. data/test/models/api_client_test.rb +20 -18
  165. data/test/models/commit_checks_test.rb +63 -61
  166. data/test/models/commits_test.rb +317 -314
  167. data/test/models/delivery_test.rb +29 -27
  168. data/test/models/deploys_test.rb +289 -287
  169. data/test/models/github_hook_test.rb +45 -43
  170. data/test/models/hook_test.rb +44 -42
  171. data/test/models/membership_test.rb +9 -7
  172. data/test/models/missing_status_test.rb +16 -14
  173. data/test/models/output_chunk_test.rb +14 -12
  174. data/test/models/rollbacks_test.rb +14 -12
  175. data/test/models/stacks_test.rb +272 -270
  176. data/test/models/status_group_test.rb +18 -16
  177. data/test/models/status_test.rb +42 -40
  178. data/test/models/task_definitions_test.rb +27 -25
  179. data/test/models/team_test.rb +39 -37
  180. data/test/models/users_test.rb +61 -59
  181. data/test/unit/command_test.rb +43 -41
  182. data/test/unit/commands_test.rb +8 -6
  183. data/test/unit/csv_serializer_test.rb +28 -26
  184. data/test/unit/deploy_commands_test.rb +179 -176
  185. data/test/unit/deploy_spec_test.rb +237 -235
  186. data/test/unit/github_url_helper_test.rb +19 -17
  187. data/test/unit/shipit_test.rb +44 -42
  188. metadata +139 -137
  189. data/app/controllers/api/base_controller.rb +0 -66
  190. data/app/controllers/api/deploys_controller.rb +0 -15
  191. data/app/controllers/api/hooks_controller.rb +0 -51
  192. data/app/controllers/api/locks_controller.rb +0 -30
  193. data/app/controllers/api/outputs_controller.rb +0 -15
  194. data/app/controllers/api/stacks_controller.rb +0 -19
  195. data/app/controllers/api/tasks_controller.rb +0 -18
  196. data/app/controllers/commit_checks_controller.rb +0 -24
  197. data/app/controllers/concerns/api/cacheable.rb +0 -11
  198. data/app/controllers/concerns/api/rendering.rb +0 -23
  199. data/app/controllers/concerns/pagination.rb +0 -25
  200. data/app/controllers/deploys_controller.rb +0 -45
  201. data/app/controllers/github_authentication_controller.rb +0 -25
  202. data/app/controllers/rollbacks_controller.rb +0 -24
  203. data/app/controllers/shipit_controller.rb +0 -54
  204. data/app/controllers/stacks_controller.rb +0 -79
  205. data/app/controllers/status_controller.rb +0 -5
  206. data/app/controllers/tasks_controller.rb +0 -46
  207. data/app/controllers/webhooks_controller.rb +0 -99
  208. data/app/helpers/chunks_helper.rb +0 -6
  209. data/app/helpers/deploys_helper.rb +0 -26
  210. data/app/helpers/github_url_helper.rb +0 -46
  211. data/app/helpers/shipit_helper.rb +0 -62
  212. data/app/helpers/stacks_helper.rb +0 -76
  213. data/app/helpers/tasks_helper.rb +0 -9
  214. data/app/jobs/background_job.rb +0 -22
  215. data/app/jobs/background_job/unique.rb +0 -26
  216. data/app/jobs/cache_deploy_spec_job.rb +0 -10
  217. data/app/jobs/chunk_rollup_job.rb +0 -19
  218. data/app/jobs/clear_git_cache_job.rb +0 -7
  219. data/app/jobs/deliver_hook_job.rb +0 -7
  220. data/app/jobs/destroy_stack_job.rb +0 -7
  221. data/app/jobs/emit_event_job.rb +0 -8
  222. data/app/jobs/fetch_commit_stats_job.rb +0 -7
  223. data/app/jobs/fetch_deployed_revision_job.rb +0 -21
  224. data/app/jobs/git_mirror_update_job.rb +0 -10
  225. data/app/jobs/github_sync_job.rb +0 -53
  226. data/app/jobs/perform_commit_checks_job.rb +0 -5
  227. data/app/jobs/perform_task_job.rb +0 -55
  228. data/app/jobs/refresh_github_user_job.rb +0 -7
  229. data/app/jobs/refresh_statuses_job.rb +0 -12
  230. data/app/jobs/setup_github_hook_job.rb +0 -9
  231. data/app/models/anonymous_user.rb +0 -41
  232. data/app/models/api_client.rb +0 -42
  233. data/app/models/commit.rb +0 -207
  234. data/app/models/commit_checks.rb +0 -88
  235. data/app/models/delivery.rb +0 -45
  236. data/app/models/deploy.rb +0 -151
  237. data/app/models/deploy_spec.rb +0 -148
  238. data/app/models/deploy_spec/bundler_discovery.rb +0 -59
  239. data/app/models/deploy_spec/capistrano_discovery.rb +0 -27
  240. data/app/models/deploy_spec/file_system.rb +0 -62
  241. data/app/models/deploy_spec/pypi_discovery.rb +0 -32
  242. data/app/models/deploy_spec/rubygems_discovery.rb +0 -32
  243. data/app/models/github_hook.rb +0 -144
  244. data/app/models/hook.rb +0 -84
  245. data/app/models/membership.rb +0 -6
  246. data/app/models/missing_status.rb +0 -18
  247. data/app/models/output_chunk.rb +0 -9
  248. data/app/models/rollback.rb +0 -29
  249. data/app/models/stack.rb +0 -306
  250. data/app/models/status.rb +0 -42
  251. data/app/models/status_group.rb +0 -33
  252. data/app/models/task.rb +0 -197
  253. data/app/models/task_definition.rb +0 -36
  254. data/app/models/team.rb +0 -67
  255. data/app/models/unknown_status.rb +0 -41
  256. data/app/models/user.rb +0 -81
  257. data/app/models/variable_definition.rb +0 -19
  258. data/app/serializers/anonymous_user_serializer.rb +0 -2
  259. data/app/serializers/commit_serializer.rb +0 -6
  260. data/app/serializers/concerns/conditional_attributes.rb +0 -20
  261. data/app/serializers/deploy_serializer.rb +0 -13
  262. data/app/serializers/hook_serializer.rb +0 -10
  263. data/app/serializers/rollback_serializer.rb +0 -5
  264. data/app/serializers/short_commit_serializer.rb +0 -7
  265. data/app/serializers/stack_serializer.rb +0 -31
  266. data/app/serializers/tail_task_serializer.rb +0 -37
  267. data/app/serializers/task_serializer.rb +0 -28
  268. data/app/serializers/user_serializer.rb +0 -3
  269. data/lib/command.rb +0 -169
  270. data/lib/commands.rb +0 -23
  271. data/lib/deploy_commands.rb +0 -19
  272. data/lib/rollback_commands.rb +0 -5
  273. data/lib/stack_commands.rb +0 -58
  274. data/lib/task_commands.rb +0 -66
@@ -1,88 +0,0 @@
1
- class CommitChecks
2
- OUTPUT_TTL = 10.minutes.to_i
3
- FINAL_STATUSES = %w(failed error success)
4
-
5
- def initialize(commit)
6
- @commit = commit
7
- end
8
-
9
- def run
10
- self.status = 'running'
11
- commands = StackCommands.new(stack)
12
- commands.with_temporary_working_directory(commit: commit) do |directory|
13
- deploy_spec = DeploySpec::FileSystem.new(directory, stack.environment)
14
- Bundler.with_clean_env do
15
- capture_all(build_commands(deploy_spec.dependencies_steps, chdir: directory))
16
- capture_all(build_commands(deploy_spec.review_checks, chdir: directory))
17
- end
18
- end
19
- rescue Command::Error
20
- self.status = 'failed'
21
- rescue
22
- self.status = 'error'
23
- raise
24
- else
25
- self.status = 'success'
26
- end
27
-
28
- def schedule
29
- if redis.set('output', '', ex: OUTPUT_TTL, nx: true)
30
- self.status = 'scheduled'
31
- PerformCommitChecksJob.perform_later(commit: commit)
32
- end
33
- end
34
-
35
- def status
36
- @status ||= redis.get('status')
37
- end
38
-
39
- def status=(status)
40
- redis.set('status', status, ex: OUTPUT_TTL)
41
- @status = status
42
- end
43
-
44
- def finished?
45
- FINAL_STATUSES.include?(status)
46
- end
47
-
48
- def output(since: 0)
49
- redis.getrange('output', since, -1)
50
- end
51
-
52
- def write(output)
53
- redis.append('output', output)
54
- end
55
-
56
- private
57
-
58
- def build_commands(commands, chdir:)
59
- commands.map { |c| Command.new(c, env: Shipit.env, chdir: chdir) }
60
- end
61
-
62
- def capture_all(commands)
63
- commands.map { |c| capture(c) }
64
- end
65
-
66
- def capture(command)
67
- command.start
68
- write("$ #{command}\n")
69
- command.stream! do |line|
70
- write(line)
71
- end
72
- rescue Command::Error => error
73
- write(error.message)
74
- raise
75
- ensure
76
- write("\n")
77
- end
78
-
79
- attr_reader :commit
80
-
81
- def redis
82
- @redis ||= Shipit.redis("commit:#{commit.id}:checks")
83
- end
84
-
85
- def stack
86
- @stack ||= commit.stack
87
- end
88
- end
@@ -1,45 +0,0 @@
1
- class Delivery < ActiveRecord::Base
2
- STATUSES = %w(pending scheduled sent).freeze
3
- enum status: STATUSES.zip(STATUSES).to_h
4
-
5
- belongs_to :hook
6
-
7
- validates :url, presence: true, url: {no_local: true, allow_blank: true}
8
- validates :content_type, presence: true
9
-
10
- serialize :response_headers, JSON
11
-
12
- def schedule!
13
- DeliverHookJob.perform_later(self)
14
- scheduled!
15
- end
16
-
17
- def send!
18
- update!(response: http.post(url, payload), status: 'sent', delivered_at: Time.now)
19
- end
20
-
21
- def response=(response)
22
- self.response_code = response.status
23
- self.response_headers = response.headers
24
- self.response_body = response.body
25
- end
26
-
27
- private
28
-
29
- def http
30
- Faraday::Connection.new do |connection|
31
- connection.headers = headers
32
- connection.adapter Faraday.default_adapter
33
- end
34
- end
35
-
36
- def headers
37
- {
38
- 'User-Agent' => 'Shipit Webhook',
39
- 'Content-Type' => content_type,
40
- 'X-Shipit-Event' => event,
41
- 'X-Shipit-Delivery' => id.to_s,
42
- 'Accept' => '*/*',
43
- }
44
- end
45
- end
data/app/models/deploy.rb DELETED
@@ -1,151 +0,0 @@
1
- require 'fileutils'
2
-
3
- class Deploy < Task
4
- CONFIRMATIONS_REQUIRED = 5
5
-
6
- state_machine :status do
7
- after_transition to: :success, do: :schedule_continuous_delivery
8
- after_transition to: :success, do: :update_undeployed_commits_count
9
- after_transition to: :aborted, do: :trigger_revert_if_required
10
- end
11
-
12
- before_create :denormalize_commit_stats
13
- after_commit :broadcast_update
14
-
15
- delegate :broadcast_update, to: :stack
16
-
17
- def build_rollback(user = nil, env: nil)
18
- Rollback.new(
19
- user_id: user.try!(:id),
20
- stack_id: stack_id,
21
- parent_id: id,
22
- since_commit: stack.last_deployed_commit,
23
- until_commit: until_commit,
24
- env: env || {},
25
- )
26
- end
27
-
28
- # Rolls the stack back to this deploy
29
- def trigger_rollback(user = AnonymousUser.new, env: nil)
30
- rollback = build_rollback(user, env: env)
31
- rollback.save!
32
- rollback.enqueue
33
-
34
- lock_reason = "A rollback for #{rollback.since_commit.sha} has been triggered. " \
35
- "Please make sure the reason for the rollback has been addressed before deploying again."
36
- stack.update!(lock_reason: lock_reason, lock_author_id: user.id)
37
-
38
- rollback
39
- end
40
-
41
- # Rolls the stack back to the **previous** deploy
42
- def trigger_revert
43
- rollback = Rollback.create!(
44
- user_id: user_id,
45
- stack_id: stack_id,
46
- parent_id: id,
47
- since_commit: until_commit,
48
- until_commit: since_commit,
49
- )
50
- rollback.enqueue
51
- lock_reason = "A rollback for #{until_commit.sha} has been triggered. " \
52
- "Please make sure the reason for the rollback has been addressed before deploying again."
53
- stack.update!(lock_reason: lock_reason, lock_author_id: user_id)
54
- rollback
55
- end
56
-
57
- def rollback?
58
- false
59
- end
60
-
61
- def commit_range
62
- [since_commit, until_commit]
63
- end
64
-
65
- delegate :supports_rollback?, to: :stack
66
-
67
- def rollbackable?
68
- success? && supports_rollback? && !currently_deployed?
69
- end
70
-
71
- def currently_deployed?
72
- until_commit_id == stack.last_deployed_commit.try!(:id)
73
- end
74
-
75
- def commits
76
- return Commit.none unless stack
77
-
78
- @commits ||= stack.commits.reachable.newer_than(since_commit_id).until(until_commit_id).order(id: :desc)
79
- end
80
-
81
- def commits_since
82
- return Commit.none unless stack
83
-
84
- @commits_since ||= stack.commits.reachable.newer_than(until_commit_id).order(id: :desc)
85
- end
86
-
87
- def since_commit_id
88
- super || default_since_commit_id
89
- end
90
-
91
- def variables
92
- stack.deploy_variables
93
- end
94
-
95
- def reject!
96
- return if failed?
97
- transaction do
98
- flap! unless flapping?
99
- update!(confirmations: [confirmations - 1, -1].min)
100
- failure! if confirmed?
101
- end
102
- end
103
-
104
- def accept!
105
- return if success?
106
- transaction do
107
- flap! unless flapping?
108
- update!(confirmations: [confirmations + 1, 1].max)
109
- complete! if confirmed?
110
- end
111
- end
112
-
113
- def confirmed?
114
- confirmations.abs >= CONFIRMATIONS_REQUIRED
115
- end
116
-
117
- private
118
-
119
- def trigger_revert_if_required
120
- return unless rollback_once_aborted?
121
- return unless supports_rollback?
122
- trigger_revert
123
- end
124
-
125
- def default_since_commit_id
126
- return unless stack
127
- @default_since_commit_id ||= last_successful_deploy.try!(:until_commit_id)
128
- end
129
-
130
- def denormalize_commit_stats
131
- self.additions = commits.map(&:additions).compact.sum
132
- self.deletions = commits.map(&:deletions).compact.sum
133
- end
134
-
135
- def schedule_continuous_delivery
136
- return unless stack.continuous_deployment?
137
-
138
- to_deploy = stack.commits.order(:id).newer_than(until_commit).successful.last
139
- return unless to_deploy
140
-
141
- stack.trigger_deploy(to_deploy, to_deploy.committer)
142
- end
143
-
144
- def last_successful_deploy
145
- stack.deploys.where(status: "success").last
146
- end
147
-
148
- def update_undeployed_commits_count
149
- stack.update_undeployed_commits_count(until_commit)
150
- end
151
- end
@@ -1,148 +0,0 @@
1
- require 'pathname'
2
-
3
- class DeploySpec
4
- Error = Class.new(StandardError)
5
-
6
- class << self
7
- def load(json)
8
- config = json.blank? ? {} : JSON.parse(json)
9
- new(config)
10
- end
11
-
12
- def dump(spec)
13
- JSON.dump(spec.cacheable.config) if spec
14
- end
15
-
16
- def bundle_path
17
- Rails.root.join('data/bundler')
18
- end
19
- end
20
-
21
- def initialize(config)
22
- @config = config
23
- end
24
-
25
- delegate :bundle_path, to: :class
26
-
27
- def cacheable
28
- self
29
- end
30
-
31
- def config(*keys)
32
- keys.flatten.reduce(@config) { |h, k| h[k] if h.respond_to?(:[]) }
33
- end
34
-
35
- def supports_fetch_deployed_revision?
36
- fetch_deployed_revision_steps.present?
37
- end
38
-
39
- def supports_rollback?
40
- rollback_steps.present?
41
- end
42
-
43
- def machine_env
44
- config('machine', 'environment') || {}
45
- end
46
-
47
- def directory
48
- config('machine', 'directory')
49
- end
50
-
51
- def dependencies_steps
52
- config('dependencies', 'override') || discover_dependencies_steps || []
53
- end
54
- alias_method :dependencies_steps!, :dependencies_steps
55
-
56
- def deploy_steps
57
- config('deploy', 'override') || discover_deploy_steps
58
- end
59
-
60
- def deploy_steps!
61
- deploy_steps || cant_detect!(:deploy)
62
- end
63
-
64
- def deploy_variables
65
- Array.wrap(config('deploy', 'variables')).map(&VariableDefinition.method(:new))
66
- end
67
-
68
- def rollback_steps
69
- config('rollback', 'override') || discover_rollback_steps
70
- end
71
-
72
- def rollback_steps!
73
- rollback_steps || cant_detect!(:rollback)
74
- end
75
-
76
- def fetch_deployed_revision_steps
77
- config('fetch') || discover_fetch_deployed_revision_steps
78
- end
79
-
80
- def fetch_deployed_revision_steps!
81
- fetch_deployed_revision_steps || cant_detect!(:fetch)
82
- end
83
-
84
- def task_definitions
85
- (config('tasks') || {}).map { |name, definition| TaskDefinition.new(name, coerce_task_definition(definition)) }
86
- end
87
-
88
- def find_task_definition(id)
89
- TaskDefinition.new(id, coerce_task_definition(config('tasks', id)) || task_not_found!(id))
90
- end
91
-
92
- def review_checklist
93
- (config('review', 'checklist') || discover_review_checklist || []).map(&:strip).select(&:present?)
94
- end
95
-
96
- def review_monitoring
97
- (config('review', 'monitoring') || []).select(&:present?)
98
- end
99
-
100
- def hidden_statuses
101
- Array.wrap(config('ci', 'hide'))
102
- end
103
-
104
- def required_statuses
105
- Array.wrap(config('ci', 'require'))
106
- end
107
-
108
- def soft_failing_statuses
109
- Array.wrap(config('ci', 'allow_failures'))
110
- end
111
-
112
- def review_checks
113
- config('review', 'checks') || []
114
- end
115
-
116
- def plugins
117
- config('plugins') || {}
118
- end
119
-
120
- private
121
-
122
- def coerce_task_definition(config)
123
- config
124
- end
125
-
126
- def discover_review_checklist
127
- end
128
-
129
- def discover_dependencies_steps
130
- end
131
-
132
- def discover_deploy_steps
133
- end
134
-
135
- def discover_rollback_steps
136
- end
137
-
138
- def discover_fetch_deployed_revision_steps
139
- end
140
-
141
- def task_not_found!(id)
142
- raise TaskDefinition::NotFound.new("No definition for task #{id.inspect}")
143
- end
144
-
145
- def cant_detect!(type)
146
- raise DeploySpec::Error.new(I18n.t("deploy_spec.hint.#{type}"))
147
- end
148
- end
@@ -1,59 +0,0 @@
1
- class DeploySpec
2
- module BundlerDiscovery
3
- DEFAULT_BUNDLER_WITHOUT = %w(default production development test staging benchmark debug)
4
-
5
- def discover_dependencies_steps
6
- discover_bundler || super
7
- end
8
-
9
- def discover_bundler
10
- bundle_install if bundler?
11
- end
12
-
13
- def bundle_exec(command)
14
- return command unless bundler?
15
- "bundle exec #{command}"
16
- end
17
-
18
- def bundle_install
19
- bundle = %(bundle check --path=#{bundle_path} || bundle install #{frozen_flag} --path=#{bundle_path} --retry=2)
20
- bundle += " --without=#{bundler_without.join(':')}" unless bundler_without.empty?
21
- [remove_ruby_version_from_gemfile, bundle]
22
- end
23
-
24
- def remove_ruby_version_from_gemfile
25
- # Heroku apps often specify a ruby version.
26
- if /darwin/ =~ RUBY_PLATFORM
27
- # OSX is nitpicky about the -i.
28
- %q(sed -i '' '/^ruby\s/d' Gemfile)
29
- else
30
- %q(sed -i '/^ruby\s/d' Gemfile)
31
- end
32
- end
33
-
34
- def frozen_flag
35
- return unless gemfile_lock_exists?
36
- return if config('dependencies', 'bundler', 'frozen') == false
37
- '--frozen'
38
- end
39
-
40
- def bundler_without
41
- config('dependencies', 'bundler', 'without') || (gem? ? [] : DEFAULT_BUNDLER_WITHOUT)
42
- end
43
-
44
- def bundler?
45
- file('Gemfile').exist?
46
- end
47
-
48
- def gemfile_lock_exists?
49
- file('Gemfile.lock').exist?
50
- end
51
-
52
- def coerce_task_definition(config)
53
- return super unless bundler?
54
- config['steps'] ||= []
55
- config['steps'] = config['steps'].map(&method(:bundle_exec))
56
- config
57
- end
58
- end
59
- end