Base gestion des paramètres par défaut
This commit is contained in:
parent
30332dc5cb
commit
1ba20bc279
15
hooks/07-bump-package-version-prebuild
Executable file
15
hooks/07-bump-package-version-prebuild
Executable file
@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env bash
|
||||
source "${TAMARIN_UTIL}"
|
||||
|
||||
if [ ! -f debian/changelog ] || [ ! -d .git ]; then
|
||||
info "To auto calculate the package version suffix, we need a git environment and a existing changelog !"
|
||||
exit
|
||||
fi
|
||||
|
||||
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}
|
||||
|
||||
sed "0,/(\(.*\))/s/(\(.*\))/(\1-${version_suffix})/" debian/changelog
|
||||
|
||||
exit 1
|
@ -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}"
|
||||
|
||||
|
19
lib/util.sh
19
lib/util.sh
@ -1,8 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
HOOKS_DIR="${BASE_DIR}/hooks"
|
||||
DEFAULT_OPTS_FILE="${BASE_DIR}/default_opts"
|
||||
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
|
||||
@ -89,13 +89,21 @@ function success {
|
||||
function log {
|
||||
local args=( $@ )
|
||||
local color=COLOR_${args[0]}
|
||||
echo -e "${!color}[${HOSTNAME}] [${args[0]}] $(remove_ansi ${args[@]:1})\e[0m"
|
||||
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 {
|
||||
local opt_name=${OPT_PREFIX}${1}
|
||||
local default_value=${2}
|
||||
@ -107,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}"
|
||||
@ -121,7 +130,7 @@ function exec_hooks {
|
||||
|
||||
for hook_script in ${hook_scripts}; do
|
||||
|
||||
info "[${hook}] >> ${hook_script}"
|
||||
info "[>> ${hook}] ${hook_script}"
|
||||
|
||||
( cd "${workspace}" && "${hook_script}" ) 2> >(stderr) 1> >(stdout)
|
||||
|
||||
@ -130,7 +139,7 @@ function exec_hooks {
|
||||
fatal "The '${hook_script}' hook script did not finished properly !"
|
||||
fi
|
||||
|
||||
info "[${hook}] << ${hook_script}"
|
||||
info "[<< ${hook}] ${hook_script}"
|
||||
|
||||
done
|
||||
|
||||
|
@ -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,23 +57,19 @@ function create_container {
|
||||
|
||||
VOLUME /src
|
||||
VOLUME /dist
|
||||
|
||||
CMD /root/.tamarin/lib/build.sh ${projectName} ${BUILD_BRANCH} /tmp ${BUILD_TAG}
|
||||
|
||||
EOF
|
||||
|
||||
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
|
||||
|
||||
# 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"
|
||||
echo "ADD ./default_ops /tmp/tamarin/default_opts" >> "$temp_dir/Dockerfile"
|
||||
fi
|
||||
|
||||
exec_hooks "containerbuild" "$temp_dir"
|
||||
|
||||
# Build image
|
||||
tar -C "$temp_dir" -czh . | docker build -t "$container_tag" - 2> >(stderr) 1> >(stdout)
|
||||
|
||||
@ -113,12 +107,7 @@ 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}"
|
||||
@ -132,7 +121,7 @@ function main {
|
||||
#
|
||||
# Parsing options
|
||||
#
|
||||
while getopts "kp:d:i:b:B:t:a:c:" option
|
||||
while getopts "kp:d:i:B:t:a:o:" option
|
||||
do
|
||||
case $option in
|
||||
k)
|
||||
@ -147,9 +136,6 @@ do
|
||||
i)
|
||||
BASE_IMAGE="${OPTARG}"
|
||||
;;
|
||||
b)
|
||||
BUILD_DIR=$(readlink -f ${OPTARG})
|
||||
;;
|
||||
B)
|
||||
BUILD_BRANCH=${OPTARG}
|
||||
;;
|
||||
@ -159,7 +145,7 @@ do
|
||||
a)
|
||||
TARGET_ARCH=${OPTARG}
|
||||
;;
|
||||
c)
|
||||
o)
|
||||
DEFAULT_OPTS=$(readlink -f ${OPTARG})
|
||||
;;
|
||||
*)
|
Loading…
Reference in New Issue
Block a user