From b072f52805b37ae2fff78b329d58cb5386b652d5 Mon Sep 17 00:00:00 2001 From: xmik Date: Mon, 5 Feb 2024 23:18:39 +1300 Subject: [PATCH] preserve log output setting into the docker containers too --- CHANGELOG.md | 5 +++ README.md | 9 ++-- image_scripts/src/entrypoint.sh | 8 +++- .../src/etc_dojo.d/scripts/50-fix-uid-gid.sh | 41 ++++++++++++++----- main.go | 3 ++ version.go | 2 +- 6 files changed, 50 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1032481..3fb1b34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +### 0.13.0 (2024-Feb-05) + +* Support multiple levels of log output produced by Dojo: `silent`, `error`, `warn`, `info`, `debug` +* Preserve log output setting into the docker containers too, to configure how much output is visible from the dojo image scripts + ### 0.12.1 (2024-Feb-05) * Fix https://github.com/kudulab/dojo/issues/37 - support the case when the current directory contains special characters diff --git a/README.md b/README.md index 5fd635a..ad7a761 100644 --- a/README.md +++ b/README.md @@ -592,12 +592,13 @@ The default value is: ```toml DOJO_LOG_LEVEL="info" ``` -Available values: `silent`, `error`, `warn`, `info`, `debug`. -*In CLI use `--log-level=info`*. -There is also an obsolete CLI option `--debug=true` or `--debug=false`. +* Available values: `silent`, `error`, `warn`, `info`, `debug`. +* If you want to minimise Dojo output, but still want to see the errors, set it to `error`. +* Defaults to `info` +* *In CLI use `--log-level=info`*. (There is also an obsolete CLI option `--debug=true` or `--debug=false`) +* If these (`--debug` and `--log-level`) are set to different values, then the most verbose value wins. E.g. if `DOJO_LOG_LEVEL="info"` and `--debug=true`, then the log level will be `debug`. -If these are set to different values, then the most verbose value wins. E.g. if `DOJO_LOG_LEVEL="info"` and `--debug=true`, then the log level will be `debug`. ##### Docker-compose file diff --git a/image_scripts/src/entrypoint.sh b/image_scripts/src/entrypoint.sh index d38a66a..47fda93 100755 --- a/image_scripts/src/entrypoint.sh +++ b/image_scripts/src/entrypoint.sh @@ -11,10 +11,14 @@ green='\033[0;32m' green_bold='\033[1;32m' noformat='\033[0m' function dojo_entrypoint_log_info { - echo -e "${bold}$(date "+%d-%m-%Y %T") Dojo entrypoint info:${noformat} ${1}" >&2 + if [[ "${DOJO_LOG_LEVEL}" != "silent" ]] && [[ "${DOJO_LOG_LEVEL}" != "error" ]] && [[ "${DOJO_LOG_LEVEL}" != "warn" ]]; then + echo -e "${bold}$(date "+%d-%m-%Y %T") Dojo entrypoint info:${noformat} ${1}" >&2 + fi } function dojo_entrypoint_log_info_green { - echo -e "${green_bold}$(date "+%d-%m-%Y %T") Dojo entrypoint info:${green} ${1}${noformat}" >&2 + if [[ "${DOJO_LOG_LEVEL}" != "silent" ]] && [[ "${DOJO_LOG_LEVEL}" != "error" ]] && [[ "${DOJO_LOG_LEVEL}" != "warn" ]]; then + echo -e "${green_bold}$(date "+%d-%m-%Y %T") Dojo entrypoint info:${green} ${1}${noformat}" >&2 + fi } # source any additional scripts with environment variables diff --git a/image_scripts/src/etc_dojo.d/scripts/50-fix-uid-gid.sh b/image_scripts/src/etc_dojo.d/scripts/50-fix-uid-gid.sh index 59485ec..dc22497 100755 --- a/image_scripts/src/etc_dojo.d/scripts/50-fix-uid-gid.sh +++ b/image_scripts/src/etc_dojo.d/scripts/50-fix-uid-gid.sh @@ -6,39 +6,52 @@ # https://github.com/tomzo/docker-uid-gid-fix/blob/master/fix-uid-gid.sh ########################################################################### +function dojo_50fixuidgid_log_info { + if [[ "${DOJO_LOG_LEVEL}" != "silent" ]] && [[ "${DOJO_LOG_LEVEL}" != "error" ]] && [[ "${DOJO_LOG_LEVEL}" != "warn" ]]; then + echo -e "$(date "+%d-%m-%Y %T") Dojo 50-fix-uid-gid info: ${1}" >&2 + fi +} +function dojo_50fixuidgid_log_error { + if [[ "${DOJO_LOG_LEVEL}" != "silent" ]] ; then + echo -e "$(date "+%d-%m-%Y %T") Dojo 50-fix-uid-gid error: ${1}" >&2 + fi +} + if [[ -z "${dojo_work}" ]]; then - echo "dojo_work not specified" >&2 + dojo_50fixuidgid_log_error "dojo_work not specified" exit 1; fi if [[ ! -d "${dojo_work}" ]]; then - echo "$dojo_work does not exist, expected to be mounted as docker volume" >&2 + dojo_50fixuidgid_log_error "$dojo_work does not exist, expected to be mounted as docker volume" exit 1; fi if [[ -z "${dojo_home}" ]]; then - echo "dojo_home not set" >&2 + dojo_50fixuidgid_log_error "dojo_home not set" exit 1; fi if [[ -z "${owner_username}" ]]; then - echo "Username not specified" + dojo_50fixuidgid_log_error "Username not specified" exit 1; fi if [[ -z "${owner_groupname}" ]]; then - echo "Groupname not specified" >&2 + dojo_50fixuidgid_log_error "Groupname not specified" exit 1; fi if ! getent passwd "${owner_username}" >/dev/null 2>&1; then - echo "User ${owner_username} does not exist" >&2 + dojo_50fixuidgid_log_error "User ${owner_username} does not exist" exit 1; fi if ! getent passwd "${owner_groupname}" >/dev/null 2>&1; then - echo "Group ${owner_groupname} does not exist" >&2 + dojo_50fixuidgid_log_error "Group ${owner_groupname} does not exist" exit 1; fi + + # use -n option which is the same as --numeric-uid-gid on Debian/Ubuntu, # but on Alpine, there is no --numeric-uid-gid option # Why we are sudo-ing as dojo? To deal with OSX legacy volume driver; see more at https://github.com/kudulab/dojo/issues/8 @@ -48,14 +61,20 @@ olduid=$(ls -n -d ${dojo_home} | awk '{ print $3 }') oldgid=$(ls -n -d ${dojo_home} | awk '{ print $4 }') if [[ "${olduid}" == "${newuid}" ]] && [[ "${oldgid}" == "${newgid}" ]]; then - echo "olduid == newuid == ${newuid}, nothing to do" >&2 + dojo_50fixuidgid_log_info "olduid == newuid == ${newuid}, nothing to do" elif [[ "0" == "${newuid}" ]] && [[ "0" == "${newgid}" ]]; then # We are on gRPC FUSE driver on Mac - do nothing # Or dojo was executed from host where current directory is owned by the root - not supported use case - echo "Assuming docker running with gRPC FUSE driver on Mac" >&2 + dojo_50fixuidgid_log_info "Assuming docker running with gRPC FUSE driver on Mac" else - ( set -x; usermod -u "${newuid}" "${owner_username}"; groupmod -g "${newgid}" "${owner_groupname}"; ) - ( set -x; chown ${newuid}:${newgid} -R "${dojo_home}"; ) + if [[ "${DOJO_LOG_LEVEL}" != "silent" ]] && [[ "${DOJO_LOG_LEVEL}" != "error" ]] && [[ "${DOJO_LOG_LEVEL}" != "warn" ]]; then + set -x + fi + ( usermod -u "${newuid}" "${owner_username}"; groupmod -g "${newgid}" "${owner_groupname}"; ) + ( chown ${newuid}:${newgid} -R "${dojo_home}"; ) + if [[ "${DOJO_LOG_LEVEL}" != "silent" ]] && [[ "${DOJO_LOG_LEVEL}" != "error" ]] && [[ "${DOJO_LOG_LEVEL}" != "warn" ]]; then + set +x + fi fi # do not chown the "$dojo_work" directory, it already has proper uid and gid, diff --git a/main.go b/main.go index 9884d1c..93bbe79 100644 --- a/main.go +++ b/main.go @@ -97,6 +97,9 @@ func main() { envService := NewEnvService() envService.AddVariable(fmt.Sprintf("DOJO_WORK_INNER=%s", mergedConfig.WorkDirInner)) envService.AddVariable(fmt.Sprintf("DOJO_WORK_OUTER=%s", mergedConfig.WorkDirOuter)) + // set the DOJO_LOG_LEVEL now, + // so that its value is preserved to docker containers + envService.AddVariable(fmt.Sprintf("DOJO_LOG_LEVEL=%s", mergedConfig.LogLevel)) shellService.SetEnvironment(envService.GetVariables()) diff --git a/version.go b/version.go index edc35f7..7297f37 100644 --- a/version.go +++ b/version.go @@ -1,3 +1,3 @@ package main -const DojoVersion = "0.12.1" +const DojoVersion = "0.13.0"