Class: Command::Run
Constant Summary collapse
- NAME =
"run"- USAGE =
"run COMMAND"- REQUIRES_ARGS =
true- DEFAULT_ARGS =
["bash"].freeze
- OPTIONS =
[ app_option(required: true), image_option, workload_option, use_local_token_option, terminal_size_option ].freeze
- DESCRIPTION =
"Runs one-off **_interactive_** replicas (analog of `heroku run`)"- LONG_DESCRIPTION =
<<~DESC - Runs one-off **_interactive_** replicas (analog of `heroku run`) - Uses `Standard` workload type and `cpln exec` as the execution method, with CLI streaming - May not work correctly with tasks that last over 5 minutes (there's a Control Plane scaling bug at the moment) - If `fix_terminal_size` is `true` in the `.controlplane/controlplane.yml` file, the remote terminal size will be fixed to match the local terminal size (may also be overriden through `--terminal-size`) > **IMPORTANT:** Useful for development where it's needed for interaction, and where network connection drops and > task crashing are tolerable. For production tasks, it's better to use `cpl run:detached`. DESC
- EXAMPLES =
<<~EX ```sh # Opens shell (bash by default). cpl run -a $APP_NAME # Need to quote COMMAND if setting ENV value or passing args. cpl run 'LOG_LEVEL=warn rails db:migrate' -a $APP_NAME # COMMAND may also be passed at the end (in this case, no need to quote). cpl run -a $APP_NAME -- rails db:migrate # Runs command, displays output, and exits shell. cpl run ls / -a $APP_NAME cpl run rails db:migrate:status -a $APP_NAME # Runs command and keeps shell open. cpl run rails c -a $APP_NAME # Uses a different image (which may not be promoted yet). cpl run rails db:migrate -a $APP_NAME --image appimage:123 # Exact image name cpl run rails db:migrate -a $APP_NAME --image latest # Latest sequential image # Uses a different workload than `one_off_workload` from `.controlplane/controlplane.yml`. cpl run bash -a $APP_NAME -w other-workload # Overrides remote CPLN_TOKEN env variable with local token. # Useful when superuser rights are needed in remote container. cpl run bash -a $APP_NAME --use-local-token ``` EX
Constants inherited from Base
Base::HIDE, Base::NO_IMAGE_AVAILABLE
Instance Attribute Summary collapse
-
#container ⇒ Object
readonly
Returns the value of attribute container.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#one_off ⇒ Object
readonly
Returns the value of attribute one_off.
-
#workload ⇒ Object
readonly
Returns the value of attribute workload.
Attributes inherited from Base
Instance Method Summary collapse
-
#call ⇒ Object
rubocop:disable Metrics/MethodLength.
Methods inherited from Base
all_commands, all_options, all_options_by_key_name, app_option, #args_join, commit_option, #cp, #ensure_workload_deleted, image_option, #initialize, #latest_image, #latest_image_from, #latest_image_next, org_option, #perform, #progress, skip_confirm_option, #step, #step_error, #step_finish, terminal_size_option, upstream_token_option, use_local_token_option, version_option, #wait_for_replica, #wait_for_workload, wait_option, workload_option
Constructor Details
This class inherits a constructor from Command::Base
Instance Attribute Details
#container ⇒ Object (readonly)
Returns the value of attribute container.
57 58 59 |
# File 'lib/command/run.rb', line 57 def container @container end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
57 58 59 |
# File 'lib/command/run.rb', line 57 def location @location end |
#one_off ⇒ Object (readonly)
Returns the value of attribute one_off.
57 58 59 |
# File 'lib/command/run.rb', line 57 def one_off @one_off end |
#workload ⇒ Object (readonly)
Returns the value of attribute workload.
57 58 59 |
# File 'lib/command/run.rb', line 57 def workload @workload end |
Instance Method Details
#call ⇒ Object
rubocop:disable Metrics/MethodLength
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/command/run.rb', line 59 def call # rubocop:disable Metrics/MethodLength @location = config[:default_location] @workload = config.["workload"] || config[:one_off_workload] @one_off = "#{workload}-run-#{rand(1000..9999)}" step("Cloning workload '#{workload}' on app '#{config.[:app]}' to '#{one_off}'") do clone_workload end wait_for_workload(one_off) wait_for_replica(one_off, location) run_in_replica ensure progress.puts ensure_workload_deleted(one_off) end |