Class: Kamal::Cli::Build

Inherits:
Base
  • Object
show all
Defined in:
lib/kamal/cli/build.rb

Defined Under Namespace

Classes: BuildError

Instance Method Summary collapse

Methods inherited from Base

exit_on_failure?, #initialize

Constructor Details

This class inherits a constructor from Kamal::Cli::Base

Instance Method Details

#createObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/kamal/cli/build.rb', line 59

def create
  mutating do
    if (remote_host = KAMAL.config.builder.remote_host)
      connect_to_remote_host(remote_host)
    end

    run_locally do
      begin
        debug "Using builder: #{KAMAL.builder.name}"
        execute *KAMAL.builder.create
      rescue SSHKit::Command::Failed => e
        if e.message =~ /stderr=(.*)/
          error "Couldn't create remote builder: #{$1}"
          false
        else
          raise
        end
      end
    end
  end
end

#deliverObject



7
8
9
10
11
12
# File 'lib/kamal/cli/build.rb', line 7

def deliver
  mutating do
    push
    pull
  end
end

#detailsObject



92
93
94
95
96
97
# File 'lib/kamal/cli/build.rb', line 92

def details
  run_locally do
    puts "Builder: #{KAMAL.builder.name}"
    puts capture(*KAMAL.builder.info)
  end
end

#pullObject



47
48
49
50
51
52
53
54
55
56
# File 'lib/kamal/cli/build.rb', line 47

def pull
  mutating do
    on(KAMAL.hosts) do
      execute *KAMAL.auditor.record("Pulled image with version #{KAMAL.config.version}"), verbosity: :debug
      execute *KAMAL.builder.clean, raise_on_non_zero_exit: false
      execute *KAMAL.builder.pull
      execute *KAMAL.builder.validate_image
    end
  end
end

#pushObject



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
44
# File 'lib/kamal/cli/build.rb', line 15

def push
  mutating do
    cli = self

    verify_local_dependencies
    run_hook "pre-build"

    if (uncommitted_changes = Kamal::Git.uncommitted_changes).present?
      say "The following paths have uncommitted changes:\n #{uncommitted_changes}", :yellow
    end

    run_locally do
      begin
        KAMAL.with_verbosity(:debug) do
          execute *KAMAL.builder.push
        end
      rescue SSHKit::Command::Failed => e
        if e.message =~ /(no builder)|(no such file or directory)/
          error "Missing compatible builder, so creating a new one first"

          if cli.create
            KAMAL.with_verbosity(:debug) { execute *KAMAL.builder.push }
          end
        else
          raise
        end
      end
    end
  end
end

#removeObject



82
83
84
85
86
87
88
89
# File 'lib/kamal/cli/build.rb', line 82

def remove
  mutating do
    run_locally do
      debug "Using builder: #{KAMAL.builder.name}"
      execute *KAMAL.builder.remove
    end
  end
end