Class: Kamal::Configuration::Builder

Inherits:
Object
  • Object
show all
Includes:
Validation
Defined in:
lib/kamal/configuration/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Validation

#validate!, #validation_yml

Constructor Details

#initialize(config:) ⇒ Builder

Returns a new instance of Builder.



8
9
10
11
12
13
14
15
16
# File 'lib/kamal/configuration/builder.rb', line 8

def initialize(config:)
  @config = config
  @builder_config = config.raw_config.builder || {}
  @image = config.image
  @server = config.registry.server
  @service = config.service

  validate! builder_config, with: Kamal::Configuration::Validator::Builder
end

Instance Attribute Details

#builder_configObject (readonly)

Returns the value of attribute builder_config.



4
5
6
# File 'lib/kamal/configuration/builder.rb', line 4

def builder_config
  @builder_config
end

#configObject (readonly)

Returns the value of attribute config.



4
5
6
# File 'lib/kamal/configuration/builder.rb', line 4

def config
  @config
end

Instance Method Details

#archesObject



26
27
28
# File 'lib/kamal/configuration/builder.rb', line 26

def arches
  Array(builder_config.fetch("arch", default_arch))
end

#argsObject



60
61
62
# File 'lib/kamal/configuration/builder.rb', line 60

def args
  builder_config["args"] || {}
end

#build_directoryObject



130
131
132
133
134
135
136
137
# File 'lib/kamal/configuration/builder.rb', line 130

def build_directory
  @build_directory ||=
    if git_clone?
      File.join clone_directory, repo_basename, repo_relative_pwd
    else
      "."
    end
end

#cache_fromObject



88
89
90
91
92
93
94
95
96
97
# File 'lib/kamal/configuration/builder.rb', line 88

def cache_from
  if cached?
    case builder_config["cache"]["type"]
    when "gha"
      cache_from_config_for_gha
    when "registry"
      cache_from_config_for_registry
    end
  end
end

#cache_toObject



99
100
101
102
103
104
105
106
107
108
# File 'lib/kamal/configuration/builder.rb', line 99

def cache_to
  if cached?
    case builder_config["cache"]["type"]
    when "gha"
      cache_to_config_for_gha
    when "registry"
      cache_to_config_for_registry
    end
  end
end

#cached?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/kamal/configuration/builder.rb', line 56

def cached?
  !!builder_config["cache"]
end

#clone_directoryObject



126
127
128
# File 'lib/kamal/configuration/builder.rb', line 126

def clone_directory
  @clone_directory ||= File.join Dir.tmpdir, "kamal-clones", [ service, pwd_sha ].compact.join("-")
end

#contextObject



76
77
78
# File 'lib/kamal/configuration/builder.rb', line 76

def context
  builder_config["context"] || "."
end

#docker_driver?Boolean

Returns:

  • (Boolean)


139
140
141
# File 'lib/kamal/configuration/builder.rb', line 139

def docker_driver?
  driver == "docker"
end

#dockerfileObject



68
69
70
# File 'lib/kamal/configuration/builder.rb', line 68

def dockerfile
  builder_config["dockerfile"] || "Dockerfile"
end

#driverObject



80
81
82
# File 'lib/kamal/configuration/builder.rb', line 80

def driver
  builder_config.fetch("driver", "docker-container")
end

#git_clone?Boolean

Returns:

  • (Boolean)


122
123
124
# File 'lib/kamal/configuration/builder.rb', line 122

def git_clone?
  Kamal::Git.used? && builder_config["context"].nil?
end

#local?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/kamal/configuration/builder.rb', line 52

def local?
  !local_disabled? && (arches.empty? || local_arches.any?)
end

#local_archesObject



30
31
32
33
34
35
36
37
38
# File 'lib/kamal/configuration/builder.rb', line 30

def local_arches
  @local_arches ||= if local_disabled?
    []
  elsif remote
    arches & [ Kamal::Utils.docker_arch ]
  else
    arches
  end
end

#local_disabled?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/kamal/configuration/builder.rb', line 84

def local_disabled?
  builder_config["local"] == false
end

#provenanceObject



114
115
116
# File 'lib/kamal/configuration/builder.rb', line 114

def provenance
  builder_config["provenance"]
end

#remoteObject



22
23
24
# File 'lib/kamal/configuration/builder.rb', line 22

def remote
  builder_config["remote"]
end

#remote?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/kamal/configuration/builder.rb', line 48

def remote?
  remote_arches.any?
end

#remote_archesObject



40
41
42
43
44
45
46
# File 'lib/kamal/configuration/builder.rb', line 40

def remote_arches
  @remote_arches ||= if remote
    arches - local_arches
  else
    []
  end
end

#sbomObject



118
119
120
# File 'lib/kamal/configuration/builder.rb', line 118

def sbom
  builder_config["sbom"]
end

#secretsObject



64
65
66
# File 'lib/kamal/configuration/builder.rb', line 64

def secrets
  (builder_config["secrets"] || []).to_h { |key| [ key, config.secrets[key] ] }
end

#sshObject



110
111
112
# File 'lib/kamal/configuration/builder.rb', line 110

def ssh
  builder_config["ssh"]
end

#targetObject



72
73
74
# File 'lib/kamal/configuration/builder.rb', line 72

def target
  builder_config["target"]
end

#to_hObject



18
19
20
# File 'lib/kamal/configuration/builder.rb', line 18

def to_h
  builder_config
end