Compare commits

...

3 Commits

5 changed files with 140 additions and 5 deletions

View File

@ -5,6 +5,7 @@ Welcome to Rx3-Docker/Docker Tools!
This project aims to give some basic tools to be used by other Rx3 docker packaging projects.
Features:
- docker_tools_install & docker_mk_dir to setup a new application environment,
- docker_mk_env command to compile env file into .env file,
- docker_start, docker_stop & docker_logs command,
- docker_service_add env file function,

View File

@ -1,3 +1,11 @@
------------------------------------------------------------------------------------------------------------------------------------
Rx3-Docker/Docker Tools V 1.3.1 - A. GIBERT - 2024/12/14
------------------------------------------------------------------------------------------------------------------------------------
- Add docker_mk_dir & docker_tools_install commands.
------------------------------------------------------------------------------------------------------------------------------------
Rx3-Docker/Docker Tools V 1.3.0 - A. GIBERT - 2024/11/26
------------------------------------------------------------------------------------------------------------------------------------

33
sbin/docker_mk_dir Executable file
View File

@ -0,0 +1,33 @@
#!/bin/bash
#-------------------------------------------------------------------------------
set -o errexit
grep -e _LOG_ -e _LIB_ .env | grep -e _EXT= | while read line
do
OIFS=$IFS
IFS="="
set $line
IFS=$OIFS
grep $1 compose.yaml >/dev/null
if [[ "$?" == "0" ]]
then
eval echo $2
fi
done | sort -u | while read dir
do
echo "Add/Create: [${dir}]"
mkdir -p ${dir}
echo -e '# Ignore everything in this directory\n*\n# Except this file\n!.gitignore' > ${dir}/.gitignore
git add ${dir}/.gitignore
done

View File

@ -10,20 +10,21 @@
# MERGED: Merged volume mode + Service suffix
# SPLITED: By service volume mode + No service suffix
#
# DOCKER_TOOLS_EXECPTION_LIBS="module_name:lib_dir_name ..."
# DOCKER_TOOLS_EXEPTION_LIBS="module_name:lib_dir_name ..."
# Example: postgres:pgsq
#
#-------------------------------------------------------------------------------
set -o errexit
if [[ "$DOCKER_TOOLS_DEBUG" == "TRUE" ]]
if [[ "${DOCKER_TOOLS_DEBUG}" == "TRUE" ]]
then
set -x
fi
APPL_HOME_DIR="$(dirname "$(dirname "$0")")"
DYNVAR_LIST="APPL_HOME_DIR"
CONFIG_FILE_LIST=""
version="$1"
@ -66,7 +67,7 @@ function module_lib_name_get
{
module=$1
for tup in ${DOCKER_TOOLS_EXECPTION_LIBS}
for tup in ${DOCKER_TOOLS_EXEPTION_LIBS}
do
if [[ "${module}" == "${tup/:*}" ]]
then
@ -170,12 +171,26 @@ function docker_service_add
else
volume_suffix_ext="${service_name}"
fi
module_lib_name="$( module_lib_name_get "${module_name}")"
if [[ "${module_lib_name}" != /* ]]
then
path_prefix="/var/lib/"
else
path_prefix=""
fi
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}")"
module_lib_path=${path_prefix}${module_lib_name}
dynvar_export "${varible_prefix}_LIB_INT" "${module_lib_path}"
dynvar_export "${varible_prefix}_LIB_EXT" "$( psfix_cat "${volume_prefix}${module_lib_path}" "-" "${volume_suffix_ext}")"
# 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" "$( psfix_cat "${volume_prefix}/var/log/init" "-" "${volume_suffix_ext}")"
@ -334,6 +349,18 @@ function docker_service_add-12
#-------------------------------------------------------------------------------
function docker_config_add
{
config_file_target="$1"
config_file_source="$2"
CONFIG_FILE_LIST+=" ${config_file_target}:${config_file_source}"
}
#-------------------------------------------------------------------------------
. ${APPL_HOME_DIR}/env
@ -355,3 +382,21 @@ for var in $( ( grep "^ *[a-zA-Z0-9_-]*=" ${APPL_HOME_DIR}/env | sed -e "s/=.*//
do
echo "${var}='${!var}'" >>${APPL_HOME_DIR}/.env
done
for tupple in ${CONFIG_FILE_LIST}
do
IFS=":"
set ${tupple}
config_file_target="$1"
config_file_source="$2"
IFS=" "
while read line
do
eval echo $(echo ${line} | sed -e 's/"/\\"/g' -e 's/</\\</g' -e 's/>/\\>/g';)
done <${config_file_source} >${config_file_target}
done

48
sbin/docker_tools_install Executable file
View File

@ -0,0 +1,48 @@
#!/bin/bash
#-------------------------------------------------------------------------------
set -o errexit
DOCKER_TOOLS_HOME_DIR="$(dirname "$(dirname "$0")")"
if [[ "$1" == "" ]]
then
APPL_HOME_DIR="$PWD"
else
APPL_HOME_DIR="$1"
fi
#-------------------------------------------------------------------------------
function link_create
{
source="$1"
target="$2"
if [[ -d "$target" ]]
then
real_target=${target}/$( basename "${source}")
else
real_target=${target}
fi
if [[ -e "${real_target}" ]]
then
mv ${real_target} ${real_target}.old
fi
ln -s ${source} ${target}
}
#-------------------------------------------------------------------------------
DOCKER_TOOLS_HOME_DIR=$( realpath --relative-to ${APPL_HOME_DIR} ${DOCKER_TOOLS_HOME_DIR})
cd ${APPL_HOME_DIR}
link_create ${DOCKER_TOOLS_HOME_DIR}/sbin .
link_create env.dist env