feat(ci): Improve log support

This commit is contained in:
Carlos Álvaro
2022-11-09 17:06:19 +01:00
committed by Carlos Álvaro
parent af0ef0c199
commit 55c150dcdf
2 changed files with 29 additions and 5 deletions

View File

@@ -6,6 +6,7 @@ for the list of changes in SaltStack.
**3005.1_2** **3005.1_2**
- CI(tests): Improve log support.
- CI(tests): Always run tests. - CI(tests): Always run tests.
- CI: Always perform cleanup tasks. - CI: Always perform cleanup tasks.
- CI: Improve build times. - CI: Improve build times.

View File

@@ -70,13 +70,31 @@ function salt-call()
docker-exec salt-call "$@" docker-exec salt-call "$@"
} }
#--- FUNCTION -------------------------------------------------------------------------------------------------------
# NAME: container_log
# DESCRIPTION: Print container log.
#----------------------------------------------------------------------------------------------------------------------
function container_log()
{
local CONTAINER_ID="$(docker container ls --all --filter NAME="${CONTAINER_NAME}" --quiet)"
[ -n "${CONTAINER_ID}" ] || return 0
echo "📝 container log (${CONTAINER_NAME})"
docker logs -t "${CONTAINER_ID}"
}
#--- FUNCTION ------------------------------------------------------------------------------------------------------- #--- FUNCTION -------------------------------------------------------------------------------------------------------
# NAME: master_log # NAME: master_log
# DESCRIPTION: Print salt-master log. # DESCRIPTION: Print salt-master log.
#---------------------------------------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------------------------------------
function master_log() function master_log()
{ {
docker-exec cat data/logs/salt/master local LOGS_DIR="${SCRIPT_PATH}/logs"
local SALT_MASTER_LOG="${LOGS_DIR}/salt/master"
[ -f "${SALT_MASTER_LOG}" ] || return 0
echo "📝 salt-master log (${SALT_MASTER_LOG})"
sudo cat "${SALT_MASTER_LOG}"
} }
#--- FUNCTION ------------------------------------------------------------------------------------------------------- #--- FUNCTION -------------------------------------------------------------------------------------------------------
@@ -87,11 +105,15 @@ function start_container_and_wait()
{ {
# shellcheck disable=SC2206 # shellcheck disable=SC2206
local DOCKER_ARGS=( $@ ) local DOCKER_ARGS=( $@ )
local LOGS_DIR="${SCRIPT_PATH}/logs"
mkdir -p "${LOGS_DIR}"
docker run --rm --detach --name "${CONTAINER_NAME}" \ docker run --detach --name "${CONTAINER_NAME}" \
--publish 4505:4505 --publish 4506:4506 \ --publish 4505:4505 --publish 4506:4506 \
--env PUID="$(id -u)" --env PGID="$(id -g)" \ --env PUID="$(id -u)" --env PGID="$(id -g)" \
--env SALT_LOG_LEVEL='info' \
--platform "${PLATFORM}" ${DOCKER_ARGS[@]} \ --platform "${PLATFORM}" ${DOCKER_ARGS[@]} \
--volume "${LOGS_DIR}/":/home/salt/data/logs/ \
"${IMAGE_NAME}" || return 1 "${IMAGE_NAME}" || return 1
echo "==> Waiting ${BOOTUP_WAIT_SECONDS} seconds for the container to be ready ..." echo "==> Waiting ${BOOTUP_WAIT_SECONDS} seconds for the container to be ready ..."
@@ -100,7 +122,7 @@ function start_container_and_wait()
#--- FUNCTION ------------------------------------------------------------------------------------------------------- #--- FUNCTION -------------------------------------------------------------------------------------------------------
# NAME: ok # NAME: ok
# DESCRIPTION: Print a successfull message. # DESCRIPTION: Print a success message.
#---------------------------------------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------------------------------------
function ok() function ok()
{ {
@@ -113,8 +135,9 @@ function ok()
#---------------------------------------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------------------------------------
function error() function error()
{ {
echo "🔥 $*" echo "🔥 $*" >&2
master_log container_log >&2
master_log >&2
return 1 return 1
} }