lib/command/run.rb in cpl-0.6.0 vs lib/command/run.rb in cpl-0.7.0
- old
+ new
@@ -8,26 +8,34 @@
DEFAULT_ARGS = ["bash"].freeze
OPTIONS = [
app_option(required: true),
image_option,
workload_option,
- use_local_token_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.
@@ -35,15 +43,15 @@
# 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
+ # 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 need superuser rights in remote container
+ # Useful when superuser rights are needed in remote container.
cpl run bash -a $APP_NAME --use-local-token
```
EX
attr_reader :location, :workload, :one_off, :container
@@ -82,11 +90,11 @@
# Ensure one-off workload will be running
spec["defaultOptions"]["suspend"] = false
# Ensure no scaling
spec["defaultOptions"]["autoscaling"]["minScale"] = 1
- spec["defaultOptions"]["autoscaling"]["minScale"] = 1
+ spec["defaultOptions"]["autoscaling"]["maxScale"] = 1
spec["defaultOptions"]["capacityAI"] = false
# Override image if specified
image = config.options[:image]
image = "/org/#{config.org}/image/#{latest_image}" if image == "latest"
@@ -102,17 +110,27 @@
# Create workload clone
cp.apply("kind" => "workload", "name" => one_off, "spec" => spec)
end
- def runner_script
+ def runner_script # rubocop:disable Metrics/MethodLength
script = Scripts.helpers_cleanup
if config.options["use_local_token"]
script += <<~SHELL
CPLN_TOKEN=$CONTROLPLANE_TOKEN
unset CONTROLPLANE_TOKEN
SHELL
+ end
+
+ # NOTE: fixes terminal size to match local terminal
+ if config.current[:fix_terminal_size] || config.options[:terminal_size]
+ if config.options[:terminal_size]
+ rows, cols = config.options[:terminal_size].split(",")
+ else
+ rows, cols = `stty -a`.match(/(\d+)\s*rows;\s*(\d+)\s*columns/).captures
+ end
+ script += "stty rows #{rows}\nstty cols #{cols}\n" if rows && cols
end
script += args_join(config.args)
script
end