109 lines
1.6 KiB
Bash
109 lines
1.6 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
|
|
# Indent output by 2 x {n} spaces
|
|
__indent() {
|
|
if [[ $1 != "" ]] && [[ $1 -ne 0 ]]; then
|
|
printf ' %0.s' {1..$1}
|
|
fi
|
|
}
|
|
|
|
__newLine() {
|
|
if [[ $1 = "" ]]; then
|
|
echo
|
|
fi
|
|
}
|
|
|
|
__msg() {
|
|
echo -ne "${C_WHITE}"
|
|
__indent $2
|
|
echo -ne "$1${C_NONE}"
|
|
__newLine $3
|
|
}
|
|
|
|
__warn() {
|
|
echo -ne "${C_WARN}"
|
|
__indent $2
|
|
echo -ne "$1${C_NONE}"
|
|
__newLine $3
|
|
}
|
|
|
|
__success() {
|
|
echo -ne "${C_GREEN}"
|
|
__indent $2
|
|
echo -ne "$1${C_NONE}"
|
|
__newLine $3
|
|
}
|
|
|
|
__err() {
|
|
echo -ne "${C_ERR}"
|
|
__indent $2
|
|
echo -ne "$1${C_NONE}"
|
|
__newLine $3
|
|
}
|
|
|
|
|
|
#
|
|
# Internal functions
|
|
#
|
|
|
|
__createNetworks() {
|
|
for _var in ${NETWORKS[@]}; do
|
|
if [[ ${_var} = "" ]]; then
|
|
continue
|
|
fi
|
|
docker network inspect ${_var} > /dev/null 2>&1
|
|
if [[ $? -ne 0 ]]; then
|
|
# If it does not, create it
|
|
__warn "The network ${_var} does not exist. Creating... " 1 no
|
|
STATUS=$(docker network create ${_var} 2>&1)
|
|
if [[ $? -ne 0 ]]; then
|
|
__err "${STATUS}"
|
|
return 117
|
|
else
|
|
__success "[ok]"
|
|
fi
|
|
fi
|
|
done
|
|
return 0
|
|
}
|
|
|
|
|
|
init() {
|
|
__err "The init function was not overridden"
|
|
|
|
return 137
|
|
}
|
|
|
|
__init() {
|
|
__msg "Initializing ${PROJECT_NAME}"
|
|
|
|
# Make sure we have the latest build
|
|
docker pull ${IMAGE_NAME}:${IMAGE_VERSION}
|
|
|
|
return $?
|
|
}
|
|
|
|
__build() {
|
|
docker build \
|
|
--build-arg IMAGE_NAME=${IMAGE_NAME} \
|
|
--build-arg IMAGE_VERSION=${IMAGE_VERSION} \
|
|
-t ${PROJECT_NAME}:latest \
|
|
${SCRIPT_PATH}
|
|
|
|
return $?
|
|
}
|
|
|
|
|
|
__ask_to_start() {
|
|
__success "Start the container? [(y)/n]... "
|
|
read START
|
|
|
|
if [[ ${START} != "" ]] && [[ ${START} != "y" ]] && [[ ${START} != "Y" ]]; then
|
|
return 0
|
|
fi
|
|
|
|
start
|
|
return $?
|
|
}
|