prima-twig 0.58.3 → 0.58.500

Sign up to get free protection for your applications and to get access to all the features.
data/bin/twig-deploy CHANGED
@@ -5,7 +5,10 @@ require_relative '../lib/prima_twig.rb'
5
5
  require_relative '../lib/prima_aws_client.rb'
6
6
  require 'colorize'
7
7
  require 'highline/import'
8
- require 'aws-sdk'
8
+ require 'aws-sdk-batch'
9
+ require 'aws-sdk-cloudformation'
10
+ require 'aws-sdk-ecs'
11
+ require 'aws-sdk-s3'
9
12
  require 'redcarpet'
10
13
  require 'mail'
11
14
  require 'erb'
@@ -55,6 +58,7 @@ class Review
55
58
  @cf = Aws::CloudFormation::Client.new
56
59
  @ecs = Aws::ECS::Client.new
57
60
  @s3 = Aws::S3::Client.new
61
+ @batch = Aws::Batch::Client.new
58
62
  @s3_bucket = "prima-artifacts-encrypted"
59
63
  end
60
64
 
@@ -94,15 +98,6 @@ class Review
94
98
  artifact = artifacts.select {|v| v[:rev] == artifact_rev}.first
95
99
 
96
100
  do_deploy! artifact_rev
97
- # exec_step "terminal-notifier -message 'Deploy terminato, vuoi lanciare paparatzinger?'" if which 'terminal-notifier'
98
- #
99
- # confirm_message = "Vuoi lanciare paparatzinger?"
100
- # launch_paparatzinger = @prima.yesno confirm_message.blue
101
- #
102
- # if launch_paparatzinger
103
- # output "Avvio paparatzinger per gli screenshot".yellow
104
- # job_name = launch_paparatzinger(artifact[:commit_msg])
105
- # end
106
101
 
107
102
  mail = Mail.new do
108
103
  from 'deploy@prima.it'
@@ -118,7 +113,6 @@ class Review
118
113
  body << "Revision: [#{artifact[:rev]}](https://github.com/primait/prima/commit/#{artifact[:rev]}) del #{artifact[:created_at].strftime('%d/%m/%Y %H:%M:%S')}\n\n"
119
114
  body << "Branch: [#{artifact[:branch]}](https://github.com/primait/prima/tree/#{artifact[:branch]})\n\n"
120
115
  body << "Commit: #{commit_msg.gsub(/_/, '\_')}\n\n"
121
- #body << "Screenshots (tra qualche minuto): [BrowserStack](https://www.browserstack.com/automate) (Filtrare per: \"#{get_paparatzinger_job_name(commit_msg).gsub(/_/, '\_')}\")" if launch_paparatzinger
122
116
 
123
117
  htmlBody = Redcarpet::Markdown.new(Redcarpet::Render::HTML.new).render body
124
118
 
@@ -144,6 +138,8 @@ class Review
144
138
 
145
139
  invalidate_prismic_cache
146
140
 
141
+ launch_crawler
142
+
147
143
  exec_step "terminal-notifier -message 'Deploy terminato'" if which 'terminal-notifier'
148
144
  end
149
145
 
@@ -217,63 +213,16 @@ class Review
217
213
  artifacts.sort_by { |v| v[:created_at] }.reverse
218
214
  end
219
215
 
220
- def launch_paparatzinger(job_name)
221
- @s3.get_object(
222
- response_target: '/tmp/paparatzinger_twig.yml',
223
- bucket: 'prima-deploy',
224
- key: 'paparatzinger_twig.yml')
225
-
226
- paparatzinger_config = YAML.load_file '/tmp/paparatzinger_twig.yml'
227
-
228
- uri = URI.parse(paparatzinger_config['prima_api_search_url'])
229
- body = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
230
- req = Net::HTTP::Get.new(uri)
231
- req["x-apikey"] = paparatzinger_config['prima_api_token']
232
- response = http.request req
233
- response.body
234
- end
235
-
236
- saves = JSON.parse body
216
+ def launch_crawler()
217
+ resp = describe_stack_resource('batch-job-crawler-production', 'JobDefinition')
237
218
 
238
- save_code = saves.sample['unique_identifier']
239
- url_garanzie = "https://www.prima.it/preventivo/auto/#{save_code}/garanzie?browserstack=true"
240
- job_name = get_paparatzinger_job_name(clean_commit_message(job_name))
241
-
242
- logical_resource_id = 'TaskDefinitionPaparatzinger'
243
- resp = @cf.describe_stack_resource({
244
- stack_name: 'ecs-task-paparatzinger-production',
245
- logical_resource_id: logical_resource_id
246
- })
247
-
248
- resp = @ecs.run_task({
249
- cluster: 'ecs-cluster-tools-vpc-production-ECSCluster-1WJQLW5EVLYEB',
250
- task_definition: resp.stack_resource_detail.physical_resource_id,
251
- overrides: {
252
- container_overrides: [
253
- {
254
- name: 'paparatzinger',
255
- environment: [
256
- {
257
- name: 'JOB_NAME',
258
- value: job_name,
259
- },
260
- {
261
- name: 'VERSION',
262
- value: paparatzinger_config['version'],
263
- },
264
- {
265
- name: 'URL_GARANZIE',
266
- value: url_garanzie
267
- }
268
- ]
269
- }
270
- ]
271
- },
272
- count: 1
219
+ @batch.submit_job({
220
+ job_name: "crawler", # required
221
+ job_queue: "tools-production", # required
222
+ job_definition: resp.stack_resource_detail.physical_resource_id # required
273
223
  })
274
- output "Paparatzinger lanciato con successo. URL: #{url_garanzie}\n".green
275
224
 
276
- job_name
225
+ output "Crawler lanciato con successo!\n".green
277
226
  end
278
227
 
279
228
  end
@@ -285,10 +234,6 @@ def clean_commit_message(commit_msg)
285
234
  commit_msg[0..99]
286
235
  end
287
236
 
288
- def get_paparatzinger_job_name(job_name)
289
- job_name.gsub /[^0-9a-z]/i, '-'
290
- end
291
-
292
237
  def which(cmd)
293
238
  exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
294
239
  ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|