Skip to content

Commit

Permalink
preserve log output setting into the docker containers too
Browse files Browse the repository at this point in the history
  • Loading branch information
xmik committed Feb 5, 2024
1 parent 8386ccd commit b072f52
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 18 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 6 additions & 2 deletions image_scripts/src/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 30 additions & 11 deletions image_scripts/src/etc_dojo.d/scripts/50-fix-uid-gid.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package main
const DojoVersion = "0.12.1"
const DojoVersion = "0.13.0"

0 comments on commit b072f52

Please sign in to comment.