From a1cdbcdac23cfdf1b4907f687096241d0a886ebb Mon Sep 17 00:00:00 2001 From: "Arnaud G. GIBERT" Date: Tue, 26 Nov 2024 17:44:43 +0100 Subject: [PATCH] - Implement volume modes, - Add DOCKER_TOOLS_VOLUME & DOCKER_TOOLS_EXECPTION_LIBS env variables. --- ReadMe.txt | 8 ++- ReleaseNotes.txt | 7 +-- sbin/docker_mk_env | 122 ++++++++++++++++++++++++++++++++------------- 3 files changed, 99 insertions(+), 38 deletions(-) diff --git a/ReadMe.txt b/ReadMe.txt index 6154c46..61f55a8 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -7,7 +7,13 @@ This project aims to give some basic tools to be used by other Rx3 docker packag Features: - docker_mk_env command to compile env file into .env file, - 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! diff --git a/ReleaseNotes.txt b/ReleaseNotes.txt index 7fbb7e3..a65f703 100644 --- a/ReleaseNotes.txt +++ b/ReleaseNotes.txt @@ -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! -- Add DOCKER_TOOLS_DEBUG env variable support. diff --git a/sbin/docker_mk_env b/sbin/docker_mk_env index d101af1..646465a 100755 --- a/sbin/docker_mk_env +++ b/sbin/docker_mk_env @@ -1,6 +1,20 @@ #!/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 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 { @@ -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 { @@ -82,10 +115,10 @@ function docker_service_add if [[ "${service_name}" == "${APPL_NAME}" ]] then 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 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 @@ -112,26 +145,47 @@ function docker_service_add if [[ "${APPL_NAME}" != "" ]] then - log_ext_suffix="-${target_name}" - - dynvar_export "${varible_prefix}_CONTEXT_PATH" "/${APPL_NAME}/${target_name}/" + dynvar_export "${varible_prefix}_CONTEXT_PATH" "/${APPL_NAME}/${service_name}/" else - log_ext_suffix="" - - dynvar_export "${varible_prefix}_CONTEXT_PATH" "/${target_name}/" + DOCKER_TOOLS_VOLUME="SINGLE" + dynvar_export "${varible_prefix}_CONTEXT_PATH" "/${service_name}/" 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_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_EXT" "./var/log/supervisor${log_ext_suffix}" - 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_SV_EXT" "$( psfix_cat "${volume_prefix}/var/log/supervisor" "-" "${volume_suffix_ext}")" + 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