Class: Kamal::Commands::App
- Defined in:
- lib/kamal/commands/app.rb
Defined Under Namespace
Modules: Assets, Containers, Cord, Execution, Images, Logging
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
- #info ⇒ Object
-
#initialize(config, role: nil, host: nil) ⇒ App
constructor
A new instance of App.
- #list_versions(*docker_args, statuses: nil) ⇒ Object
- #make_env_directory ⇒ Object
- #remove_env_file ⇒ 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 Cord
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 inherited from Base
#container_id_for, #make_directory, #make_directory_for, #remove_directory, #run_over_ssh
Constructor Details
#initialize(config, role: nil, host: nil) ⇒ App
Returns a new instance of App.
8 9 10 11 12 |
# File 'lib/kamal/commands/app.rb', line 8 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
56 57 58 |
# File 'lib/kamal/commands/app.rb', line 56 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
52 53 54 |
# File 'lib/kamal/commands/app.rb', line 52 def current_running_container_id current_running_container(format: "--quiet") end |
#current_running_version ⇒ Object
60 61 62 63 64 |
# File 'lib/kamal/commands/app.rb', line 60 def current_running_version pipe \ current_running_container(format: "--format '{{.Names}}'"), extract_version_from_name end |
#info ⇒ Object
47 48 49 |
# File 'lib/kamal/commands/app.rb', line 47 def info docker :ps, *filter_args end |
#list_versions(*docker_args, statuses: nil) ⇒ Object
66 67 68 69 70 |
# File 'lib/kamal/commands/app.rb', line 66 def list_versions(*docker_args, statuses: nil) pipe \ docker(:ps, *filter_args(statuses: statuses), *docker_args, "--format", '"{{.Names}}"'), extract_version_from_name end |
#make_env_directory ⇒ Object
73 74 75 |
# File 'lib/kamal/commands/app.rb', line 73 def make_env_directory make_directory role.env(host).secrets_directory end |
#remove_env_file ⇒ Object
77 78 79 |
# File 'lib/kamal/commands/app.rb', line 77 def remove_env_file [ :rm, "-f", role.env(host).secrets_file ] end |
#run(hostname: nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/kamal/commands/app.rb', line 14 def run(hostname: nil) docker :run, "--detach", "--restart unless-stopped", "--name", container_name, *([ "--hostname", hostname ] if hostname), "-e", "KAMAL_CONTAINER_NAME=\"#{container_name}\"", "-e", "KAMAL_VERSION=\"#{config.version}\"", *role.env_args(host), *role.health_check_args, *role.logging_args, *config.volume_args, *role.asset_volume_args, *role.label_args, *role.option_args, config.absolute_image, role.cmd end |
#start ⇒ Object
33 34 35 |
# File 'lib/kamal/commands/app.rb', line 33 def start docker :start, container_name end |
#status(version:) ⇒ Object
37 38 39 |
# File 'lib/kamal/commands/app.rb', line 37 def status(version:) pipe container_id_for_version(version), xargs(docker(:inspect, "--format", DOCKER_HEALTH_STATUS_FORMAT)) end |
#stop(version: nil) ⇒ Object
41 42 43 44 45 |
# File 'lib/kamal/commands/app.rb', line 41 def stop(version: nil) pipe \ version ? container_id_for_version(version) : current_running_container_id, xargs(config.stop_wait_time ? docker(:stop, "-t", config.stop_wait_time) : docker(:stop)) end |