Merge branch 'feature/default_opts' into develop

This commit is contained in:
wpetit 2015-11-18 10:45:38 +01:00
commit 6054755cdc
8 changed files with 117 additions and 63 deletions

View File

@ -18,7 +18,6 @@ then
git checkout ${BUILD_BRANCH}
tags=$(git tag master -l "release/*"|sort -r)
else
info "DEBUG DEBUG DEBUG "
tagbranch="build-tag-${BUILD_TAG}"
git checkout -b ${tagbranch}
set_opt "tag_branch" "${tag_branch}"
@ -48,16 +47,7 @@ do
distribution=$(get_opt distribution UNRELEASED)
urgency=$(get_opt urgency low)
commit_count=$(git rev-list --count --first-parent HEAD)
current_commit=$(git log -n 1 --pretty=format:"%h")
version_suffix=tamarin${commit_count}~${current_commit}
package_version=${version}-${version_suffix}
# Define package_version opt if not defined
if [ -z "$(get_opt package_version)" ]; then
# Share computed package version
set_opt package_version "${package_version}"
fi
package_version=${version}
# Define project_version opt if not defined
if [ -z "$(get_opt project_version)" ]; then
@ -65,7 +55,7 @@ do
set_opt project_version "${version}"
fi
echo "${project_name} (${package_version}) ${distribution}; urgency=${urgency}" >> debian/changelog
echo "${project_name} (${version}) ${distribution}; urgency=${urgency}" >> debian/changelog
echo >> debian/changelog

View File

@ -0,0 +1,19 @@
#!/usr/bin/env bash
source "${TAMARIN_UTIL}"
if [ ! -f debian/changelog ]; then
info "No changelog. Skipping..."
exit
fi
if [ -d .git ]; then
info "It seems to be a Git repository. Generating version suffix based on Git history..."
commit_count=$(git rev-list --count HEAD)
current_commit=$(git log -n 1 --pretty=format:"%h")
version_suffix=tamarin${commit_count}~${current_commit}
else
info "Not a Git project. Fallback to timestamp for suffix generation..."
version_suffix=tamarin$(date +%Y%m%d%H%M)
fi
sed -i "0,/(\(.*\))/s/(\(.*\))/(\1-${version_suffix})/" debian/changelog

View File

@ -1,8 +1,6 @@
#!/bin/bash
source "${TAMARIN_UTIL}"
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
fi

View File

@ -9,7 +9,6 @@ DIST_DIR="${BASE_DIR}/dist"
SRC_DIR="${BASE_DIR}/src"
PROJECT_NAME=${1}
BUILD_BRANCH=${2}
BUILD_DIR=${3}
BUILD_TAG=${4}
function build_project()
@ -17,12 +16,13 @@ function build_project()
info "Building project '${PROJECT_NAME}' for ${TARGET_ARCH} architecture..."
load_default_opts
set_opt project_name "${PROJECT_NAME}"
set_opt build_dir "${BUILD_DIR}"
set_opt build_branch "${BUILD_BRANCH}"
set_opt build_tag "${BUILD_TAG}"
local workspace=$(mktemp -p ${BUILD_DIR} -d)/${PROJECT_NAME}
local workspace=$(mktemp -d)/${PROJECT_NAME}
info "Build dir is ${workspace}"
mkdir -p "${workspace}"
@ -34,7 +34,7 @@ function build_project()
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
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"
info "Updating packages definition..."
apt-get update 2> >(error) 1> >(info)
apt-get update 2> >(stderr) 1> >(stdout)
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
HOOKS_DIR="${BASE_DIR}/hooks"
OPT_FILE="${BASE_DIR}/tmp/.tamarin_opts"
DEFAULT_OPTS_FILE="${BASE_DIR}/tmp/default_opts"
OPT_FILE="${BASE_DIR}/tmp/tamarin/opts"
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 {
if [ -z "$@" ]; then
while read str; do
@ -14,6 +45,16 @@ function info {
fi
}
function warn {
if [ -z "$@" ]; then
while read str; do
log WARN "${str}"
done
else
log WARN "$@"
fi
}
function debug {
if [ -z "$@" ]; then
while read str; do
@ -24,16 +65,6 @@ function debug {
fi
}
function error {
if [ -z "$@" ]; then
while read str; do
log ERROR "${str}" >&2
done
else
log ERROR "$@" >&2
fi
}
function fatal {
if [ -z "$@" ]; then
while read str; do
@ -45,9 +76,32 @@ function fatal {
exit 1
}
function success {
if [ -z "$@" ]; then
while read str; do
log SUCCESS "${str}"
done
else
log SUCCESS "$@"
fi
}
function log {
local args=( $@ )
echo "[${HOSTNAME}] [${args[0]}] ${args[@]:1}"
local color=COLOR_${args[0]}
echo -e "${!color}[${args[0]}] $(remove_ansi ${args[@]:1})\e[0m"
}
function remove_ansi {
echo "$@" | sed 's,\x1B\[[0-9;]*[a-zA-Z],,g'
}
function load_default_opts {
if [[ -e "${DEFAULT_OPTS_FILE}" ]]; then
info "Loading default opts..."
else
info "No default opts found."
fi
}
function get_opt {
@ -61,6 +115,7 @@ function get_opt {
function set_opt {
local opt_name=${1}
local opt_value=${2}
mkdir -p "$(dirname ${OPT_FILE})"
touch "${OPT_FILE}"
sed -i "s/^${OPT_PREFIX}${opt_name}*$//" "${OPT_FILE}"
echo "${OPT_PREFIX}${opt_name}=\"${opt_value}\"" >> "${OPT_FILE}"
@ -75,16 +130,16 @@ function exec_hooks {
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 [ $? != 0 ]; then
fatal "The '${hook_script}' hook script did not finished properly !"
fi
info "[${hook}] ${hook_script} Done."
info "[<< ${hook}] ${hook_script}"
done

View File

@ -4,21 +4,20 @@ set -e
TAMARIN_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
BASE_DIR="$TAMARIN_DIR" source "$TAMARIN_DIR/lib/util.sh"
function show_usage {
echo
echo "Usage: $0 -p project_path [-d destination] [-i image] [-k]"
echo "Usage: $0 -p project_path [-a arch] [-d destination] [-i image] [-k]"
echo
echo "Parameters: "
echo
echo " -p Path to the project to build"
echo " -a Optional : Target architecture (default amd64)"
echo " -o Optional : Default options file to load (default none)"
echo " -d Optional : Destination of the builed packages (default ./packages)"
echo " -i Optional : Name of the Docker image to use for build (default: debian:jessie)"
echo " -k Optional : Keep the Docker container after build "
echo " -b Optional : Build directory (default /tmp)"
echo " -B Optional : Build branch (for git projects only) (default dist/ubuntu/precise/master)"
echo
exit 2
@ -35,7 +34,6 @@ function create_container {
local temp_dir="$(mktemp -d)"
local projectName=${1}
local buildDir=${2}
# Link lib & hooks folders
ln -s $(readlink -f "$TAMARIN_DIR/lib") "$temp_dir/lib"
@ -43,7 +41,7 @@ function create_container {
# Create Dockerfile
cat << EOF > "$temp_dir/Dockerfile"
FROM $BASE_IMAGE
FROM ${BASE_IMAGE}
ENV DEBIAN_FRONTEND noninteractive
@ -59,20 +57,21 @@ function create_container {
VOLUME /src
VOLUME /dist
EOF
# Add default opts file if defined
if [[ -e "${DEFAULT_OPTS}" ]]; then
ln -s "${DEFAULT_OPTS}" "$temp_dir/default_opts"
echo "ADD ./default_ops /tmp/tamarin/default_opts" >> "$temp_dir/Dockerfile"
fi
exec_hooks "containerbuild" "$temp_dir"
if [[ -z ${BUILD_DIR} ]]
then
echo " CMD /root/.tamarin/lib/build.sh ${projectName} ${BUILD_BRANCH} /tmp ${BUILD_TAG}" >> "$temp_dir/Dockerfile"
else
echo " VOLUME /build" >> "$temp_dir/Dockerfile"
echo " CMD /root/.tamarin/lib/build.sh ${projectName} ${BUILD_BRANCH} /build ${BUILD_TAG}" >> "$temp_dir/Dockerfile"
fi
echo "CMD /root/.tamarin/lib/build.sh ${projectName} ${BUILD_BRANCH} /tmp ${BUILD_TAG}" >> "$temp_dir/Dockerfile"
# 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
rm -rf "$temp_dir"
@ -108,26 +107,21 @@ function main {
docker_opt="${docker_opt}"
fi
if [[ -z ${BUILD_DIR} ]]
then
docker_opt="${docker_opt} -v=\"$PROJECT_PATH:/src:ro\" -v=\"$PROJECT_DEST:/dist:rw\" $container_tag"
else
docker_opt="${docker_opt} -v=\"$PROJECT_PATH:/src:ro\" -v=\"$PROJECT_DEST:/dist:rw\" -v=\"${BUILD_DIR}:/build\" $container_tag"
fi
docker_opt="${docker_opt} -v=\"$PROJECT_PATH:/src:ro\" -v=\"$PROJECT_DEST:/dist:rw\" $container_tag"
info "Switching to container..."
debug "docker ${docker_opt}"
docker ${docker_opt}
res=${?}
info "Done"
success "Done"
return ${res}
}
#
# Parsing options
#
while getopts "kp:d:i:b:B:t:a:" option
while getopts "kp:d:i:B:t:a:o:" option
do
case $option in
k)
@ -142,9 +136,6 @@ do
i)
BASE_IMAGE="${OPTARG}"
;;
b)
BUILD_DIR=$(readlink -f ${OPTARG})
;;
B)
BUILD_BRANCH=${OPTARG}
;;
@ -154,6 +145,9 @@ do
a)
TARGET_ARCH=${OPTARG}
;;
o)
DEFAULT_OPTS=$(readlink -f ${OPTARG})
;;
*)
show_usage
;;
@ -173,9 +167,7 @@ done
if [[ -n ${http_proxy} ]]
then
info "-"
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"
fi
main