diff --git a/hooks/debian/install-build-depends-prebuild b/hooks/debian/install-build-depends-prebuild index f98c2a1..8b6fe2d 100755 --- a/hooks/debian/install-build-depends-prebuild +++ b/hooks/debian/install-build-depends-prebuild @@ -4,5 +4,5 @@ source "${TAMARIN_UTIL}" if [ -f debian/control ]; then info "Installing build dependencies..." - mk-build-deps --install debian/control + mk-build-deps -t "apt-get --force-yes -y" --install debian/control fi diff --git a/hooks/git/create-changelog-prebuild b/hooks/git/create-changelog-prebuild index dbd0bcc..f99d912 100755 --- a/hooks/git/create-changelog-prebuild +++ b/hooks/git/create-changelog-prebuild @@ -1,5 +1,4 @@ #!/usr/bin/env bash - source "${TAMARIN_UTIL}" if [ -f debian/changelog ] || [ ! -d .git ]; then @@ -9,30 +8,59 @@ fi # 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 -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}") +echo "BUILD TAG IS ${BUILD_TAG}" -project_name=$(get_opt project_name) -version=$(get_opt version 0.0.0) -distribution=$(get_opt distribution UNRELEASED) -urgency=$(get_opt urgency low) +if [[ ${BUILD_TAG} == "last" ]] +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}" + tags="${BUILD_TAG}" +fi -commit_count=$(git rev-list --count --first-parent HEAD) -current_commit=$(git log -n 1 --pretty=format:"%h") -version_suffix=${commit_count}~${current_commit} +if [[ -z ${tags} ]] +then + 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 -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 >> debian/changelog + echo " -- ${maintainer} $(date -R)" >> debian/changelog + echo >> debian/changelog +done diff --git a/lib/build.sh b/lib/build.sh index 4268f31..a3f3ffc 100755 --- a/lib/build.sh +++ b/lib/build.sh @@ -7,14 +7,23 @@ source "${TAMARIN_UTIL}" 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 { +function build_project() +{ - info "Building project ${PROJECT_NAME}..." + info "Building project '${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}" # Copy sources to workspace diff --git a/package.sh b/package.sh index 252722e..8df1e37 100755 --- a/package.sh +++ b/package.sh @@ -9,14 +9,18 @@ BASE_DIR="$TAMARIN_DIR" source "$TAMARIN_DIR/lib/util.sh" function show_usage { echo - echo "Usage: $0 src dist [image]" + echo "Usage: $0 -p project_path [-d destination] [-i image] [-k]" echo - echo "Paramètres: " + echo "Parameters: " echo - echo " - src Chemin vers le répertoire des sources du projet à empaqueter" - echo " - dist Chemin vers le répertoire de destination du paquet à créer" - echo " - image Optionel - Nom de l'image Docker à utiliser comme base pourl'environnement de build. Défaut: debian:jessie" + echo " -p Path to the project to build" + 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 } # Create a build container based on the $BASE_IMAGE argument @@ -29,6 +33,9 @@ function create_container { # Create temporary dir for the Dockerfile 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" ln -s $(readlink -f "$TAMARIN_DIR/hooks") "$temp_dir/hooks" @@ -40,7 +47,7 @@ function create_container { ENV DEBIAN_FRONTEND noninteractive 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 /project @@ -51,11 +58,16 @@ function create_container { VOLUME /src VOLUME /dist - - CMD /root/.tamarin/lib/build.sh - 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" # Build image @@ -71,26 +83,84 @@ function main { info "Building container from $BASE_IMAGE..." - # Create container & "$container_tag" variable - create_container + local project_name=$(basename ${PROJECT_PATH}) - 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..." - 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" - + return ${res} } -# Test for arguments -if [ -z "$1" ] || [ -z "$2" ]; then - show_usage - exit 1 +# +# 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 + ;; + 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 -PROJECT_PATH="$(readlink -f $1)" -PROJECT_DIST="$(readlink -f $2)" -BASE_IMAGE="${3:-debian:jessie}" - main