这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/deployment/one-off-processes.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ The `run` command can be used to run a one-off process for a specific command. T
dokku run node-js-app ls -lah
```

The `run` command can also be used to run a command defined in your Procfile:

```
console: bundle exec racksh
```

```shell
# runs `bundle exec racksh` in the `/app` directory of the application `my-app`
dokku run my-app console
```

If you want to remove the container after a command has started, you can run the following command:

```shell
Expand Down
13 changes: 13 additions & 0 deletions plugins/00_dokku-standard/subcommands/run
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_CORE_AVAILABLE_PATH/ps/functions"
source "$PLUGIN_AVAILABLE_PATH/config/functions"

dokku_run_cmd() {
Expand All @@ -23,6 +24,18 @@ dokku_run_cmd() {
[[ "$DOKKU_RM_CONTAINER" ]] && local DOKKU_RUN_OPTS="--rm"
has_tty && local DOKKU_RUN_OPTS+=" -i -t"
is_image_herokuish_based "$IMAGE" && local EXEC_CMD="/exec"

DOKKU_QUIET_OUTPUT=1 extract_procfile "$APP"

POTENTIAL_PROCFILE_KEY="$1"
PROC_CMD=$(get_cmd_from_procfile "$APP" "$POTENTIAL_PROCFILE_KEY" || echo '')
remove_procfile "$APP"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm now cleaning up the Procfile after using it, just like deploy does.

It would be nice if get_cmd_from_procfile would take care of extracting the Procfile and cleaning it up. Potential downside of that is that if you would call it multiple times it would extract the Procfile every time, but the overhead of that is pretty small I think and also seems unlikely you would call this multiple times. What do you think @josegonzalez @michaelshobbs?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, I think this is fine as is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, this seems fine to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright fine be me :-)


if [ ! -z "$PROC_CMD" ]; then
dokku_log_info1 "Found '$POTENTIAL_PROCFILE_KEY' in Procfile, running that command"
set -- "$PROC_CMD" "${@:2}"
fi

# shellcheck disable=SC2086
docker run $DOKKU_GLOBAL_RUN_ARGS $DOKKU_RUN_OPTS $DOCKER_ARGS $IMAGE $EXEC_CMD "$@"
}
Expand Down
1 change: 1 addition & 0 deletions tests/apps/nodejs-express/Procfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
cron: node worker.js
web: node web.js
worker: node worker.js
custom: echo -n


# Old version with separate processes (use this if you have issues with the threaded version)
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/30_core_1.bats
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ build_nginx_config() {
assert_success
}

@test "(core) run command from Procfile" {
deploy_app
run /bin/bash -c "dokku run $TEST_APP custom 'hi dokku' | tail -n 1"
echo "output: "$output
echo "status: "$status

assert_success
assert_output 'hi dokku'
}

@test "(core) port exposure (dockerfile raw port)" {
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
cat<<EOF > $DOCKERFILE
Expand Down