Class: Kamal::Commands::App

Inherits:
Base
  • Object
show all
Includes:
Assets, Containers, ErrorPages, Execution, Images, Logging, Proxy
Defined in:
lib/kamal/commands/app.rb

Defined Under Namespace

Modules: Assets, Containers, ErrorPages, Execution, Images, Logging, Proxy

Constant Summary collapse

ACTIVE_DOCKER_STATUSES =
[ :running, :restarting ]

Constants included from Containers

Containers::DOCKER_HEALTH_LOG_FORMAT

Constants inherited from Base

Base::DOCKER_HEALTH_STATUS_FORMAT

Instance Attribute Summary collapse

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods included from Assets

#clean_up_assets, #extract_assets, #sync_asset_volumes

Methods included from Containers

#container_health_log, #list_container_names, #list_containers, #remove_container, #remove_containers, #rename_container

Methods included from ErrorPages

#clean_up_error_pages, #create_error_pages_directory

Methods included from Execution

#execute_in_existing_container, #execute_in_existing_container_over_ssh, #execute_in_new_container, #execute_in_new_container_over_ssh

Methods included from Images

#list_images, #remove_images, #tag_latest_image

Methods included from Logging

#follow_logs, #logs

Methods included from Proxy

#create_ssl_directory, #deploy, #live, #maintenance, #remove, #remove_proxy_app_directory

Methods inherited from Base

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

Constructor Details

#initialize(config, role: nil, host: nil) ⇒ App

Returns a new instance of App.



10
11
12
13
14
# File 'lib/kamal/commands/app.rb', line 10

def initialize(config, role: nil, host: nil)
  super(config)
  @role = role
  @host = host
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



6
7
8
# File 'lib/kamal/commands/app.rb', line 6

def host
  @host
end

#roleObject (readonly)

Returns the value of attribute role.



6
7
8
# File 'lib/kamal/commands/app.rb', line 6

def role
  @role
end

Instance Method Details

#container_id_for_version(version, only_running: false) ⇒ Object



59
60
61
# File 'lib/kamal/commands/app.rb', line 59

def container_id_for_version(version, only_running: false)
  container_id_for(container_name: container_name(version), only_running: only_running)
end

#current_running_container_idObject



55
56
57
# File 'lib/kamal/commands/app.rb', line 55

def current_running_container_id
  current_running_container(format: "--quiet")
end

#current_running_versionObject



63
64
65
66
67
# File 'lib/kamal/commands/app.rb', line 63

def current_running_version
  pipe \
    current_running_container(format: "--format '{{.Names}}'"),
    extract_version_from_name
end

#ensure_env_directoryObject



75
76
77
# File 'lib/kamal/commands/app.rb', line 75

def ensure_env_directory
  make_directory role.env_directory
end

#infoObject



50
51
52
# File 'lib/kamal/commands/app.rb', line 50

def info
  docker :ps, *container_filter_args
end

#list_versions(*docker_args, statuses: nil) ⇒ Object



69
70
71
72
73
# File 'lib/kamal/commands/app.rb', line 69

def list_versions(*docker_args, statuses: nil)
  pipe \
    docker(:ps, *container_filter_args(statuses: statuses), *docker_args, "--format", '"{{.Names}}"'),
    extract_version_from_name
end

#run(hostname: nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/kamal/commands/app.rb', line 16

def run(hostname: nil)
  docker :run,
    "--detach",
    "--restart unless-stopped",
    "--name", container_name,
    "--network", "kamal",
    *([ "--hostname", hostname ] if hostname),
    "--env", "KAMAL_CONTAINER_NAME=\"#{container_name}\"",
    "--env", "KAMAL_VERSION=\"#{config.version}\"",
    "--env", "KAMAL_HOST=\"#{host}\"",
    *role.env_args(host),
    *role.logging_args,
    *config.volume_args,
    *role.asset_volume_args,
    *role.label_args,
    *role.option_args,
    config.absolute_image,
    role.cmd
end

#startObject



36
37
38
# File 'lib/kamal/commands/app.rb', line 36

def start
  docker :start, container_name
end

#status(version:) ⇒ Object



40
41
42
# File 'lib/kamal/commands/app.rb', line 40

def status(version:)
  pipe container_id_for_version(version), xargs(docker(:inspect, "--format", DOCKER_HEALTH_STATUS_FORMAT))
end

#stop(version: nil) ⇒ Object



44
45
46
47
48
# File 'lib/kamal/commands/app.rb', line 44

def stop(version: nil)
  pipe \
    version ? container_id_for_version(version) : current_running_container_id,
    xargs(docker(:stop, *role.stop_args))
end