lib/command/run_detached.rb in cpl-1.0.2 vs lib/command/run_detached.rb in cpl-1.0.3
- old
+ new
@@ -6,11 +6,12 @@
USAGE = "run:detached COMMAND"
REQUIRES_ARGS = true
OPTIONS = [
app_option(required: true),
image_option,
- workload_option
+ workload_option,
+ use_local_token_option
].freeze
DESCRIPTION = "Runs one-off **_non-interactive_** replicas (close analog of `heroku run:detached`)"
LONG_DESCRIPTION = <<~DESC
- Runs one-off **_non-interactive_** replicas (close analog of `heroku run:detached`)
- Uses `Cron` workload type with log async fetching
@@ -26,22 +27,20 @@
cpl run:detached '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:detached -a $APP_NAME -- rails db:migrate
- # Uses some other image.
- cpl run:detached rails db:migrate -a $APP_NAME --image /some/full/image/path
-
- # Uses latest app image (which may not be promoted yet).
- cpl run:detached rails db:migrate -a $APP_NAME --image latest
-
# Uses a different image (which may not be promoted yet).
cpl run:detached rails db:migrate -a $APP_NAME --image appimage:123 # Exact image name
cpl run:detached 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:detached rails db:migrate:status -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:detached rails db:migrate:status -a $APP_NAME --use-local-token
```
EX
WORKLOAD_SLEEP_CHECK = 2
@@ -89,12 +88,12 @@
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"
- container_spec["image"] = image if image
+ image = latest_image if image == "latest"
+ container_spec["image"] = "/org/#{config.org}/image/#{image}"
# Set cron job props
spec["type"] = "cron"
spec["job"] = { "schedule" => "* * * * *", "restartPolicy" => "Never" }
spec["defaultOptions"]["autoscaling"] = {}
@@ -106,12 +105,18 @@
# Create workload clone
cp.apply("kind" => "workload", "name" => one_off, "spec" => spec)
end
- def runner_script
+ def runner_script # rubocop:disable Metrics/MethodLength
script = "echo '-- STARTED RUNNER SCRIPT --'\n"
script += Scripts.helpers_cleanup
+
+ if config.options["use_local_token"]
+ script += <<~SHELL
+ CPLN_TOKEN=$CONTROLPLANE_TOKEN
+ SHELL
+ end
script += <<~SHELL
if ! eval "#{args_join(config.args)}"; then echo "----- CRASHED -----"; fi
echo "-- FINISHED RUNNER SCRIPT, DELETING WORKLOAD --"