- New dynamic service environment variable generator support:
- Implement docker_service_add function.
This commit is contained in:
parent
d0b3985a23
commit
67101865a7
@ -6,7 +6,8 @@ This is project aims to give some basic tools to be used by others Rx3 docker pa
|
||||
|
||||
Features:
|
||||
- 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.
|
||||
|
||||
|
||||
Enjoy it!
|
||||
|
@ -1,3 +1,12 @@
|
||||
------------------------------------------------------------------------------------------------------------------------------------
|
||||
Docker Tools V 1.1.0 - A. GIBERT - 2024/11/03
|
||||
------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
- New dynamic service environment variable generator support:
|
||||
- Implement docker_service_add function.
|
||||
|
||||
|
||||
|
||||
------------------------------------------------------------------------------------------------------------------------------------
|
||||
Docker Tools V 1.0.0 - A. GIBERT - 2024/10/05
|
||||
------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -4,11 +4,97 @@
|
||||
set -o errexit
|
||||
|
||||
APPL_HOME_DIR="$(dirname "$(dirname "$0")")"
|
||||
DYNVAR_LIST=""
|
||||
|
||||
version="$1"
|
||||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
function dynvar_export
|
||||
{
|
||||
var=$1
|
||||
value=$2
|
||||
|
||||
|
||||
eval export ${var}=\"${value}\"
|
||||
|
||||
DYNVAR_LIST+=" ${var}"
|
||||
}
|
||||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
function docker_service_add
|
||||
{
|
||||
varible_prefix="$1"
|
||||
shift
|
||||
|
||||
for var in NAME NAME_FULL URL_PREFIX IMG_NAME VERSION_EXT VERSION_INT PORT_MAIN_EXT PORT_MAIN_INT PORT_ADMIN_EXT PORT_ADMIN_INT USER_NAME GROUP_NAME
|
||||
do
|
||||
dynvar_export "${varible_prefix}_${var}" "$1"
|
||||
shift
|
||||
done
|
||||
|
||||
if [[ $( eval echo \${${varible_prefix}_IMG_NAME}) != "-" ]]
|
||||
then
|
||||
# No Build
|
||||
|
||||
dynvar_export "${varible_prefix}_IMG_URL" "\${${varible_prefix}_URL_PREFIX}/\${${varible_prefix}_IMG_NAME}:\${${varible_prefix}_VERSION_INT}"
|
||||
else
|
||||
# Build
|
||||
|
||||
dynvar_export "${varible_prefix}_IMG_URL" "\${${varible_prefix}_URL_PREFIX}/\${${varible_prefix}_NAME}:\${${varible_prefix}_VERSION_INT}"
|
||||
|
||||
dynvar_export "${varible_prefix}_MODULE_NAME" "\${${varible_prefix}_NAME}"
|
||||
dynvar_export "${varible_prefix}_MODULE_PATH" "src/\${${varible_prefix}_NAME}"
|
||||
fi
|
||||
|
||||
dynvar_export "${varible_prefix}_CONTAINER_NAME" "${CONTAINER_NAME_PREFIX}-\${${varible_prefix}_NAME}"
|
||||
dynvar_export "${varible_prefix}_HOST" "\${${varible_prefix}_CONTAINER_NAME}"
|
||||
|
||||
dynvar_export "${varible_prefix}_PORT_MAIN_EXT" "\$(( \${${varible_prefix}_PORT_MAIN_EXT} + ${PORT_ENV_OFFSET}))"
|
||||
dynvar_export "${varible_prefix}_PORT_SV_EXT" "\$(( \${${varible_prefix}_PORT_MAIN_EXT} + ${PORT_SV_OFFSET}))"
|
||||
dynvar_export "${varible_prefix}_PORT_SV_INT" "9001"
|
||||
|
||||
if [[ $( eval echo \${${varible_prefix}_PORT_ADMIN_EXT}) != "-" ]]
|
||||
then
|
||||
dynvar_export "${varible_prefix}_PORT_ADMIN_EXT" "\$(( \${${varible_prefix}_PORT_ADMIN_EXT} + ${PORT_ENV_OFFSET}))"
|
||||
fi
|
||||
|
||||
if [[ $( eval echo \${${varible_prefix}_USER_NAME}) == "-" ]]
|
||||
then
|
||||
dynvar_export "${varible_prefix}_USER_ID" "-"
|
||||
else
|
||||
if [[ $( eval echo \${${varible_prefix}_USER_NAME}) =~ ^[0-9]+$ ]]
|
||||
then
|
||||
dynvar_export "${varible_prefix}_USER_ID" "\${${varible_prefix}_USER_NAME}"
|
||||
else
|
||||
dynvar_export "${varible_prefix}_USER_ID" "\$( id -u \${${varible_prefix}_USER_NAME})"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ $( eval echo \${${varible_prefix}_GROUP_NAME}) == "-" ]]
|
||||
then
|
||||
dynvar_export "${varible_prefix}_GROUP_ID" "-"
|
||||
else
|
||||
if [[ $( eval echo \${${varible_prefix}_GROUP_NAME}) =~ ^[0-9]+$ ]]
|
||||
then
|
||||
dynvar_export "${varible_prefix}_GROUP_ID" "\${${varible_prefix}_GROUP_NAME}"
|
||||
else
|
||||
dynvar_export "${varible_prefix}_GROUP_ID" "\$( getent group \${${varible_prefix}_GROUP_NAME} | cut -d: -f3)"
|
||||
fi
|
||||
fi
|
||||
|
||||
dynvar_export "${varible_prefix}_CONTEXT_PATH" "/${APPL_NAME}/\${${varible_prefix}_NAME}/"
|
||||
|
||||
|
||||
# dynvar_export "${varible_prefix}_" "${varible_prefix}_${}"
|
||||
}
|
||||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
. ${APPL_HOME_DIR}/env
|
||||
|
||||
@ -25,7 +111,7 @@ fi
|
||||
|
||||
>${APPL_HOME_DIR}/.env
|
||||
|
||||
for var in $(grep "^ *[a-zA-Z0-9_-]*=" ${APPL_HOME_DIR}/env | sed -e "s/=.*//" -e "s/ *//" | sort -u)
|
||||
for var in $( ( grep "^ *[a-zA-Z0-9_-]*=" ${APPL_HOME_DIR}/env | sed -e "s/=.*//" -e "s/ *//"; echo ${DYNVAR_LIST} | sed -e 's/ /\n/g') | sort -u)
|
||||
do
|
||||
echo "${var}='${!var}'" >>${APPL_HOME_DIR}/.env
|
||||
done
|
||||
|
Loading…
Reference in New Issue
Block a user