Merge branch 'feature/getopt-git-dch' into develop

This commit is contained in:
wpetit 2015-09-02 17:29:53 +02:00
commit fc862e1369
4 changed files with 152 additions and 45 deletions

View File

@ -4,5 +4,5 @@ source "${TAMARIN_UTIL}"
if [ -f debian/control ]; then if [ -f debian/control ]; then
info "Installing build dependencies..." info "Installing build dependencies..."
mk-build-deps --install debian/control mk-build-deps -t "apt-get --force-yes -y" --install debian/control
fi fi

View File

@ -1,5 +1,4 @@
#!/usr/bin/env bash #!/usr/bin/env bash
source "${TAMARIN_UTIL}" source "${TAMARIN_UTIL}"
if [ -f debian/changelog ] || [ ! -d .git ]; then if [ -f debian/changelog ] || [ ! -d .git ]; then
@ -9,30 +8,59 @@ fi
# Get commits log as changelog # Get commits log as changelog
logs=$(git log --pretty=format:"%an - %h : %s" | sed 's/"/\\"/g') BUILD_BRANCH=$(get_opt build_branch dist/ubuntu/precise/master)
BUILD_TAG=$(get_opt build_tag "last")
# Set the top commiter as the maintainer of the project if not defined echo "BUILD TAG IS ${BUILD_TAG}"
top_contributor=$(git log --pretty=short | git shortlog -s -n -e | sed 's/^\s*[0-9]*\s*//g' | head -n 1)
maintainer=$(get_opt maintainer "${top_contributor}")
project_name=$(get_opt project_name) if [[ ${BUILD_TAG} == "last" ]]
version=$(get_opt version 0.0.0) then
distribution=$(get_opt distribution UNRELEASED) git checkout ${BUILD_BRANCH}
urgency=$(get_opt urgency low) 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}"
tags="${BUILD_TAG}"
fi
commit_count=$(git rev-list --count --first-parent HEAD) if [[ -z ${tags} ]]
current_commit=$(git log -n 1 --pretty=format:"%h") then
version_suffix=${commit_count}~${current_commit} error "No relase tag found, you repo must have a tag like 'release/X.X'"
exit 2
fi
echo "${project_name} (${version}.tamarin${version_suffix}) ${distribution}; urgency=${urgency}" > debian/changelog touch debian/changelog
echo >> debian/changelog for tag in ${tags}
do
logs=$(git log --pretty=format:"%an - %h : %s" ${tag} | sed 's/"/\\"/g')
while read -r entry; do # Set the top commiter as the maintainer of the project if not defined
top_contributor=$(git log --pretty=short | git shortlog -s -n -e | sed 's/^\s*[0-9]*\s*//g' | head -n 1)
maintainer=$(get_opt maintainer "${top_contributor}")
project_name=$(get_opt project_name)
version=${tag#*/} #$(get_opt version 0.0.0)
version=${version/_/-} #$(get_opt version 0.0.0)
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=${commit_count}~${current_commit}
echo "${project_name} (${version}.tamarin${version_suffix}) ${distribution}; urgency=${urgency}" >> debian/changelog
echo >> debian/changelog
while read -r entry; do
echo " * ${entry}" >> debian/changelog echo " * ${entry}" >> debian/changelog
done <<< "$(echo -e "${logs}" | sed 's/^"//')" done <<< "$(echo -e "${logs}" | sed 's/^"//')"
echo >> debian/changelog echo >> debian/changelog
echo " -- ${maintainer} $(date -R)" >> debian/changelog echo " -- ${maintainer} $(date -R)" >> debian/changelog
echo >> debian/changelog echo >> debian/changelog
done

View File

@ -7,14 +7,23 @@ source "${TAMARIN_UTIL}"
DIST_DIR="${BASE_DIR}/dist" DIST_DIR="${BASE_DIR}/dist"
SRC_DIR="${BASE_DIR}/src" SRC_DIR="${BASE_DIR}/src"
PROJECT_NAME=${1}
BUILD_BRANCH=${2}
BUILD_DIR=${3}
BUILD_TAG=${4}
function build_project { function build_project()
{
info "Building project ${PROJECT_NAME}..." info "Building project '${PROJECT_NAME}'..."
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_tag "${BUILD_TAG}"
local workspace=$(mktemp -d)/${PROJECT_NAME} local workspace=$(mktemp -p ${BUILD_DIR} -d)/${PROJECT_NAME}
info "Build dir is ${workspace}"
mkdir -p "${workspace}" mkdir -p "${workspace}"
# Copy sources to workspace # Copy sources to workspace

View File

@ -9,14 +9,18 @@ BASE_DIR="$TAMARIN_DIR" source "$TAMARIN_DIR/lib/util.sh"
function show_usage { function show_usage {
echo echo
echo "Usage: $0 src dist [image]" echo "Usage: $0 -p project_path [-d destination] [-i image] [-k]"
echo echo
echo "Paramètres: " echo "Parameters: "
echo echo
echo " - src Chemin vers le répertoire des sources du projet à empaqueter" echo " -p Path to the project to build"
echo " - dist Chemin vers le répertoire de destination du paquet à créer" echo " -d Optional : Destination of the builed packages (default ./packages)"
echo " - image Optionel - Nom de l'image Docker à utiliser comme base pourl'environnement de build. Défaut: 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 " -b Optional : Build directory (default /tmp)"
echo " -B Optional : Build branch (for git projects only) (default dist/ubuntu/precise/master)"
echo echo
exit 2
} }
# Create a build container based on the $BASE_IMAGE argument # Create a build container based on the $BASE_IMAGE argument
@ -29,6 +33,9 @@ function create_container {
# Create temporary dir for the Dockerfile # Create temporary dir for the Dockerfile
local temp_dir="$(mktemp -d)" local temp_dir="$(mktemp -d)"
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"
ln -s $(readlink -f "$TAMARIN_DIR/hooks") "$temp_dir/hooks" ln -s $(readlink -f "$TAMARIN_DIR/hooks") "$temp_dir/hooks"
@ -40,7 +47,7 @@ function create_container {
ENV DEBIAN_FRONTEND noninteractive ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update &&\ RUN apt-get update &&\
apt-get install --yes build-essential devscripts apt-get install --yes build-essential devscripts equivs git-buildpackage
RUN mkdir /root/.tamarin RUN mkdir /root/.tamarin
RUN mkdir /project RUN mkdir /project
@ -51,11 +58,16 @@ function create_container {
VOLUME /src VOLUME /src
VOLUME /dist VOLUME /dist
CMD /root/.tamarin/lib/build.sh
EOF EOF
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
exec_hooks "containerbuild" "$temp_dir" exec_hooks "containerbuild" "$temp_dir"
# Build image # Build image
@ -71,26 +83,84 @@ function main {
info "Building container from $BASE_IMAGE..." info "Building container from $BASE_IMAGE..."
# Create container & "$container_tag" variable local project_name=$(basename ${PROJECT_PATH})
create_container
local project_name="$(basename "${PROJECT_PATH}")" # Create container & "$container_tag" variable
create_container ${project_name}
local docker_opt="run -e \"DISTRIB=$BASE_IMAGE\" -e \"PROJECT_NAME=$project_name\""
if [[ ${PERSIST_CONTAINER} -eq 0 ]]
then
docker_opt="${docker_opt} --rm "
else
docker_opt="${docker_opt}"
fi
if [[ -z ${BUILD_DIR} ]]
then
docker_opt="${docker_opt} -v=\"$PROJECT_PATH:/src\" -v=\"$PROJECT_DEST:/dist\" $container_tag"
else
docker_opt="${docker_opt} -v=\"$PROJECT_PATH:/src\" -v=\"$PROJECT_DEST:/dist\" -v=\"${BUILD_DIR}:/build\" $container_tag"
fi
info "Switching to container..." info "Switching to container..."
docker run -e "DISTRIB=$BASE_IMAGE" -e "PROJECT_NAME=$project_name" --rm -v="$PROJECT_PATH:/src" -v="$PROJECT_DIST:/dist" "$container_tag" echo "docker ${docker_opt}"
docker ${docker_opt}
res=${?}
info "Done" info "Done"
return ${res}
} }
# Test for arguments #
if [ -z "$1" ] || [ -z "$2" ]; then # Parsing options
#
while getopts "kp:d:i:b:B:t:" option
do
case $option in
k)
PERSIST_CONTAINER=1
;;
p)
PROJECT_PATH=$(readlink -f ${OPTARG})
;;
d)
PROJECT_DEST=$(readlink -f ${OPTARG})
;;
i)
BASE_IMAGE="${OPTARG}"
;;
b)
BUILD_DIR=$(readlink -f ${OPTARG})
;;
B)
BUILD_BRANCH=${OPTARG}
;;
t)
BUILD_TAG=${OPTARG}
;;
*)
show_usage show_usage
exit 1 ;;
esac
done
[[ -z ${PROJECT_PATH} ]] && show_usage
[[ -z ${PROJECT_DEST} ]] && PROJECT_DEST=$(readlink -f "./packages")
[[ -z ${BASE_IMAGE} ]] && BASE_IMAGE="debian:jessie"
[[ -z ${BUILD_BRANCH} ]] && BUILD_BRANCH="dist/ubuntu/precise/master"
[[ -z ${PERSIST_CONTAINER} ]] && PERSIST_CONTAINER=0
#
# Warn user about "proxy"
#
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 "-"
fi fi
PROJECT_PATH="$(readlink -f $1)"
PROJECT_DIST="$(readlink -f $2)"
BASE_IMAGE="${3:-debian:jessie}"
main main