- Implement volume modes,

- Add DOCKER_TOOLS_VOLUME & DOCKER_TOOLS_EXECPTION_LIBS env variables.
This commit is contained in:
Arnaud G. GIBERT 2024-11-26 17:44:43 +01:00
parent 7bf4bc661a
commit a1cdbcdac2
3 changed files with 99 additions and 38 deletions

View File

@ -7,7 +7,13 @@ This project aims to give some basic tools to be used by other Rx3 docker packag
Features: Features:
- docker_mk_env command to compile env file into .env file, - docker_mk_env command to compile env file into .env file,
- docker_start, docker_stop & docker_logs command, - docker_start, docker_stop & docker_logs command,
- docker_service_add env file function. - docker_service_add env file function,
- docker_build_push.
Support different mounted volume modes:
- Single,
- Merged, (Old mode)
- Splited. (Default)
Enjoy it! Enjoy it!

View File

@ -1,10 +1,11 @@
------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------
Rx3-Docker/Docker Tools V 1.3.0 - A. GIBERT - 2024/11/xx Rx3-Docker/Docker Tools V 1.3.0 - A. GIBERT - 2024/11/26
------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------
- Improve docker_service_add function. - Improve docker_service_add function,
- Switch by default to splited volume mode,
- Add DOCKER_TOOLS_DEBUG, DOCKER_TOOLS_VOLUME & DOCKER_TOOLS_EXECPTION_LIBS env variable support.
- Warning: API break! - Warning: API break!
- Add DOCKER_TOOLS_DEBUG env variable support.

View File

@ -1,6 +1,20 @@
#!/bin/bash #!/bin/bash
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#
# DOCKER_TOOLS_DEBUG= TRUE | FALSE # Enable debugging (Default FALSE)
#
# DOCKER_TOOLS_VOLUME= SINGLE | MERGED | SPLITED # Default: SPLITED
# SINGLE: Merged volume mode + No service suffix
# MERGED: Merged volume mode + Service suffix
# SPLITED: By service volume mode + No service suffix
#
# DOCKER_TOOLS_EXECPTION_LIBS="module_name:lib_dir_name ..."
# Example: postgres:pgsq
#
#-------------------------------------------------------------------------------
set -o errexit set -o errexit
if [[ "$DOCKER_TOOLS_DEBUG" == "TRUE" ]] if [[ "$DOCKER_TOOLS_DEBUG" == "TRUE" ]]
@ -15,24 +29,6 @@ version="$1"
#-------------------------------------------------------------------------------
function prefix_add
{
prefix=$1
separator=$2
var=$3
if [[ "${prefix}" != "" ]]
then
echo -n "${prefix}${separator}"
fi
echo "${var}"
}
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
function dynvar_export function dynvar_export
{ {
@ -47,6 +43,43 @@ function dynvar_export
#-------------------------------------------------------------------------------
function psfix_cat
{
prefix=$1
separator=$2
suffix=$3
if [[ "${prefix}" == "" ]] || [[ "${suffix}" == "" ]]
then
separator=""
fi
echo "${prefix}${separator}${suffix}"
}
#-------------------------------------------------------------------------------
function module_lib_name_get
{
module=$1
for tup in ${DOCKER_TOOLS_EXECPTION_LIBS}
do
if [[ "${module}" == "${tup/:*}" ]]
then
echo ${tup/*:}
return
fi
done
echo "${module}"
}
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
function docker_service_add function docker_service_add
{ {
@ -82,10 +115,10 @@ function docker_service_add
if [[ "${service_name}" == "${APPL_NAME}" ]] if [[ "${service_name}" == "${APPL_NAME}" ]]
then then
dynvar_export "${varible_prefix}_IMG_URL" "${target_url_prefix}:${target_version}" dynvar_export "${varible_prefix}_IMG_URL" "${target_url_prefix}:${target_version}"
dynvar_export "${varible_prefix}_HOST_NAME" "$( prefix_add "${HOST_NAME_PREFIX}" "-" "webapp")" dynvar_export "${varible_prefix}_HOST_NAME" "$( psfix_cat "${HOST_NAME_PREFIX}" "-" "webapp")"
else else
dynvar_export "${varible_prefix}_IMG_URL" "${target_url_prefix}/${target_name}:${target_version}" dynvar_export "${varible_prefix}_IMG_URL" "${target_url_prefix}/${target_name}:${target_version}"
dynvar_export "${varible_prefix}_HOST_NAME" "$( prefix_add "${HOST_NAME_PREFIX}" "-" "${service_name}")" dynvar_export "${varible_prefix}_HOST_NAME" "$( psfix_cat "${HOST_NAME_PREFIX}" "-" "${service_name}")"
fi fi
@ -112,26 +145,47 @@ function docker_service_add
if [[ "${APPL_NAME}" != "" ]] if [[ "${APPL_NAME}" != "" ]]
then then
log_ext_suffix="-${target_name}" dynvar_export "${varible_prefix}_CONTEXT_PATH" "/${APPL_NAME}/${service_name}/"
dynvar_export "${varible_prefix}_CONTEXT_PATH" "/${APPL_NAME}/${target_name}/"
else else
log_ext_suffix="" DOCKER_TOOLS_VOLUME="SINGLE"
dynvar_export "${varible_prefix}_CONTEXT_PATH" "/${service_name}/"
dynvar_export "${varible_prefix}_CONTEXT_PATH" "/${target_name}/"
fi fi
dynvar_export "${varible_prefix}_LIB_INT" "/var/lib/${module_name}"
dynvar_export "${varible_prefix}_LIB_EXT" "./var/lib/${module_name}" if [[ "${DOCKER_TOOLS_VOLUME}" == "" ]]
then
DOCKER_TOOLS_VOLUME="SPLITED"
fi
if [[ "${DOCKER_TOOLS_VOLUME}" != "SPLITED" ]]
then
volume_prefix="."
else
volume_prefix="./mnt/${service_name}"
fi
if [[ "${DOCKER_TOOLS_VOLUME}" != "MERGED" ]]
then
volume_suffix_ext=""
else
volume_suffix_ext="${service_name}"
fi
module_lib_name="$( module_lib_name_get "${module_name}")"
dynvar_export "${varible_prefix}_LIB_INT" "/var/lib/${module_lib_name}"
dynvar_export "${varible_prefix}_LIB_EXT" "$( psfix_cat "${volume_prefix}/var/lib/${module_lib_name}" "-" "${volume_suffix_ext}")"
dynvar_export "${varible_prefix}_LOG_INIT_INT" "/var/log/init" dynvar_export "${varible_prefix}_LOG_INIT_INT" "/var/log/init"
dynvar_export "${varible_prefix}_LOG_INIT_EXT" "./var/log/init${log_ext_suffix}" dynvar_export "${varible_prefix}_LOG_INIT_EXT" "$( psfix_cat "${volume_prefix}/var/log/init" "-" "${volume_suffix_ext}")"
dynvar_export "${varible_prefix}_LOG_SV_INT" "/var/log/supervisor" dynvar_export "${varible_prefix}_LOG_SV_INT" "/var/log/supervisor"
dynvar_export "${varible_prefix}_LOG_SV_EXT" "./var/log/supervisor${log_ext_suffix}" dynvar_export "${varible_prefix}_LOG_SV_EXT" "$( psfix_cat "${volume_prefix}/var/log/supervisor" "-" "${volume_suffix_ext}")"
dynvar_export "${varible_prefix}_LOG_POST_INT" "/var/log/supervisor"
dynvar_export "${varible_prefix}_LOG_POST_EXT" "./var/log/supervisor${log_ext_suffix}"
dynvar_export "${varible_prefix}_LOG_MAIN_INT" "/var/log/${module_name}" dynvar_export "${varible_prefix}_LOG_MAIN_INT" "/var/log/${module_name}"
dynvar_export "${varible_prefix}_LOG_MAIN_EXT" "./var/log/${module_name}" dynvar_export "${varible_prefix}_LOG_MAIN_EXT" "$( psfix_cat "${volume_prefix}/var/log/${module_name}" "-" "${volume_suffix_ext}")"
# Ports # Ports