fix(deployment): Fix log file path and log colour (#6890)

* Fix CD log file path handling

* Variables don't substitute

* Disable color escapes in Google Cloud logs

* Use correct elif syntax
This commit is contained in:
teor 2023-06-09 17:41:09 +10:00 committed by GitHub
parent a18f47d5f6
commit 89bf875744
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 4 deletions

View File

@ -18,6 +18,7 @@ on:
description: 'Network to deploy: Mainnet or Testnet'
required: true
log_file:
default: ''
description: 'Log to a file path rather than standard output'
no_cache:
description: 'Disable the Docker cache for this build'
@ -217,7 +218,7 @@ jobs:
--user-output-enabled \
--metadata google-logging-enabled=true,google-logging-use-fluentbit=true \
--container-image ${{ vars.GAR_BASE }}/zebrad@${{ needs.build.outputs.image_digest }} \
--container-env "NETWORK=${{ matrix.network }},LOG_FILE=${{ vars.CD_LOG_FILE }},SENTRY_DSN=${{ vars.SENTRY_DSN }},SHORT_SHA=${{ env.GITHUB_SHA_SHORT }}" \
--container-env "NETWORK=${{ matrix.network }},LOG_FILE=${{ vars.CD_LOG_FILE }},LOG_COLOR=false,SENTRY_DSN=${{ vars.SENTRY_DSN }},SHORT_SHA=${{ env.GITHUB_SHA_SHORT }}" \
--create-disk=name=zebrad-cache-${{ env.GITHUB_SHA_SHORT }}-${NETWORK},auto-delete=yes,size=300GB,type=pd-ssd \
--container-mount-disk=mount-path="/zebrad-cache",name=zebrad-cache-${{ env.GITHUB_SHA_SHORT }}-${NETWORK} \
--machine-type ${{ vars.GCP_SMALL_MACHINE }} \
@ -318,7 +319,7 @@ jobs:
--container-stdin \
--container-tty \
--container-image ${{ vars.GAR_BASE }}/zebrad@${{ needs.build.outputs.image_digest }} \
--container-env "NETWORK=${{ inputs.network }},LOG_FILE=${{ inputs.log_file || vars.CD_LOG_FILE }},SENTRY_DSN=${{ vars.SENTRY_DSN }},SHORT_SHA=${{ env.GITHUB_SHA_SHORT }}" \
--container-env "NETWORK=${{ inputs.network }},LOG_FILE=${{ inputs.log_file }},LOG_COLOR=false,SENTRY_DSN=${{ vars.SENTRY_DSN }},SHORT_SHA=${{ env.GITHUB_SHA_SHORT }}" \
--create-disk=auto-delete=yes,size=300GB,type=pd-ssd \
--create-disk=name=zebrad-cache-${{ env.GITHUB_SHA_SHORT }}-${NETWORK},auto-delete=yes,size=300GB,type=pd-ssd \
--container-mount-disk=mount-path='/zebrad-cache',name=zebrad-cache-${{ env.GITHUB_SHA_SHORT }}-${NETWORK} \

View File

@ -162,6 +162,12 @@ ENV RPC_PORT ${RPC_PORT}
ARG LOG_FILE
ENV LOG_FILE ${LOG_FILE}
# Zebra automatically detects if it is attached to a terminal, and uses colored output.
# Set this to 'true' to force using color even if the output is not a terminal.
# Set this to 'false' to disable using color even if the output is a terminal.
ARG LOG_COLOR
ENV LOG_COLOR ${LOG_COLOR}
# Expose configured ports
EXPOSE 8233 18233 $RPC_PORT

View File

@ -53,13 +53,28 @@ listen_addr = "0.0.0.0:${RPC_PORT}"
EOF
fi
if [[ -n "$LOG_FILE" ]] || [[ -n "$LOG_COLOR" ]]; then
cat <<EOF >> "$ZEBRA_CONF_PATH"
[tracing]
#endpoint_addr = "0.0.0.0:3000"
EOF
fi
if [[ -n "$LOG_FILE" ]]; then
mkdir -p $(dirname "$LOG_FILE")
cat <<EOF >> "$ZEBRA_CONF_PATH"
[tracing]
log_file = "${LOG_FILE}"
#endpoint_addr = "0.0.0.0:3000"
EOF
fi
if [[ "$LOG_COLOR" = "true" ]]; then
cat <<EOF >> "$ZEBRA_CONF_PATH"
force_use_color = true
EOF
elif [[ "$LOG_COLOR" = "false" ]]; then
cat <<EOF >> "$ZEBRA_CONF_PATH"
use_color = false
EOF
fi