Arnaud G. GIBERT
9462b195c5
- docker_service_add: - Add *_LOG_* variable generation, - Add docker_build_push command.
132 lines
4.6 KiB
Bash
Executable File
132 lines
4.6 KiB
Bash
Executable File
#!/bin/bash
|
|
#-------------------------------------------------------------------------------
|
|
|
|
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 APPL_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
|
|
|
|
|
|
dynvar_export "${varible_prefix}_LOG_INT_INIT_DIR" "/var/log/init"
|
|
dynvar_export "${varible_prefix}_LOG_EXT_INIT_DIR" "./var/log/init-\${${varible_prefix}_NAME}"
|
|
dynvar_export "${varible_prefix}_LOG_INT_SV_DIR" "/var/log/supervisor"
|
|
dynvar_export "${varible_prefix}_LOG_EXT_SV_DIR" "./var/log/supervisor-\${${varible_prefix}_NAME}"
|
|
|
|
if [[ $( eval echo \${${varible_prefix}_APPL_NAME}) != "-" ]]
|
|
then
|
|
dynvar_export "${varible_prefix}_LIB_INT_DIR" "/var/lib/\${${varible_prefix}_APPL_NAME}"
|
|
dynvar_export "${varible_prefix}_LIB_EXT_DIR" "./var/lib/\${${varible_prefix}_APPL_NAME}"
|
|
dynvar_export "${varible_prefix}_LOG_INT_MAIN_DIR" "/var/log/\${${varible_prefix}_APPL_NAME}"
|
|
dynvar_export "${varible_prefix}_LOG_EXT_MAIN_DIR" "./var/log/\${${varible_prefix}_APPL_NAME}"
|
|
fi
|
|
|
|
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_EXT}"
|
|
else
|
|
# Build
|
|
|
|
dynvar_export "${varible_prefix}_IMG_URL" "\${${varible_prefix}_URL_PREFIX}/\${${varible_prefix}_NAME}:\${${varible_prefix}_VERSION_EXT}"
|
|
|
|
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
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
if [[ "${version}" != "" ]]
|
|
then
|
|
APPL_VERSION="$1"
|
|
fi
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
>${APPL_HOME_DIR}/.env
|
|
|
|
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
|