这是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
8 changes: 4 additions & 4 deletions dokku
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,10 @@ case "$1" in
echo "Options:"

cat<<EOF | pluginhook commands help | sort
help Print the list of commands
plugins Print active plugins
plugins-install Install active plugins
plugins-update Update active plugins
help Print the list of commands
plugins Print active plugins
plugins-install Install active plugins
plugins-update Update active plugins
EOF
;;

Expand Down
12 changes: 6 additions & 6 deletions plugins/00_dokku-standard/commands
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,12 @@ case "$1" in

help)
cat && cat<<EOF
ls Pretty listing of deployed applications and containers
logs <app> [-t] Show the last logs for an application (-t follows)
run <app> <cmd> Run a command in the environment of an application
url <app> Show the first URL for an application (compatibility)
urls <app> Show all URLs for an application
version Print dokku's version
ls Pretty listing of deployed applications and containers
logs <app> [-t] Show the last logs for an application (-t follows)
run <app> <cmd> Run a command in the environment of an application
url <app> Show the first URL for an application (compatibility)
urls <app> Show all URLs for an application
version Print dokku's version
EOF
;;

Expand Down
8 changes: 4 additions & 4 deletions plugins/20_events/commands
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ case "$1" in

help | events:help)
cat && cat<<EOF
events [-t] Show the last events (-t follows)
events:list List logged events
events:on Enable events logger
events:off Disable events logger
events [-t] Show the last events (-t follows)
events:list List logged events
events:on Enable events logger
events:off Disable events logger
EOF
;;

Expand Down
6 changes: 3 additions & 3 deletions plugins/apps/commands
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ case "$1" in

help | apps:help)
cat && cat<<EOF
apps List your apps
apps:create <app> Create a new app
apps:destroy <app> Permanently destroy an app
apps List your apps
apps:create <app> Create a new app
apps:destroy <app> Permanently destroy an app
EOF
;;

Expand Down
4 changes: 2 additions & 2 deletions plugins/backup/commands
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ case "$1" in

help | backup:help)
cat && cat<<EOF
backup:export [file] Export dokku configuration files
backup:import [file] Import dokku configuration files
backup:export [file] Export dokku configuration files
backup:import [file] Import dokku configuration files
Copy link
Member

Choose a reason for hiding this comment

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

Lol when are these rando-spaces going away?

Copy link
Member Author

Choose a reason for hiding this comment

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

When you fix them, duh! 😈

EDIT: or when I do #1292

Copy link
Member

Choose a reason for hiding this comment

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

:D

EOF
;;

Expand Down
126 changes: 70 additions & 56 deletions plugins/config/commands
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$(dirname $0)/../common/functions"

ENV_FILE="$DOKKU_ROOT/$2/ENV"
ENV_FILE_TEMP="$DOKKU_ROOT/$2/ENV.tmp"
config_create () {
[ -f $ENV_FILE ] || {
touch $ENV_FILE
Expand All @@ -24,7 +22,7 @@ config_styled_hash () {

while read -r word; do
KEY=$(echo $word | cut -d"=" -f1)
VALUE=$(echo $word | cut -d"=" -f2- | sed -e "s/^'//" -e "s/'$//")
VALUE=$(echo $word | cut -d"=" -f2- | sed -e "s/^'//" -e "s/'$//" -e "s/\$$//g")
Copy link
Member Author

Choose a reason for hiding this comment

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

strips trailing $ from output of read -r


num_zeros=$((${#longest} - ${#KEY}))
zeros=" "
Expand All @@ -38,6 +36,8 @@ config_styled_hash () {

config_write() {
ENV_TEMP="$1"
ENV_FILE_TEMP="${ENV_FILE}.tmp"

echo "$ENV_TEMP" | sed '/^$/d' | sort > $ENV_FILE_TEMP
if ! cmp -s $ENV_FILE $ENV_FILE_TEMP; then
cp -f $ENV_FILE_TEMP $ENV_FILE
Expand All @@ -46,14 +46,43 @@ config_write() {
rm -f $ENV_FILE_TEMP
}

parse_config_args() {
case "$2" in
--global)
ENV_FILE="$DOKKU_ROOT/ENV"
DOKKU_CONFIG_TYPE="global"
DOKKU_CONFIG_RESTART=false
;;
--no-restart)
APP="$3"
ENV_FILE="$DOKKU_ROOT/$APP/ENV"
DOKKU_CONFIG_RESTART=false
DOKKU_CONFIG_TYPE="app"
set -- "${@:1:1}" "${@:3}"
Copy link
Member Author

Choose a reason for hiding this comment

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

removes $2 from $@. no need to do that in case of --global

esac

APP=${APP:="$2"}
ENV_FILE=${ENV_FILE:="$DOKKU_ROOT/$APP/ENV"}
DOKKU_CONFIG_TYPE=${DOKKU_CONFIG_TYPE:="app"}
DOKKU_CONFIG_RESTART=${DOKKU_CONFIG_RESTART:=true}

if [[ "$DOKKU_CONFIG_TYPE" = "app" ]]; then
if [[ -z $APP ]]; then
echo "Please specify an app to run the command on" >&2 && exit 1
else
verify_app_name "$2"
fi
fi
export APP ENV_FILE DOKKU_CONFIG_TYPE DOKKU_CONFIG_RESTART
}

case "$1" in
config)
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
verify_app_name "$2"
APP="$2"

parse_config_args "$@"
config_create
[[ ! -s $ENV_FILE ]] && echo "$APP has no config vars" && exit 1

[[ "$APP" ]] && DOKKU_CONFIG_TYPE=$APP
[[ ! -s $ENV_FILE ]] && echo "no config vars for $DOKKU_CONFIG_TYPE" && exit 1

VARS=$(grep -Eo "export ([a-zA-Z_][a-zA-Z0-9_]*=.*)" $ENV_FILE | cut -d" " -f2-)

Expand All @@ -64,14 +93,13 @@ case "$1" in
fi
done

dokku_log_info2_quiet "$APP config vars"

dokku_log_info2_quiet "$DOKKU_CONFIG_TYPE config vars"
config_styled_hash "$VARS"
;;

config:get)
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
verify_app_name "$2"
APP="$2"
parse_config_args "$@"

if [[ -z $3 ]]; then
echo "Usage: dokku config:get APP KEY"
Expand All @@ -90,26 +118,8 @@ case "$1" in
;;

config:set)
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
verify_app_name "$2"
APP="$2"

if [[ -z "${*:3}" ]]; then
echo "Usage: dokku config:set APP KEY1=VALUE1 [KEY2=VALUE2 ...]"
echo "Must specify KEY and VALUE to set."
exit 1
fi

shift 2
dokku config:set-norestart $APP "$@"
dokku_log_info1 "Restarting app $APP"
dokku ps:restart $APP
;;

config:set-norestart)
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
verify_app_name "$2"
APP="$2"
parse_config_args "$@"
[[ "$2" = "--no-restart" ]] && set -- "${@:1:1}" "${@:3}"
Copy link
Member Author

Choose a reason for hiding this comment

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

couldn't get around doing this again as parse_config_args is run in subshell, unless we have two functions (one to set env vars and one to echo new $@ and use it. meh...


if [[ -z "${*:3}" ]]; then
echo "Usage: dokku config:set APP KEY1=VALUE1 [KEY2=VALUE2 ...]"
Expand Down Expand Up @@ -153,29 +163,16 @@ ${var}"

config_write "$ENV_TEMP"
fi
;;

config:unset)
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
verify_app_name "$2"
APP="$2"

if [[ -z $3 ]]; then
echo "Usage: dokku config:unset APP KEY1 [KEY2 ...]"
echo "Must specify KEY to unset."
exit 1
if [[ "$DOKKU_CONFIG_RESTART" == "true" ]]; then
dokku_log_info1 "Restarting app $APP"
dokku ps:restart $APP
fi
;;

shift 2
dokku config:unset-norestart $APP "$@"
dokku_log_info1 "Restarting app $APP"
dokku ps:restart $APP
;;

config:unset-norestart)
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
verify_app_name "$2"
APP="$2"
config:unset)
parse_config_args "$@"
[[ "$2" = "--no-restart" ]] && set -- "${@:1:1}" "${@:3}"

if [[ -z $3 ]]; then
echo "Usage: dokku config:unset APP KEY1 [KEY2 ...]"
Expand All @@ -193,14 +190,31 @@ ${var}"

config_write "$ENV_TEMP"
done

if [[ "$DOKKU_CONFIG_RESTART" == "true" ]]; then
dokku_log_info1 "Restarting app $APP"
dokku ps:restart $APP
fi
;;

config:set-norestart)
dokku_log_info2 "$1 is deprecated as of v0.3.22"
shift 1
dokku config:set --no-restart "$@"
;;

config:unset-norestart)
dokku_log_info2 "$1 is deprecated as of v0.3.22"
shift 1
dokku config:unset --no-restart "$@"
;;

help | config:help)
cat && cat<<EOF
config <app> Display the config vars for an app
config:get <app> KEY Display a config value for an app
config:set <app> KEY1=VALUE1 [KEY2=VALUE2 ...] Set one or more config vars
config:unset <app> KEY1 [KEY2 ...] Unset one or more config vars
config (<app>|--global) Display all global or app-specific config vars
config:get (<app>|--global) KEY Display a global or app-specific config value
config:set (<app>|--global) KEY1=VALUE1 [KEY2=VALUE2 ...] Set one or more config vars
config:unset (<app>|--global) KEY1 [KEY2 ...] Unset one or more config vars
EOF
;;

Expand Down
8 changes: 4 additions & 4 deletions plugins/docker-options/commands
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ case "$1" in
# Display usage help
help)
cat && cat<<EOF
docker-options <app> Display apps docker options for all phases
docker-options <app> <phase(s)> Display apps docker options for phase (comma seperated phase list)
docker-options:add <app> <phase(s)> OPTION Add docker option to app for phase (comma seperated phase list)
docker-options:remove <app> <phase(s)> OPTION Remove docker option from app for phase (comma seperated phase list)
docker-options <app> Display apps docker options for all phases
docker-options <app> <phase(s)> Display apps docker options for phase (comma seperated phase list)
docker-options:add <app> <phase(s)> OPTION Add docker option to app for phase (comma seperated phase list)
docker-options:remove <app> <phase(s)> OPTION Remove docker option from app for phase (comma seperated phase list)
EOF
;;

Expand Down
8 changes: 4 additions & 4 deletions plugins/domains/commands
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ case "$1" in

help | domains:help)
cat && cat<<EOF
domains <app> List custom domains for app
domains:add <app> DOMAIN Add a custom domain to app
domains:clear <app> Clear all custom domains for app
domains:remove <app> DOMAIN Remove a custom domain from app
domains <app> List custom domains for app
domains:add <app> DOMAIN Add a custom domain to app
domains:clear <app> Clear all custom domains for app
domains:remove <app> DOMAIN Remove a custom domain from app
EOF
;;

Expand Down
4 changes: 2 additions & 2 deletions plugins/nginx-vhosts/commands
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ EOF

help | nginx:help)
cat && cat<<EOF
nginx:import-ssl <app> Imports a tarball from stdin; should contain server.crt and server.key
nginx:build-config <app> (Re)builds nginx config for given app
nginx:import-ssl <app> Imports a tarball from stdin; should contain server.crt and server.key
nginx:build-config <app> (Re)builds nginx config for given app
EOF
;;

Expand Down
16 changes: 8 additions & 8 deletions plugins/ps/commands
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ case "$1" in

help | ps:help)
cat && cat<<EOF
ps <app> List processes running in app container(s)
ps:scale <app> <proc>=<count> [<proc>=<count>] Set how many processes of a given process to run
ps:start <app> Start app container(s)
ps:stop <app> Stop app container(s)
ps:rebuild <app> Rebuild an app
ps:rebuildall Rebuild all apps
ps:restart <app> Restart app container(s)
ps:restartall Restart all deployed app containers
ps <app> List processes running in app container(s)
ps:scale <app> <proc>=<count> [<proc>=<count>] Set how many processes of a given process to run
ps:start <app> Start app container(s)
ps:stop <app> Stop app container(s)
ps:rebuild <app> Rebuild an app
ps:rebuildall Rebuild all apps
ps:restart <app> Restart app container(s)
ps:restartall Restart all deployed app containers
EOF
;;

Expand Down
2 changes: 1 addition & 1 deletion plugins/shell/commands
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ case "$1" in

help | shell:help)
cat && cat<<EOF
shell Spawn dokku shell
shell Spawn dokku shell
EOF
;;

Expand Down
44 changes: 43 additions & 1 deletion tests/unit/config.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,55 @@
load test_helper

setup() {
[[ -f $DOKKU_ROOT/ENV ]] && mv -f $DOKKU_ROOT/ENV $DOKKU_ROOT/ENV.bak
sudo -H -u dokku /bin/bash -c "echo 'export global_test=true' > $DOKKU_ROOT/ENV"
create_app
}

teardown() {
destroy_app
rm -f "$DOKKU_ROOT/ENV"
[[ -f $DOKKU_ROOT/ENV.bak ]] && mv -f $DOKKU_ROOT/ENV.bak $DOKKU_ROOT/ENV
}

@test "(config) config:set --global" {
run ssh dokku@dokku.me config:set --global test_var=true test_var2=\"hello world\"
echo "output: "$output
echo "status: "$status
assert_success
}

@test "(config) config:get --global" {
run ssh dokku@dokku.me config:set --global test_var=true test_var2=\"hello world\" test_var3=\"with\\nnewline\"
echo "output: "$output
echo "status: "$status
assert_success
run dokku config:get --global test_var2
echo "output: "$output
echo "status: "$status
assert_output 'hello world'
run dokku config:get --global test_var3
echo "output: "$output
echo "status: "$status
assert_output 'with\nnewline'
}

@test "(config) config:unset --global" {
run ssh dokku@dokku.me config:set --global test_var=true test_var2=\"hello world\"
echo "output: "$output
echo "status: "$status
assert_success
run dokku config:get --global test_var
echo "output: "$output
echo "status: "$status
assert_success
run dokku config:unset --global test_var
echo "output: "$output
echo "status: "$status
assert_success
run dokku config:get --global test_var
echo "output: "$output
echo "status: "$status
assert_output ""
}

@test "(config) config:set" {
Expand Down