mirror of
https://github.com/dokku/dokku.git
synced 2026-08-29 10:08:53 +02:00
The new exec callers somehow setup the environment differently, causing sed to not properly detect that it should run in unbuffered form. This change forces sed to run in unbuffered mode. Closes #6602
54 lines
1.7 KiB
Bash
Executable File
54 lines
1.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -eo pipefail
|
|
[[ $DOKKU_TRACE ]] && set -x
|
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
|
|
|
trigger-scheduler-docker-local-scheduler-logs() {
|
|
declare desc="scheduler-docker-local scheduler-logs plugin trigger"
|
|
declare trigger="scheduler-logs"
|
|
declare DOKKU_SCHEDULER="$1" APP="$2" CONTAINER_NAME="$3" TAIL="$4" PRETTY_PRINT="$5" NUM="$6"
|
|
local DOKKU_LOGS_ARGS=""
|
|
|
|
if [[ "$DOKKU_SCHEDULER" != "docker-local" ]]; then
|
|
return
|
|
fi
|
|
|
|
if [[ "$TAIL" == "true" ]]; then
|
|
DOKKU_LOGS_ARGS="--follow "
|
|
fi
|
|
|
|
local COLORS=(36 33 32 35 31)
|
|
|
|
if [[ -n "$CONTAINER_NAME" ]]; then
|
|
local CONTAINERS=("$CONTAINER_NAME")
|
|
else
|
|
local CONTAINERS=()
|
|
NAMES="$("$DOCKER_BIN" container ls --all --filter "label=com.dokku.app-name=$APP" --filter "label=com.dokku.container-type=run" --format '{{ .Names }}')"
|
|
while IFS= read -r CONTAINER_NAME; do
|
|
CONTAINERS+=("$CONTAINER_NAME")
|
|
done <<<"$NAMES"
|
|
fi
|
|
|
|
local DOKKU_LOGS_ARGS+="--tail $NUM"
|
|
((MAX_INDEX = ${#CONTAINERS[*]} - 1)) || true
|
|
for i in ${!CONTAINERS[*]}; do
|
|
local DYNO="$(echo "${CONTAINERS[i]}" | cut -d. -f3)"
|
|
local CID="${CONTAINERS[i]}"
|
|
local COLOR=${COLORS[i % ${#COLORS[*]}]}
|
|
if [[ $PRETTY_PRINT == "true" ]]; then
|
|
local DOKKU_LOGS_CMD+="($DOCKER_BIN logs $DOKKU_LOGS_ARGS $CID 2>&1)"
|
|
else
|
|
local DOKKU_LOGS_PRETTY_PRINT_CMD="sed -u -r 's/^([^Z]+Z )/\x1b[${COLOR}m\1app[$DYNO]:\x1b[0m /gm'"
|
|
local DOKKU_LOGS_CMD+="($DOCKER_BIN logs -t $DOKKU_LOGS_ARGS $CID 2>&1 | $DOKKU_LOGS_PRETTY_PRINT_CMD)"
|
|
fi
|
|
if [[ $i != "$MAX_INDEX" ]]; then
|
|
local DOKKU_LOGS_CMD+="& "
|
|
else
|
|
local DOKKU_LOGS_CMD+="; "
|
|
fi
|
|
done
|
|
bash -c "($DOKKU_LOGS_CMD)"
|
|
}
|
|
|
|
trigger-scheduler-docker-local-scheduler-logs "$@"
|