Method: Kamal::Cli::App#boot

Defined in:
lib/kamal/cli/app.rb

#bootObject



3
4
5
6
7
8
9
10
11
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
37
38
39
40
41
42
43
# File 'lib/kamal/cli/app.rb', line 3

def boot
  with_lock do
    say "Get most recent version available as an image...", :magenta unless options[:version]
    using_version(version_or_latest) do |version|
      say "Start container with version #{version} (or reboot if already running)...", :magenta

      # Assets are prepared in a separate step to ensure they are on all hosts before booting
      on(KAMAL.app_hosts) do
        Kamal::Cli::App::ErrorPages.new(host, self).run

        KAMAL.roles_on(host).each do |role|
          Kamal::Cli::App::Assets.new(host, role, self).run
          Kamal::Cli::App::SslCertificates.new(host, role, self).run
        end
      end

      # Primary hosts and roles are returned first, so they can open the barrier
      barrier = Kamal::Cli::Healthcheck::Barrier.new

      host_boot_groups.each do |hosts|
        host_list = Array(hosts).join(",")
        run_hook "pre-app-boot", hosts: host_list

        on(hosts) do |host|
          KAMAL.roles_on(host).each do |role|
            Kamal::Cli::App::Boot.new(host, role, self, version, barrier).run
          end
        end

        run_hook "post-app-boot", hosts: host_list
        sleep KAMAL.config.boot.wait if KAMAL.config.boot.wait
      end

      # Tag once the app booted on all hosts
      on(KAMAL.app_hosts) do |host|
        execute *KAMAL.auditor.record("Tagging #{KAMAL.config.absolute_image} as the latest image"), verbosity: :debug
        execute *KAMAL.app.tag_latest_image
      end
    end
  end
end