feat: add support for customizing the remote in use for all commands sent via the official client
Closes #5564
This commit is contained in:
@@ -61,9 +61,13 @@ fn-dokku-host() {
|
||||
echo "$DOKKU_HOST"
|
||||
}
|
||||
|
||||
fn-get-remote() {
|
||||
git config dokku.remote 2>/dev/null || echo "dokku"
|
||||
}
|
||||
|
||||
main() {
|
||||
declare CMD="$1" APP_ARG="$2"
|
||||
local APP="" DOKKU_GIT_REMOTE="dokku" DOKKU_REMOTE_HOST=""
|
||||
local APP="" DOKKU_GIT_REMOTE="$(fn-get-remote)" DOKKU_REMOTE_HOST=""
|
||||
local cmd_set=false next_index=1 skip=false args=("$@")
|
||||
|
||||
for arg in "$@"; do
|
||||
@@ -100,7 +104,7 @@ main() {
|
||||
done
|
||||
|
||||
DOKKU_REMOTE_HOST="$(fn-dokku-host "$DOKKU_GIT_REMOTE" "$DOKKU_HOST")"
|
||||
if [[ -z "$DOKKU_REMOTE_HOST" ]]; then
|
||||
if [[ -z "$DOKKU_REMOTE_HOST" ]] && [[ "$CMD" != remote ]] && [[ "$CMD" != remote:* ]]; then
|
||||
fn-client-help-msg
|
||||
fi
|
||||
|
||||
@@ -143,6 +147,33 @@ main() {
|
||||
apps:destroy)
|
||||
fn-is-git-repo && fn-has-dokku-remote && git remote remove "$DOKKU_GIT_REMOTE"
|
||||
;;
|
||||
remote)
|
||||
echo "$DOKKU_GIT_REMOTE"
|
||||
exit 0
|
||||
;;
|
||||
remote:add)
|
||||
shift 1
|
||||
git remote add "$@"
|
||||
exit "$?"
|
||||
;;
|
||||
remote:list)
|
||||
git remote
|
||||
exit "$?"
|
||||
;;
|
||||
remote:set)
|
||||
shift 1
|
||||
git config dokku.remote "$@"
|
||||
exit "$?"
|
||||
;;
|
||||
remote:remove)
|
||||
shift 1
|
||||
git remote remove "$@"
|
||||
exit "$?"
|
||||
;;
|
||||
remote:unset)
|
||||
git config --unset dokku.remote
|
||||
exit "$?"
|
||||
;;
|
||||
esac
|
||||
|
||||
[[ " apps certs help ls nginx shell storage trace version " == *" $CMD "* ]] && unset APP
|
||||
|
||||
@@ -89,6 +89,22 @@ In addition, the following commands have special local side-effects:
|
||||
- `apps:destroy`:
|
||||
- Removes the local `dokku` git remote if set.
|
||||
|
||||
#### Specifying a remote
|
||||
|
||||
While many users will only ever push to a single dokku remote from a given repository, it may be useful to point the same repository at multiple remotes, especially in the case of pre-production environments. This can be done via the `remote` commands. These commands are _only_ available within the official remote client, and are not server-side commands.
|
||||
|
||||
To see your currently configured remote, run `dokku remote`. This will respect the `--remote` flag.
|
||||
|
||||
To list all available remotes, run `dokku remote:list`. This is equivalent to running `git remote`.
|
||||
|
||||
To add a remote, run `dokku remote:add $REMOTE_NAME dokku@dokku.me:$APP_NAME`, replacing `$REMOTE_NAME` with your desired remote name, the `$APP_NAME` with your desired app name and the host `dokku.me` with your Dokku host. This is equivalent to running `git remote add $REMOTE_NAME dokku@dokku.me:$APP_NAME`.
|
||||
|
||||
To remove a remote, run `dokku remote:remove $REMOTE_NAME`. This is equivalent to running `git remote remove $REMOTE_NAME`.
|
||||
|
||||
By default, the remote in use is `dokku`. To change the remote the client uses by default, run `dokku remote:set $REMOTE_NAME`, where `$REMOTE_NAME` is the name of your desired remote. This will not check the value specified, so that remote _must_ be available or errors will occur when running normal client commands. Note that specifying `--remote` when running dokku commands will override this configuration value.
|
||||
|
||||
To clear the configured remote, run `dokku remote:unset`. The client will unset the configured remote, and will default back to `dokku`, or the value of `--remote` if specified.
|
||||
|
||||
## Unofficial Clients
|
||||
|
||||
Please refer to the [community clients](/docs/community/clients.md) list for more details.
|
||||
|
||||
@@ -223,3 +223,75 @@ teardown() {
|
||||
assert_success
|
||||
done
|
||||
}
|
||||
|
||||
@test "(client) apps:create AND apps:destroy with name" {
|
||||
setup_client_repo
|
||||
local test_app_name=test-apps-create-with-name
|
||||
run /bin/bash -c "${BATS_TEST_DIRNAME}/../../contrib/dokku_client.sh apps:create $test_app_name"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "${BATS_TEST_DIRNAME}/../../contrib/dokku_client.sh remote"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "dokku"
|
||||
|
||||
run /bin/bash -c "${BATS_TEST_DIRNAME}/../../contrib/dokku_client.sh remote:list"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "dokku"
|
||||
|
||||
run /bin/bash -c "${BATS_TEST_DIRNAME}/../../contrib/dokku_client.sh remote:set dokku2"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "${BATS_TEST_DIRNAME}/../../contrib/dokku_client.sh remote"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "dokku2"
|
||||
|
||||
run /bin/bash -c "${BATS_TEST_DIRNAME}/../../contrib/dokku_client.sh remote:list"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "dokku"
|
||||
|
||||
run /bin/bash -c "${BATS_TEST_DIRNAME}/../../contrib/dokku_client.sh remote:add dokku2 dokku@dokku.me:dokku2"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "dokku2"
|
||||
|
||||
run /bin/bash -c "${BATS_TEST_DIRNAME}/../../contrib/dokku_client.sh remote:list"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "dokku\dokku2"
|
||||
|
||||
run /bin/bash -c "${BATS_TEST_DIRNAME}/../../contrib/dokku_client.sh remote:remove dokku2"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "${BATS_TEST_DIRNAME}/../../contrib/dokku_client.sh remote:list"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "dokku"
|
||||
|
||||
run /bin/bash -c "${BATS_TEST_DIRNAME}/../../contrib/dokku_client.sh remote:unset"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "${BATS_TEST_DIRNAME}/../../contrib/dokku_client.sh remote"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "dokku"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user