Class: Kamal::Commands::App
- Defined in:
- lib/kamal/commands/app.rb
Defined Under Namespace
Modules: Assets, Containers, 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
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#role ⇒ Object
readonly
Returns the value of attribute role.
Attributes inherited from Base
Instance Method Summary collapse
- #container_id_for_version(version, only_running: false) ⇒ Object
- #current_running_container_id ⇒ Object
- #current_running_version ⇒ Object
- #ensure_env_directory ⇒ Object
- #info ⇒ Object
-
#initialize(config, role: nil, host: nil) ⇒ App
constructor
A new instance of App.
- #list_versions(*docker_args, statuses: nil) ⇒ Object
- #run(hostname: nil) ⇒ Object
- #start ⇒ Object
- #status(version:) ⇒ Object
- #stop(version: nil) ⇒ Object
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 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
Methods included from Proxy
Methods inherited from Base
#container_id_for, #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
#host ⇒ Object (readonly)
Returns the value of attribute host.
6 7 8 |
# File 'lib/kamal/commands/app.rb', line 6 def host @host end |
#role ⇒ Object (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
58 59 60 |
# File 'lib/kamal/commands/app.rb', line 58 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_id ⇒ Object
54 55 56 |
# File 'lib/kamal/commands/app.rb', line 54 def current_running_container_id current_running_container(format: "--quiet") end |
#current_running_version ⇒ Object
62 63 64 65 66 |
# File 'lib/kamal/commands/app.rb', line 62 def current_running_version pipe \ current_running_container(format: "--format '{{.Names}}'"), extract_version_from_name end |
#ensure_env_directory ⇒ Object
74 75 76 |
# File 'lib/kamal/commands/app.rb', line 74 def ensure_env_directory make_directory role.env_directory end |
#info ⇒ Object
49 50 51 |
# File 'lib/kamal/commands/app.rb', line 49 def info docker :ps, *filter_args end |
#list_versions(*docker_args, statuses: nil) ⇒ Object
68 69 70 71 72 |
# File 'lib/kamal/commands/app.rb', line 68 def list_versions(*docker_args, statuses: nil) pipe \ docker(:ps, *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 |
# 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), "-e", "KAMAL_CONTAINER_NAME=\"#{container_name}\"", "-e", "KAMAL_VERSION=\"#{config.version}\"", *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 |
#start ⇒ Object
35 36 37 |
# File 'lib/kamal/commands/app.rb', line 35 def start docker :start, container_name end |
#status(version:) ⇒ Object
39 40 41 |
# File 'lib/kamal/commands/app.rb', line 39 def status(version:) pipe container_id_for_version(version), xargs(docker(:inspect, "--format", DOCKER_HEALTH_STATUS_FORMAT)) end |
#stop(version: nil) ⇒ Object
43 44 45 46 47 |
# File 'lib/kamal/commands/app.rb', line 43 def stop(version: nil) pipe \ version ? container_id_for_version(version) : current_running_container_id, xargs(docker(:stop, *role.stop_args)) end |