Method: Indocker::DeploymentProgress#log

Defined in:
lib/indocker/deployment_progress.rb

#logObject



246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
# File 'lib/indocker/deployment_progress.rb', line 246

def log
  return if !@logger
  system("clear")

  if @skip_build
    @logger.info("Warning: Image build is skipped for all containers".purple)
  end

  if @skip_deploy
    @logger.info("Warning: All container deployment is skipped".purple)
  end

  if @force_restart
    @logger.info("Warning: All containers will be force restarted".purple)
  end

  # BINARIES formatter
  synced_binaries_servers = []
  not_synced_binaries_servers = []

  @synced_binaries.each do |server, data|
    if data[:state] == :finished
      synced_binaries_servers << server
    else
      not_synced_binaries_servers << server
    end
  end

  if !synced_binaries_servers.empty?
    @logger.info("Binaries synced:".green)

    synced_binaries_servers.each do |server|
      data = @synced_binaries[server]
      total = ", total: #{(data[:finish] - data[:start]).round}s" if data[:finish]
      @logger.info("  - #{server.name.to_s.yellow}#{total}")
    end
  end

  if !not_synced_binaries_servers.empty?
    @logger.info("Binaries syncing:".green)

    not_synced_binaries_servers.each do |server|
      data = @synced_binaries[server]
      @logger.info("  - #{server.name.to_s.cyan} (#{data[:state]}...)")
    end
  end

  # ENV FILES formatter
  synced_env_files = []
  not_synced_env_files = []

  @synced_env_files.each do |env_file, server_info|
    server_info.each do |server, data|
      if data[:state] == :finished
        if !synced_env_files.include?(env_file)
          synced_env_files << env_file
        end
      else
        if !not_synced_env_files.include?(env_file)
          not_synced_env_files << env_file
        end
      end
    end
  end

  if !synced_env_files.empty?
    @logger.info("ENV files synced:".green)

    synced_env_files.each do |env_file|
      servers_data = @synced_env_files[env_file]

      servers_data.each do |server, data|
        next if data[:state] != :finished
        total = ", total: #{(data[:finish] - data[:start]).round}s" if data[:finish]
        @logger.info("  - #{env_file.to_s.yellow}, server: #{server.name}#{total}")
      end
    end
  end

  if !not_synced_env_files.empty?
    @logger.info("ENV files syncing:".green)

    not_synced_env_files.each do |env_file|
      servers_data = @synced_env_files[env_file]

      servers_data.each do |server, data|
        next if data[:state] == :finished
        @logger.info("  - #{env_file.to_s.cyan}, server: #{server.name} (#{data[:state]}...)")
      end
    end
  end

  # Artifacts formatter
  synced_artifact = []
  not_synced_artifact = []

  @synced_artifacts.each do |artifact, server_info|
    server_info.each do |server, data|
      if data[:state] == :finished
        if !synced_artifact.include?(artifact)
          synced_artifact << artifact
        end
      else
        if !not_synced_artifact.include?(artifact)
          not_synced_artifact << artifact
        end
      end
    end
  end

  if !synced_artifact.empty?
    @logger.info("Artifacts synced:".green)

    synced_artifact.each do |artifact|
      servers_data = @synced_artifacts[artifact]

      servers_data.each do |server, data|
        next if data[:state] != :finished
        total = ", total: #{(data[:finish] - data[:start]).round}s" if data[:finish]
        @logger.info("  - #{artifact.name.to_s.yellow}, server: #{server.name}#{total}")
      end
    end
  end

  if !not_synced_artifact.empty?
    @logger.info("Artifacts syncing:".green)

    not_synced_artifact.each do |artifact|
      servers_data = @synced_artifacts[artifact]

      servers_data.each do |server, data|
        next if data[:state] == :finished
        @logger.info("  - #{artifact.name.to_s.cyan}, server: #{server.name} (#{data[:state]}...)")
      end
    end
  end

  # REPOSITORIES formatter
  synced_repositories = []
  not_synced_repositories = []

  @synced_repositories.each do |repository, server_info|
    server_info.each do |server, data|
      if data[:state] == :finished
        if !synced_repositories.include?(repository)
          synced_repositories << repository
        end
      else
        if !not_synced_repositories.include?(repository)
          not_synced_repositories << repository
        end
      end
    end
  end

  if !synced_repositories.empty?
    @logger.info("Repositories synced:".green)

    synced_repositories.each do |repository|
      servers_data = @synced_repositories[repository]

      servers_data.each do |server, data|
        next if data[:state] != :finished
        total = ", total: #{(data[:finish] - data[:start]).round}s" if data[:finish]
        @logger.info("  - #{repository.to_s.yellow}, server: #{server.name}#{total}")
      end
    end
  end

  if !not_synced_repositories.empty?
    @logger.info("Repositories syncing:".green)

    not_synced_repositories.each do |repository|
      servers_data = @synced_repositories[repository]

      servers_data.each do |server, data|
        next if data[:state] == :finished
        @logger.info("  - #{repository.to_s.cyan}, server: #{server.name} (#{data[:state]}...)")
      end
    end
  end

  # Containers formatter
  deployed_containers = []
  not_deployed_containers = []

  @deployed_containers.each do |container, server_info|
    server_info.each do |server, data|
      if data[:state] == :finished
        if !deployed_containers.include?(container)
          deployed_containers << container
        end
      else
        if !not_deployed_containers.include?(container)
          not_deployed_containers << container
        end
      end
    end
  end

  if !deployed_containers.empty?
    @logger.info("Deployed containers:".green)

    deployed_containers = deployed_containers
      .sort_by { |container|
        @deployed_containers[container]
          .map { |server, data| data[:deploy_finish] }
          .reject(&:nil?)
          .sort
          .last
          .to_i
      }

    deployed_containers.each do |container|
      servers_data = @deployed_containers[container]

      servers_data.each do |server, data|
        next if data[:state] != :finished
        total = ", total: #{(data[:deploy_finish] - data[:build_start]).round}s"
        build = ", build: #{(data[:build_finish] - data[:build_start]).round}s"
        deploy = ", deploy: #{(data[:deploy_finish] - data[:deploy_start]).round}s"
        @logger.info("  - #{container.name.to_s.yellow}, server: #{server.name}#{build}#{deploy}#{total}")
      end
    end
  end

  if !not_deployed_containers.empty?
    @logger.info("To be deployed containers:".green)

    not_deployed_containers.each do |container|
      servers_data = @deployed_containers[container]

      servers_data.each do |server, data|
        next if data[:state] == :finished

        name = container.name.to_s

        name = if data[:state] == :waiting
          name
        else
          name.cyan
        end

        @logger.info("  - #{name}, server: #{server.name} (#{data[:state]}...)")
      end
    end
  end
end