Base gestion des paramètres par défaut
This commit is contained in:
parent
30332dc5cb
commit
1ba20bc279
|
@ -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"
|
SRC_DIR="${BASE_DIR}/src"
|
||||||
PROJECT_NAME=${1}
|
PROJECT_NAME=${1}
|
||||||
BUILD_BRANCH=${2}
|
BUILD_BRANCH=${2}
|
||||||
BUILD_DIR=${3}
|
|
||||||
BUILD_TAG=${4}
|
BUILD_TAG=${4}
|
||||||
|
|
||||||
function build_project()
|
function build_project()
|
||||||
|
@ -17,12 +16,13 @@ function build_project()
|
||||||
|
|
||||||
info "Building project '${PROJECT_NAME}' for ${TARGET_ARCH} architecture..."
|
info "Building project '${PROJECT_NAME}' for ${TARGET_ARCH} architecture..."
|
||||||
|
|
||||||
|
load_default_opts
|
||||||
|
|
||||||
set_opt project_name "${PROJECT_NAME}"
|
set_opt project_name "${PROJECT_NAME}"
|
||||||
set_opt build_dir "${BUILD_DIR}"
|
|
||||||
set_opt build_branch "${BUILD_BRANCH}"
|
set_opt build_branch "${BUILD_BRANCH}"
|
||||||
set_opt build_tag "${BUILD_TAG}"
|
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}"
|
info "Build dir is ${workspace}"
|
||||||
mkdir -p "${workspace}"
|
mkdir -p "${workspace}"
|
||||||
|
|
||||||
|
|
19
lib/util.sh
19
lib/util.sh
|
@ -1,8 +1,8 @@
|
||||||
#!/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"
|
DEFAULT_OPTS_FILE="${BASE_DIR}/tmp/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
|
# Colors
|
||||||
|
@ -89,13 +89,21 @@ function success {
|
||||||
function log {
|
function log {
|
||||||
local args=( $@ )
|
local args=( $@ )
|
||||||
local color=COLOR_${args[0]}
|
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 {
|
function remove_ansi {
|
||||||
echo "$@" | sed 's,\x1B\[[0-9;]*[a-zA-Z],,g'
|
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 {
|
function get_opt {
|
||||||
local opt_name=${OPT_PREFIX}${1}
|
local opt_name=${OPT_PREFIX}${1}
|
||||||
local default_value=${2}
|
local default_value=${2}
|
||||||
|
@ -107,6 +115,7 @@ function get_opt {
|
||||||
function set_opt {
|
function set_opt {
|
||||||
local opt_name=${1}
|
local opt_name=${1}
|
||||||
local opt_value=${2}
|
local opt_value=${2}
|
||||||
|
mkdir -p "$(dirname ${OPT_FILE})"
|
||||||
touch "${OPT_FILE}"
|
touch "${OPT_FILE}"
|
||||||
sed -i "s/^${OPT_PREFIX}${opt_name}*$//" "${OPT_FILE}"
|
sed -i "s/^${OPT_PREFIX}${opt_name}*$//" "${OPT_FILE}"
|
||||||
echo "${OPT_PREFIX}${opt_name}=\"${opt_value}\"" >> "${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
|
for hook_script in ${hook_scripts}; do
|
||||||
|
|
||||||
info "[${hook}] >> ${hook_script}"
|
info "[>> ${hook}] ${hook_script}"
|
||||||
|
|
||||||
( cd "${workspace}" && "${hook_script}" ) 2> >(stderr) 1> >(stdout)
|
( 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 !"
|
fatal "The '${hook_script}' hook script did not finished properly !"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
info "[${hook}] << ${hook_script}"
|
info "[<< ${hook}] ${hook_script}"
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
|
@ -4,21 +4,20 @@ set -e
|
||||||
|
|
||||||
TAMARIN_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
TAMARIN_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||||
|
|
||||||
|
|
||||||
BASE_DIR="$TAMARIN_DIR" source "$TAMARIN_DIR/lib/util.sh"
|
BASE_DIR="$TAMARIN_DIR" source "$TAMARIN_DIR/lib/util.sh"
|
||||||
|
|
||||||
function show_usage {
|
function show_usage {
|
||||||
echo
|
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
|
||||||
echo "Parameters: "
|
echo "Parameters: "
|
||||||
echo
|
echo
|
||||||
echo " -p Path to the project to build"
|
echo " -p Path to the project to build"
|
||||||
echo " -a Optional : Target architecture (default amd64)"
|
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 " -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 " -i Optional : Name of the Docker image to use for build (default: debian:jessie)"
|
||||||
echo " -k Optional : Keep the Docker container after build "
|
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 " -B Optional : Build branch (for git projects only) (default dist/ubuntu/precise/master)"
|
||||||
echo
|
echo
|
||||||
exit 2
|
exit 2
|
||||||
|
@ -35,7 +34,6 @@ function create_container {
|
||||||
local temp_dir="$(mktemp -d)"
|
local temp_dir="$(mktemp -d)"
|
||||||
|
|
||||||
local projectName=${1}
|
local projectName=${1}
|
||||||
local buildDir=${2}
|
|
||||||
|
|
||||||
# Link lib & hooks folders
|
# Link lib & hooks folders
|
||||||
ln -s $(readlink -f "$TAMARIN_DIR/lib") "$temp_dir/lib"
|
ln -s $(readlink -f "$TAMARIN_DIR/lib") "$temp_dir/lib"
|
||||||
|
@ -43,7 +41,7 @@ function create_container {
|
||||||
|
|
||||||
# Create Dockerfile
|
# Create Dockerfile
|
||||||
cat << EOF > "$temp_dir/Dockerfile"
|
cat << EOF > "$temp_dir/Dockerfile"
|
||||||
FROM $BASE_IMAGE
|
FROM ${BASE_IMAGE}
|
||||||
|
|
||||||
ENV DEBIAN_FRONTEND noninteractive
|
ENV DEBIAN_FRONTEND noninteractive
|
||||||
|
|
||||||
|
@ -59,23 +57,19 @@ function create_container {
|
||||||
|
|
||||||
VOLUME /src
|
VOLUME /src
|
||||||
VOLUME /dist
|
VOLUME /dist
|
||||||
|
|
||||||
|
CMD /root/.tamarin/lib/build.sh ${projectName} ${BUILD_BRANCH} /tmp ${BUILD_TAG}
|
||||||
|
|
||||||
EOF
|
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
|
# Add default opts file if defined
|
||||||
if [[ -e "${DEFAULT_OPTS}" ]]; then
|
if [[ -e "${DEFAULT_OPTS}" ]]; then
|
||||||
ln -s "${DEFAULT_OPTS}" "$temp_dir/default_opts"
|
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
|
fi
|
||||||
|
|
||||||
|
exec_hooks "containerbuild" "$temp_dir"
|
||||||
|
|
||||||
# Build image
|
# Build image
|
||||||
tar -C "$temp_dir" -czh . | docker build -t "$container_tag" - 2> >(stderr) 1> >(stdout)
|
tar -C "$temp_dir" -czh . | docker build -t "$container_tag" - 2> >(stderr) 1> >(stdout)
|
||||||
|
|
||||||
|
@ -113,12 +107,7 @@ function main {
|
||||||
docker_opt="${docker_opt}"
|
docker_opt="${docker_opt}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -z ${BUILD_DIR} ]]
|
|
||||||
then
|
|
||||||
docker_opt="${docker_opt} -v=\"$PROJECT_PATH:/src:ro\" -v=\"$PROJECT_DEST:/dist:rw\" $container_tag"
|
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
|
|
||||||
|
|
||||||
info "Switching to container..."
|
info "Switching to container..."
|
||||||
debug "docker ${docker_opt}"
|
debug "docker ${docker_opt}"
|
||||||
|
@ -132,7 +121,7 @@ function main {
|
||||||
#
|
#
|
||||||
# Parsing options
|
# Parsing options
|
||||||
#
|
#
|
||||||
while getopts "kp:d:i:b:B:t:a:c:" option
|
while getopts "kp:d:i:B:t:a:o:" option
|
||||||
do
|
do
|
||||||
case $option in
|
case $option in
|
||||||
k)
|
k)
|
||||||
|
@ -147,9 +136,6 @@ do
|
||||||
i)
|
i)
|
||||||
BASE_IMAGE="${OPTARG}"
|
BASE_IMAGE="${OPTARG}"
|
||||||
;;
|
;;
|
||||||
b)
|
|
||||||
BUILD_DIR=$(readlink -f ${OPTARG})
|
|
||||||
;;
|
|
||||||
B)
|
B)
|
||||||
BUILD_BRANCH=${OPTARG}
|
BUILD_BRANCH=${OPTARG}
|
||||||
;;
|
;;
|
||||||
|
@ -159,7 +145,7 @@ do
|
||||||
a)
|
a)
|
||||||
TARGET_ARCH=${OPTARG}
|
TARGET_ARCH=${OPTARG}
|
||||||
;;
|
;;
|
||||||
c)
|
o)
|
||||||
DEFAULT_OPTS=$(readlink -f ${OPTARG})
|
DEFAULT_OPTS=$(readlink -f ${OPTARG})
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
Loading…
Reference in New Issue