Class: Chagall::Deploy

Inherits:
Base
  • Object
show all
Defined in:
lib/chagall/deploy.rb

Constant Summary

Constants inherited from Base

Base::LOG_LEVELS

Instance Attribute Summary collapse

Attributes inherited from Base

#logger, #ssh

Instance Method Summary collapse

Instance Attribute Details

#total_timeObject (readonly)

Returns the value of attribute total_time.



10
11
12
# File 'lib/chagall/deploy.rb', line 10

def total_time
  @total_time
end

Instance Method Details

#check_image_or_buildObject



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/chagall/deploy.rb', line 38

def check_image_or_build
  image_exists = verify_image(check_only: true)

  if image_exists
    logger.info "Image #{@image_tag} exists and compose files are up to date"
    return
  end

  t("Building image") { build }
  t("Rotating cache") { rotate_cache }
  t("Verifying image") { verify_image }
end

#check_interruptedObject



73
74
75
76
77
78
# File 'lib/chagall/deploy.rb', line 73

def check_interrupted
  return unless @interrupted

  puts "Operation interrupted by user"
  cleanup_and_exit
end

#cleanup_and_exitObject



67
68
69
70
71
# File 'lib/chagall/deploy.rb', line 67

def cleanup_and_exit
  puts "Cleaning up..."
  # Add any cleanup tasks here
  exit 1
end

#executeObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/chagall/deploy.rb', line 12

def execute
  @interrupted = false
  @total_time = 0.0
  setup_signal_handlers

  # binding.irb

  t("Checking uncommitted changes") { check_uncommit_changes } unless Settings[:skip_uncommit]
  t("Check image or build") { check_image_or_build }
  t("Tag as production") { tag_as_production }
  t("Update compose files") { update_compose_files }
  t("Deploy compose files") { deploy_compose_files }
  t("Rotate release") { rotate_releases }

  print_total_time
rescue Interrupt
  logger.info "\nDeployment interrupted by user"
  print_total_time
  cleanup_and_exit
rescue StandardError => e
  logger.error "Deployment failed: #{e.message}"
  logger.debug e.backtrace.join("\n") if ENV["DEBUG"]
  print_total_time
  exit 1
end

#setup_signal_handlersObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/chagall/deploy.rb', line 51

def setup_signal_handlers
  # Handle CTRL+C (SIGINT)
  Signal.trap("INT") do
    @interrupted = true
    puts "\nReceived interrupt signal. Cleaning up..."
    cleanup_and_exit
  end

  # Handle SIGTERM
  Signal.trap("TERM") do
    @interrupted = true
    puts "\nReceived termination signal. Cleaning up..."
    cleanup_and_exit
  end
end