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 =
"- Runs one-off **_interactive_** replicas (analog of `heroku run`)\n- Uses `Standard` workload type and `cpln exec` as the execution method, with CLI streaming\n- May not work correctly with tasks that last over 5 minutes (there's a Control Plane scaling bug at the moment)\n- 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`)\n\n> **IMPORTANT:** Useful for development where it's needed for interaction, and where network connection drops and\n> task crashing are tolerable. For production tasks, it's better to use `cpl run:detached`.\n"- EXAMPLES =
"```sh\n# Opens shell (bash by default).\ncpl run -a $APP_NAME\n\n# Need to quote COMMAND if setting ENV value or passing args.\ncpl run 'LOG_LEVEL=warn rails db:migrate' -a $APP_NAME\n\n# COMMAND may also be passed at the end (in this case, no need to quote).\ncpl run -a $APP_NAME -- rails db:migrate\n\n# Runs command, displays output, and exits shell.\ncpl run ls / -a $APP_NAME\ncpl run rails db:migrate:status -a $APP_NAME\n\n# Runs command and keeps shell open.\ncpl run rails c -a $APP_NAME\n\n# Uses a different image (which may not be promoted yet).\ncpl run rails db:migrate -a $APP_NAME --image appimage:123 # Exact image name\ncpl run rails db:migrate -a $APP_NAME --image latest # Latest sequential image\n\n# Uses a different workload than `one_off_workload` from `.controlplane/controlplane.yml`.\ncpl run bash -a $APP_NAME -w other-workload\n\n# Overrides remote CPLN_TOKEN env variable with local token.\n# Useful when superuser rights are needed in remote container.\ncpl run bash -a $APP_NAME --use-local-token\n```\n"
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.options[: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 |