Ajout paramètre pour définir des opts par défaut + couleur dans la sortie

This commit is contained in:
wpetit 2015-10-22 16:55:54 +02:00
parent 8afd107858
commit 30332dc5cb
6 changed files with 78 additions and 29 deletions

View File

@ -18,7 +18,6 @@ then
git checkout ${BUILD_BRANCH} git checkout ${BUILD_BRANCH}
tags=$(git tag master -l "release/*"|sort -r) tags=$(git tag master -l "release/*"|sort -r)
else else
info "DEBUG DEBUG DEBUG "
tagbranch="build-tag-${BUILD_TAG}" tagbranch="build-tag-${BUILD_TAG}"
git checkout -b ${tagbranch} git checkout -b ${tagbranch}
set_opt "tag_branch" "${tag_branch}" set_opt "tag_branch" "${tag_branch}"

View File

@ -1,8 +1,6 @@
#!/bin/bash #!/bin/bash
source "${TAMARIN_UTIL}"
if [ -f debian/control ]; then if [ -f debian/control ]; then
info "Installing build dependencies..." echo "Installing build dependencies..."
mk-build-deps -r -t "apt-get --force-yes -y --no-install-recommends" --install debian/control mk-build-deps -r -t "apt-get --force-yes -y --no-install-recommends" --install debian/control
fi fi

View File

@ -34,7 +34,7 @@ function build_project()
cd "${workspace}" cd "${workspace}"
dpkg-buildpackage -b -a "${TARGET_ARCH}" 2> >(error) 1> >(info) dpkg-buildpackage -b -a "${TARGET_ARCH}" 2> >(stderr) 1> >(stdout)
if [ $? != 0 ]; then if [ $? != 0 ]; then
fatal "The build process has not completed successfuly !" fatal "The build process has not completed successfuly !"

View File

@ -6,7 +6,7 @@ DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source "${DIR}/util.sh" source "${DIR}/util.sh"
info "Updating packages definition..." info "Updating packages definition..."
apt-get update 2> >(error) 1> >(info) apt-get update 2> >(stderr) 1> >(stdout)
info "Installing package $1..." info "Installing package $1..."
gdebi --n "$1" 2> >(error) 1> >(info) gdebi --n "$1" 2> >(stderr) 1> >(stdout)

View File

@ -1,9 +1,40 @@
#!/usr/bin/env bash #!/usr/bin/env bash
HOOKS_DIR="${BASE_DIR}/hooks" HOOKS_DIR="${BASE_DIR}/hooks"
DEFAULT_OPTS_FILE="${BASE_DIR}/default_opts"
OPT_FILE="${BASE_DIR}/tmp/.tamarin_opts" OPT_FILE="${BASE_DIR}/tmp/.tamarin_opts"
OPT_PREFIX="tamarin_opt_" OPT_PREFIX="tamarin_opt_"
# Colors
COLOR_INFO='\e[0;36m'
COLOR_FATAL='\e[0;31m'
COLOR_WARN='\e[0;33m'
COLOR_SUCCESS='\e[0;32m'
COLOR_ERR='\e[0;37m'
COLOR_OUT='\e[0;37m'
COLOR_DEBUG='\e[0;35m'
function stderr {
if [ -z "$@" ]; then
while read str; do
log ERR "${str}"
done
else
log stderr "$@"
fi
}
function stdout {
if [ -z "$@" ]; then
while read str; do
log OUT "${str}"
done
else
log OUT "$@"
fi
}
function info { function info {
if [ -z "$@" ]; then if [ -z "$@" ]; then
while read str; do while read str; do
@ -14,6 +45,16 @@ function info {
fi fi
} }
function warn {
if [ -z "$@" ]; then
while read str; do
log WARN "${str}"
done
else
log WARN "$@"
fi
}
function debug { function debug {
if [ -z "$@" ]; then if [ -z "$@" ]; then
while read str; do while read str; do
@ -24,16 +65,6 @@ function debug {
fi fi
} }
function error {
if [ -z "$@" ]; then
while read str; do
log ERROR "${str}" >&2
done
else
log ERROR "$@" >&2
fi
}
function fatal { function fatal {
if [ -z "$@" ]; then if [ -z "$@" ]; then
while read str; do while read str; do
@ -45,9 +76,24 @@ function fatal {
exit 1 exit 1
} }
function success {
if [ -z "$@" ]; then
while read str; do
log SUCCESS "${str}"
done
else
log SUCCESS "$@"
fi
}
function log { function log {
local args=( $@ ) local args=( $@ )
echo "[${HOSTNAME}] [${args[0]}] ${args[@]:1}" local color=COLOR_${args[0]}
echo -e "${!color}[${HOSTNAME}] [${args[0]}] $(remove_ansi ${args[@]:1})\e[0m"
}
function remove_ansi {
echo "$@" | sed 's,\x1B\[[0-9;]*[a-zA-Z],,g'
} }
function get_opt { function get_opt {
@ -75,16 +121,16 @@ function exec_hooks {
for hook_script in ${hook_scripts}; do for hook_script in ${hook_scripts}; do
info "[${hook}] Executing ${hook_script}" info "[${hook}] >> ${hook_script}"
( cd "${workspace}" && "${hook_script}" ) 2> >(error) 1> >(info) ( cd "${workspace}" && "${hook_script}" ) 2> >(stderr) 1> >(stdout)
# If the script did not execute properly, we stop here # If the script did not execute properly, we stop here
if [ $? != 0 ]; then if [ $? != 0 ]; then
fatal "The '${hook_script}' hook script did not finished properly !" fatal "The '${hook_script}' hook script did not finished properly !"
fi fi
info "[${hook}] ${hook_script} Done." info "[${hook}] << ${hook_script}"
done done

View File

@ -63,16 +63,21 @@ EOF
exec_hooks "containerbuild" "$temp_dir" exec_hooks "containerbuild" "$temp_dir"
if [[ -z ${BUILD_DIR} ]] if [[ -z "${BUILD_DIR}" ]]; then
then
echo " CMD /root/.tamarin/lib/build.sh ${projectName} ${BUILD_BRANCH} /tmp ${BUILD_TAG}" >> "$temp_dir/Dockerfile" echo " CMD /root/.tamarin/lib/build.sh ${projectName} ${BUILD_BRANCH} /tmp ${BUILD_TAG}" >> "$temp_dir/Dockerfile"
else else
echo " VOLUME /build" >> "$temp_dir/Dockerfile" echo " VOLUME /build" >> "$temp_dir/Dockerfile"
echo " CMD /root/.tamarin/lib/build.sh ${projectName} ${BUILD_BRANCH} /build ${BUILD_TAG}" >> "$temp_dir/Dockerfile" echo " CMD /root/.tamarin/lib/build.sh ${projectName} ${BUILD_BRANCH} /build ${BUILD_TAG}" >> "$temp_dir/Dockerfile"
fi fi
# Add default opts file if defined
if [[ -e "${DEFAULT_OPTS}" ]]; then
ln -s "${DEFAULT_OPTS}" "$temp_dir/default_opts"
echo " ADD ./default_ops /root/.tamarin/default_opts" >> "$temp_dir/Dockerfile"
fi
# Build image # Build image
tar -C "$temp_dir" -czh . | docker build -t "$container_tag" - 2> >(error) 1> >(info) tar -C "$temp_dir" -czh . | docker build -t "$container_tag" - 2> >(stderr) 1> >(stdout)
# Delete temporary folder # Delete temporary folder
rm -rf "$temp_dir" rm -rf "$temp_dir"
@ -120,14 +125,14 @@ function main {
docker ${docker_opt} docker ${docker_opt}
res=${?} res=${?}
info "Done" success "Done"
return ${res} return ${res}
} }
# #
# Parsing options # Parsing options
# #
while getopts "kp:d:i:b:B:t:a:" option while getopts "kp:d:i:b:B:t:a:c:" option
do do
case $option in case $option in
k) k)
@ -154,6 +159,9 @@ do
a) a)
TARGET_ARCH=${OPTARG} TARGET_ARCH=${OPTARG}
;; ;;
c)
DEFAULT_OPTS=$(readlink -f ${OPTARG})
;;
*) *)
show_usage show_usage
;; ;;
@ -173,9 +181,7 @@ done
if [[ -n ${http_proxy} ]] if [[ -n ${http_proxy} ]]
then then
info "-" warn "You have a proxy defined please make sure docker deamon is configured to use this proxy"
info "[WARN] You have a proxy defined please make sure docker deamon is configured to use this proxy"
info "-"
fi fi
main main