From 7d00e2c422d8d4b1ba2becd233b763fa5d0f4792 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Thu, 14 Mar 2024 08:00:26 -0400 Subject: [PATCH] feat: implement builds:output This still needs tightening to ensure we don't trigger this for normal git plugin commands - as well as anything that triggers a deploy - but works in a pinch. --- dokku | 4 ++++ plugins/builds/subcommands/cancel | 2 +- plugins/builds/subcommands/output | 33 +++++++++++++++++++++---------- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/dokku b/dokku index 60caaa6e2..b6912a8e5 100755 --- a/dokku +++ b/dokku @@ -188,6 +188,10 @@ execute_dokku_cmd() { set -- "$PLUGIN_CMD" "$@" fi + if [[ $PLUGIN_NAME =~ git-* ]] || [[ $PLUGIN_NAME =~ git:* ]]; then + exec &> >(tee >(tee | logger -i -t "dokku-${DOKKU_PID}")) + fi + if [[ -x $PLUGIN_ENABLED_PATH/$PLUGIN_NAME/subcommands/default ]]; then "$PLUGIN_ENABLED_PATH/$PLUGIN_NAME/subcommands/default" "$@" implemented=1 diff --git a/plugins/builds/subcommands/cancel b/plugins/builds/subcommands/cancel index 818905a4c..8472feae6 100755 --- a/plugins/builds/subcommands/cancel +++ b/plugins/builds/subcommands/cancel @@ -34,4 +34,4 @@ cmd-builds-cancel() { kill -quit -- "-${PROCESS_GROUP_ID}" && rm -f "$APP_DEPLOY_LOCK_FILE" } -cmd-builds-cancel "$@" \ No newline at end of file +cmd-builds-cancel "$@" diff --git a/plugins/builds/subcommands/output b/plugins/builds/subcommands/output index 4ddb23ecc..ab1453059 100755 --- a/plugins/builds/subcommands/output +++ b/plugins/builds/subcommands/output @@ -7,20 +7,33 @@ cmd-builds-output() { declare desc="shows build output" declare cmd="builds:output" [[ "$1" == "$cmd" ]] && shift 1 - declare APP="$1" + declare APP="$1" DEPLOY_ID="$2" verify_app_name "$APP" - local APP_DEPLOY_LOCK_FILE PROCESS_ID - APP_DEPLOY_LOCK_FILE="$DOKKU_ROOT/$APP/.deploy.lock" - if [[ ! -f "$APP_DEPLOY_LOCK_FILE" ]]; then - dokku_log_info1 "No matching app deploy found" - return + if [[ -z "$DEPLOY_ID" ]] || [[ "$DEPLOY_ID" == "current" ]]; then + local APP_DEPLOY_LOCK_FILE PROCESS_ID + APP_DEPLOY_LOCK_FILE="$DOKKU_ROOT/$APP/.deploy.lock" + if [[ ! -f "$APP_DEPLOY_LOCK_FILE" ]]; then + dokku_log_info1 "App not currently deploying" + return + fi + + DEPLOY_ID="$(cat "$APP_DEPLOY_LOCK_FILE")" + if [[ -z "$DEPLOY_ID" ]]; then + dokku_log_info1 "No matching app deploy found" + return + fi fi - PROCESS_ID="$(cat "$APP_DEPLOY_LOCK_FILE")" - if [[ -z "$PROCESS_ID" ]]; then - dokku_log_info1 "No matching app deploy found" - return + if [[ -z "$DEPLOY_ID" ]]; then + dokku_log_fail "No deploy id specified" + return 1 + fi + + if [[ -x /usr/bin/systemctl ]] || [[ -x /usr/local/bin/systemctl ]]; then + journalctl -n1000 -f -b -a -o cat "SYSLOG_IDENTIFIER=dokku-${DEPLOY_ID}" + else + grep "dokku-${DEPLOY_ID}" /var/log/syslog fi }