Skip to content

Commit abbb3b6

Browse files
Updates to run command (#151)
* test: fix duplicate apps deletion during cleanup * feat: raise error if no value is provided for a non-boolean option * feat: add option to delete specific workload to delete command * feat: add options to use different limit on number of entries and loopback window to logs command * feat: add option to display logs for specific replica to logs command * feat: add option to stop specific replica to ps:stop command * feat: improve run command * feat: improve handling of commands that accept extra options * feat: run release script in context of run command * fix: use exact same image as original workload by default * fix: wait for runner workload to be updated before starting job * chore: add note regarding stty size * test: update specs * fix: add delay before starting job if image changed * More log drain variants * Add log_method option, cleanup * Fix Kernel.system orphan process handling
1 parent d757dbc commit abbb3b6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1302
-1163
lines changed

README.md

+5-9
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ aliases:
183183

184184
# Control Plane offers the ability to use multiple locations.
185185
# default_location is used for commands that require a location
186-
# including `ps`, `run`, `run:detached`, `apply-template`.
186+
# including `ps`, `run`, `apply-template`.
187187
# This can be overridden with option --location=<location> and
188188
# CPLN_LOCATION environment variable.
189189
default_location: aws-us-east-2
@@ -215,15 +215,15 @@ aliases:
215215

216216
# Workloads that are for the application itself and are using application Docker images.
217217
# These are updated with the new image when running the `deploy-image` command,
218-
# and are also used by the `info`, `ps:`, and `run:cleanup` commands in order to get all of the defined workloads.
218+
# and are also used by the `info` and `ps:` commands in order to get all of the defined workloads.
219219
# On the other hand, if you have a workload for Redis, that would NOT use the application Docker image
220220
# and not be listed here.
221221
app_workloads:
222222
- rails
223223
- sidekiq
224224

225225
# Additional "service type" workloads, using non-application Docker images.
226-
# These are only used by the `info`, `ps:` and `run:cleanup` commands in order to get all of the defined workloads.
226+
# These are only used by the `info` and `ps:` commands in order to get all of the defined workloads.
227227
additional_workloads:
228228
- redis
229229
- postgres
@@ -233,7 +233,7 @@ aliases:
233233
maintenance_workload: maintenance
234234

235235
# Fixes the remote terminal size to match the local terminal size
236-
# when running the commands `cpl run` or `cpl run:detached`.
236+
# when running `cpl run`.
237237
fix_terminal_size: true
238238

239239
# Apps with a deployed image created before this amount of days will be listed for deletion
@@ -248,10 +248,6 @@ aliases:
248248
# when running the command `cpl cleanup-images` (`image_retention_max_qty` takes precedence).
249249
image_retention_days: 5
250250

251-
# Run workloads created before this amount of days will be listed for deletion
252-
# when running the command `cpl run:cleanup`.
253-
stale_run_workload_created_days: 2
254-
255251
apps:
256252
my-app-staging:
257253
# Use the values from the common section above.
@@ -336,7 +332,7 @@ cpl build-image -a tutorial-app
336332
# Run database migrations (or other release tasks) with the latest image,
337333
# while the app is still running on the previous image.
338334
# This is analogous to the release phase.
339-
cpl run:detached rails db:migrate -a tutorial-app --image latest
335+
cpl run -a tutorial-app --image latest -- rails db:migrate
340336

341337
# Pomote the latest image to the app.
342338
cpl deploy-image -a tutorial-app

docs/commands.md

+53-53
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,22 @@ cpl copy-image-from-upstream -a $APP_NAME --upstream-token $UPSTREAM_TOKEN --ima
105105

106106
### `delete`
107107

108-
- Deletes the whole app (GVC with all workloads, all volumesets and all images)
108+
- Deletes the whole app (GVC with all workloads, all volumesets and all images) or a specific workload
109109
- Will ask for explicit user confirmation
110110

111111
```sh
112+
# Deletes the whole app (GVC with all workloads, all volumesets and all images).
112113
cpl delete -a $APP_NAME
114+
115+
# Deletes a specific workload.
116+
cpl delete -a $APP_NAME -w $WORKLOAD_NAME
113117
```
114118

115119
### `deploy-image`
116120

117121
- Deploys the latest image to app workloads
118122
- Optionally runs a release script before deploying if specified through `release_script` in the `.controlplane/controlplane.yml` file and `--run-release-phase` is provided
123+
- The release script is run in the context of `cpl run` with the latest image
119124
- The deploy will fail if the release script exits with a non-zero code or doesn't exist
120125

121126
```sh
@@ -177,13 +182,23 @@ cpl latest-image -a $APP_NAME
177182
### `logs`
178183
179184
- Light wrapper to display tailed raw logs for app/workload syntax
185+
- Defaults to showing the last 200 entries from the past 1 hour before tailing
180186
181187
```sh
182188
# Displays logs for the default workload (`one_off_workload`).
183189
cpl logs -a $APP_NAME
184190
185191
# Displays logs for a specific workload.
186192
cpl logs -a $APP_NAME -w $WORKLOAD_NAME
193+
194+
# Displays logs for a specific replica of a workload.
195+
cpl logs -a $APP_NAME -w $WORKLOAD_NAME -r $REPLICA_NAME
196+
197+
# Uses a different limit on number of entries.
198+
cpl logs -a $APP_NAME --limit 100
199+
200+
# Uses a different loopback window.
201+
cpl logs -a $APP_NAME --since 30min
187202
```
188203
189204
### `maintenance`
@@ -311,6 +326,9 @@ cpl ps:stop -a $APP_NAME
311326
312327
# Stops a specific workload in app.
313328
cpl ps:stop -a $APP_NAME -w $WORKLOAD_NAME
329+
330+
# Stops a specific replica of a workload.
331+
cpl ps:stop -a $APP_NAME -w $WORKLOAD_NAME -r $REPLICA_NAME
314332
```
315333
316334
### `ps:wait`
@@ -327,26 +345,43 @@ cpl ps:swait -a $APP_NAME -w $WORKLOAD_NAME
327345
328346
### `run`
329347
330-
- Runs one-off **_interactive_** replicas (analog of `heroku run`)
331-
- Uses `Standard` workload type and `cpln exec` as the execution method, with CLI streaming
332-
- 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`)
333-
334-
> **IMPORTANT:** Useful for development where it's needed for interaction, and where network connection drops and
335-
> task crashing are tolerable. For production tasks, it's better to use `cpl run:detached`.
348+
- Runs one-off interactive or non-interactive replicas (analog of `heroku run`)
349+
- Uses `Cron` workload type and either:
350+
- - `cpln workload exec` for interactive mode, with CLI streaming
351+
- - log async fetching for non-interactive mode
352+
- The Dockerfile entrypoint is used as the command by default, which assumes `exec "${@}"` to be present,
353+
and the args ["bash", "-c", cmd_to_run] are passed
354+
- The entrypoint can be overriden through `--entrypoint`, which must be a single command or a script path that exists in the container,
355+
and the args ["bash", "-c", cmd_to_run] are passed,
356+
unless the entrypoint is `bash`, in which case the args ["-c", cmd_to_run] are passed
357+
- Providing `--entrypoint none` sets the entrypoint to `bash` by default
358+
- If `fix_terminal_size` is `true` in the `.controlplane/controlplane.yml` file,
359+
the remote terminal size will be fixed to match the local terminal size (may also be overriden through `--terminal-size`)
336360
337361
```sh
338362
# Opens shell (bash by default).
339363
cpl run -a $APP_NAME
340364
341-
# Need to quote COMMAND if setting ENV value or passing args.
342-
cpl run -a $APP_NAME -- 'LOG_LEVEL=warn rails db:migrate'
365+
# Runs interactive command, keeps shell open, and stops job when exiting.
366+
cpl run -a $APP_NAME --interactive -- rails c
343367
344-
# Runs command, displays output, and exits shell.
345-
cpl run -a $APP_NAME -- ls /
346-
cpl run -a $APP_NAME -- rails db:migrate:status
368+
# Some commands are automatically detected as interactive, so no need to pass `--interactive`.
369+
cpl run -a $APP_NAME -- bash
370+
cpl run -a $APP_NAME -- rails console
371+
cpl run -a $APP_NAME -- rails c
372+
cpl run -a $APP_NAME -- rails dbconsole
373+
cpl run -a $APP_NAME -- rails db
347374
348-
# Runs command and keeps shell open.
349-
cpl run -a $APP_NAME -- rails c
375+
# Runs non-interactive command, outputs logs, exits with the exit code of the command and stops job.
376+
cpl run -a $APP_NAME -- rails db:migrate
377+
378+
# Runs non-iteractive command, detaches, exits with 0, and prints commands to:
379+
# - see logs from the job
380+
# - stop the job
381+
cpl run -a $APP_NAME --detached -- rails db:migrate
382+
383+
# The command needs to be quoted if setting an env variable or passing args.
384+
cpl run -a $APP_NAME -- 'SOME_ENV_VAR=some_value rails db:migrate'
350385
351386
# Uses a different image (which may not be promoted yet).
352387
cpl run -a $APP_NAME --image appimage:123 -- rails db:migrate # Exact image name
@@ -358,47 +393,12 @@ cpl run -a $APP_NAME -w other-workload -- bash
358393
# Overrides remote CPLN_TOKEN env variable with local token.
359394
# Useful when superuser rights are needed in remote container.
360395
cpl run -a $APP_NAME --use-local-token -- bash
361-
```
362-
363-
### `run:cleanup`
364-
365-
- Deletes stale run workloads for an app
366-
- Workloads are considered stale based on how many days since created
367-
- `stale_run_workload_created_days` in the `.controlplane/controlplane.yml` file specifies the number of days after created that the workload is considered stale
368-
- Works for both interactive workloads (created with `cpl run`) and non-interactive workloads (created with `cpl run:detached`)
369-
- Will ask for explicit user confirmation of deletion
370-
371-
```sh
372-
cpl run:cleanup -a $APP_NAME
373-
```
374-
375-
### `run:detached`
376-
377-
- Runs one-off **_non-interactive_** replicas (close analog of `heroku run:detached`)
378-
- Uses `Cron` workload type with log async fetching
379-
- Implemented with only async execution methods, more suitable for production tasks
380-
- Has alternative log fetch implementation with only JSON-polling and no WebSockets
381-
- Less responsive but more stable, useful for CI tasks
382-
- Deletes the workload whenever finished with success
383-
- Deletes the workload whenever finished with failure by default
384-
- Use `--no-clean-on-failure` to disable cleanup to help with debugging failed runs
385-
386-
```sh
387-
cpl run:detached rails db:prepare -a $APP_NAME
388396
389-
# Need to quote COMMAND if setting ENV value or passing args.
390-
cpl run:detached -a $APP_NAME -- 'LOG_LEVEL=warn rails db:migrate'
397+
# Replaces the existing Dockerfile entrypoint with `bash`.
398+
cpl run -a $APP_NAME --entrypoint none -- rails db:migrate
391399
392-
# Uses a different image (which may not be promoted yet).
393-
cpl run:detached -a $APP_NAME --image appimage:123 -- rails db:migrate # Exact image name
394-
cpl run:detached -a $APP_NAME --image latest -- rails db:migrate # Latest sequential image
395-
396-
# Uses a different workload than `one_off_workload` from `.controlplane/controlplane.yml`.
397-
cpl run:detached -a $APP_NAME -w other-workload -- rails db:migrate:status
398-
399-
# Overrides remote CPLN_TOKEN env variable with local token.
400-
# Useful when superuser rights are needed in remote container.
401-
cpl run:detached -a $APP_NAME --use-local-token -- rails db:migrate:status
400+
# Replaces the existing Dockerfile entrypoint.
401+
cpl run -a $APP_NAME --entrypoint /app/alternative-entrypoint.sh -- rails db:migrate
402402
```
403403
404404
### `setup-app`

docs/migrating.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ cpl setup-app -a my-app-staging
9393
cpl build-image -a my-app-staging --commit 456
9494
9595
# Prepare database.
96-
cpl run:detached -a my-app-staging --image latest -- rails db:prepare
96+
cpl run -a my-app-staging --image latest -- rails db:prepare
9797
9898
# Deploy latest image.
9999
cpl deploy-image -a my-app-staging
@@ -113,7 +113,7 @@ cpl build-image -a my-app-staging --commit ABC
113113
114114
# Run database migrations (or other release tasks) with latest image, while app is still running on previous image.
115115
# This is analogous to the release phase.
116-
cpl run:detached -a my-app-staging --image latest -- rails db:migrate
116+
cpl run -a my-app-staging --image latest -- rails db:migrate
117117
118118
# Deploy latest image.
119119
cpl deploy-image -a my-app-staging
@@ -215,9 +215,9 @@ fi
215215

216216
# The `NEW_APP` env var that we exported above can be used to either reset or migrate the database before deploying.
217217
if [ -n "${NEW_APP}" ]; then
218-
cpl run:detached 'LOG_LEVEL=warn rails db:reset' -a ${APP_NAME} --image latest
218+
cpl run -a ${APP_NAME} --image latest -- rails db:reset
219219
else
220-
cpl run:detached 'LOG_LEVEL=warn rails db:migrate_and_wait_replica' -a ${APP_NAME} --image latest
220+
cpl run -a ${APP_NAME} --image latest -- rails db:migrate
221221
fi
222222
```
223223

examples/circleci.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ build-staging:
2727
command: cpl build-image -a ${APP_NAME}
2828
- run:
2929
name: Database tasks
30-
command: cpl run:detached -a ${APP_NAME} --image latest -- rails db:migrate
30+
command: cpl run -a ${APP_NAME} --image latest -- rails db:migrate
3131
- run:
3232
name: Deploy image
3333
command: cpl deploy-image -a ${APP_NAME}
@@ -75,9 +75,9 @@ build-review-app:
7575
name: Database tasks
7676
command: |
7777
if [ -n "${NEW_APP}" ]; then
78-
cpl run:detached -a ${APP_NAME} --image latest -- LOG_LEVEL=warn rails db:reset
78+
cpl run -a ${APP_NAME} --image latest -- rails db:reset
7979
else
80-
cpl run:detached -a ${APP_NAME} --image latest -- LOG_LEVEL=warn rails db:migrate
80+
cpl run -a ${APP_NAME} --image latest -- rails db:migrate
8181
fi
8282
- run:
8383
name: Deploy image

examples/controlplane.yml

+4-8
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ aliases:
1717

1818
# Control Plane offers the ability to use multiple locations.
1919
# default_location is used for commands that require a location
20-
# including `ps`, `run`, `run:detached`, `apply-template`.
20+
# including `ps`, `run`, `apply-template`.
2121
# This can be overridden with option --location=<location> and
2222
# CPLN_LOCATION environment variable.
2323
# TODO: Allow specification of multiple locations.
@@ -50,15 +50,15 @@ aliases:
5050

5151
# Workloads that are for the application itself and are using application Docker images.
5252
# These are updated with the new image when running the `deploy-image` command,
53-
# and are also used by the `info`, `ps:`, and `run:cleanup` commands in order to get all of the defined workloads.
53+
# and are also used by the `info` and `ps:` commands in order to get all of the defined workloads.
5454
# On the other hand, if you have a workload for Redis, that would NOT use the application Docker image
5555
# and not be listed here.
5656
app_workloads:
5757
- rails
5858
- sidekiq
5959

6060
# Additional "service type" workloads, using non-application Docker images.
61-
# These are only used by the `info`, `ps:` and `run:cleanup` commands in order to get all of the defined workloads.
61+
# These are only used by the `info` and `ps:` commands in order to get all of the defined workloads.
6262
additional_workloads:
6363
- redis
6464
- postgres
@@ -68,7 +68,7 @@ aliases:
6868
maintenance_workload: maintenance
6969

7070
# Fixes the remote terminal size to match the local terminal size
71-
# when running the commands `cpl run` or `cpl run:detached`.
71+
# when running `cpl run`.
7272
fix_terminal_size: true
7373

7474
# Apps with a deployed image created before this amount of days will be listed for deletion
@@ -83,10 +83,6 @@ aliases:
8383
# when running the command `cpl cleanup-images` (`image_retention_max_qty` takes precedence).
8484
image_retention_days: 5
8585

86-
# Run workloads created before this amount of days will be listed for deletion
87-
# when running the command `cpl run:cleanup`.
88-
stale_run_workload_created_days: 2
89-
9086
apps:
9187
my-app-staging:
9288
# Use the values from the common section above.

0 commit comments

Comments
 (0)