这是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
29 changes: 1 addition & 28 deletions plugins/00_dokku-standard/commands
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
[[ " build release trace delete ls logs run url urls version help " == *" $1 "* ]] || exit $DOKKU_NOT_IMPLEMENTED_EXIT
[[ " build release trace delete ls run url urls version help " == *" $1 "* ]] || exit $DOKKU_NOT_IMPLEMENTED_EXIT
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_AVAILABLE_PATH/config/functions"
Expand Down Expand Up @@ -126,32 +126,6 @@ case "$1" in
done
;;

logs)
[[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
APP="$2"; verify_app_name "$2"

if (is_deployed $APP); then
CONTAINER_IDS=( $(get_app_container_ids $APP) )
LAST_CONTAINER_ID=${CONTAINER_IDS[${#CONTAINER_IDS[@]} - 1]}

if [[ $3 == "-t" ]]; then
DOKKU_LOGS_ARGS="--follow --tail 100"
else
DOKKU_LOGS_ARGS="--tail 100"
fi
for CID in "${CONTAINER_IDS[@]}"; do
if [[ "$CID" != "$LAST_CONTAINER_ID" ]]; then
DOKKU_LOGS_CMD+="docker logs $DOKKU_LOGS_ARGS $CID& "
else
DOKKU_LOGS_CMD+="docker logs $DOKKU_LOGS_ARGS $CID; "
fi
done
bash -c "($DOKKU_LOGS_CMD)"
else
echo "Application's container not found"
fi
;;

run)
[[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
APP="$2"; IMAGE_TAG=$(get_running_image_tag $APP); IMAGE=$(get_app_image_name $APP $IMAGE_TAG)
Expand Down Expand Up @@ -217,7 +191,6 @@ case "$1" in
help)
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
Expand Down
49 changes: 49 additions & 0 deletions plugins/logs/commands
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_AVAILABLE_PATH/config/functions"
source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/functions"

case "$1" in
logs)
[[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
APP="$2"; verify_app_name "$2"
APP_ROOT="$DOKKU_ROOT/$APP"
COLORS=(36 33 32 35 31)

if (is_deployed "$APP"); then
CONTAINERS=("$APP_ROOT"/CONTAINER.*)
if [[ $3 == "-t" ]]; then
DOKKU_LOGS_ARGS="--follow --tail 100"
else
DOKKU_LOGS_ARGS="--tail 100"
fi
((MAX_INDEX=${#CONTAINERS[*]} - 1)) || true
for i in ${!CONTAINERS[*]}; do
DYNO=$(echo "${CONTAINERS[i]}" | sed -r 's/.*CONTAINER\.(.*)/\1/')
CID=$(< "${CONTAINERS[i]}")
COLOR=${COLORS[i % ${#COLORS[*]}]}
DOKKU_LOGS_CMD+="(docker logs -t $DOKKU_LOGS_ARGS $CID 2>&1 | sed -r 's/^([^Z]+Z )/\x1b[${COLOR}m\1$APP[$DYNO]:\x1b[0m /gm')"
if [[ $i != "$MAX_INDEX" ]]; then
DOKKU_LOGS_CMD+="& "
else
DOKKU_LOGS_CMD+="; "
fi
done
bash -c "($DOKKU_LOGS_CMD)"
else
echo "Application's container not found"
fi
;;

help)
cat<<EOF
logs <app> [-t], Show the last logs for an application (-t follows)
EOF
;;

*)
exit $DOKKU_NOT_IMPLEMENTED_EXIT
;;

esac
4 changes: 4 additions & 0 deletions plugins/logs/plugin.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[plugin]
description = "dokku core logs plugin"
version = "0.4.0"
[plugin.config]