Class: Kamal::Commands::Builder::Base

Inherits:
Kamal::Commands::Base show all
Defined in:
lib/kamal/commands/builder/base.rb

Direct Known Subclasses

Cloud, Local, Pack, Remote

Defined Under Namespace

Classes: BuilderError

Constant Summary collapse

ENDPOINT_DOCKER_HOST_INSPECT =
"'{{.Endpoints.docker.Host}}'"

Constants inherited from Kamal::Commands::Base

Kamal::Commands::Base::DOCKER_HEALTH_STATUS_FORMAT

Instance Attribute Summary

Attributes inherited from Kamal::Commands::Base

#config

Instance Method Summary collapse

Methods inherited from Kamal::Commands::Base

#container_id_for, #ensure_docker_installed, #initialize, #make_directory, #make_directory_for, #remove_directory, #remove_file, #run_over_ssh

Constructor Details

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

Instance Method Details

#build_contextObject



47
48
49
# File 'lib/kamal/commands/builder/base.rb', line 47

def build_context
  config.builder.context
end

#build_optionsObject



43
44
45
# File 'lib/kamal/commands/builder/base.rb', line 43

def build_options
  [ *build_cache, *build_labels, *build_args, *build_secrets, *build_dockerfile, *build_target, *build_ssh, *builder_provenance, *builder_sbom ]
end

#cleanObject



13
14
15
# File 'lib/kamal/commands/builder/base.rb', line 13

def clean
  docker :image, :rm, "--force", config.absolute_image
end

#first_mirrorObject



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

def first_mirror
  docker(:info, "--format '{{index .RegistryConfig.Mirrors 0}}'")
end

#infoObject



33
34
35
36
37
# File 'lib/kamal/commands/builder/base.rb', line 33

def info
  combine \
    docker(:context, :ls),
    docker(:buildx, :ls)
end

#inspect_builderObject



39
40
41
# File 'lib/kamal/commands/builder/base.rb', line 39

def inspect_builder
  docker :buildx, :inspect, builder_name unless docker_driver?
end

#login_to_registry_locally?Boolean

Returns:

  • (Boolean)


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

def 
  true
end

#pullObject



29
30
31
# File 'lib/kamal/commands/builder/base.rb', line 29

def pull
  docker :pull, config.absolute_image
end

#push(export_action = "registry", tag_as_dirty: false, no_cache: false) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/kamal/commands/builder/base.rb', line 17

def push(export_action = "registry", tag_as_dirty: false, no_cache: false)
  docker :buildx, :build,
    "--output=type=#{export_action}",
    *platform_options(arches),
    *([ "--builder", builder_name ] unless docker_driver?),
    *build_tag_options(tag_as_dirty: tag_as_dirty),
    *build_options,
    *([ "--no-cache" ] if no_cache),
    build_context,
    "2>&1"
end

#push_envObject



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

def push_env
  {}
end

#validate_imageObject



51
52
53
54
55
56
57
58
# File 'lib/kamal/commands/builder/base.rb', line 51

def validate_image
  pipe \
    docker(:inspect, "-f", "'{{ .Config.Labels.service }}'", config.absolute_image),
    any(
      [ :grep, "-x", config.service ],
      "(echo \"Image #{config.absolute_image} is missing the 'service' label\" && exit 1)"
    )
end