Merge branch 'feature/getopt-git-dch' into develop
This commit is contained in:
commit
fc862e1369
|
@ -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
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
source "${TAMARIN_UTIL}"
|
||||
|
||||
if [ -f debian/changelog ] || [ ! -d .git ]; then
|
||||
|
@ -9,14 +8,42 @@ 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")
|
||||
|
||||
echo "BUILD TAG IS ${BUILD_TAG}"
|
||||
|
||||
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
|
||||
|
||||
if [[ -z ${tags} ]]
|
||||
then
|
||||
error "No relase tag found, you repo must have a tag like 'release/X.X'"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
touch debian/changelog
|
||||
|
||||
for tag in ${tags}
|
||||
do
|
||||
logs=$(git log --pretty=format:"%an - %h : %s" ${tag} | sed 's/"/\\"/g')
|
||||
|
||||
# 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=$(get_opt version 0.0.0)
|
||||
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)
|
||||
|
||||
|
@ -24,7 +51,7 @@ 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 "${project_name} (${version}.tamarin${version_suffix}) ${distribution}; urgency=${urgency}" >> debian/changelog
|
||||
|
||||
echo >> debian/changelog
|
||||
|
||||
|
@ -36,3 +63,4 @@ echo >> debian/changelog
|
|||
|
||||
echo " -- ${maintainer} $(date -R)" >> debian/changelog
|
||||
echo >> debian/changelog
|
||||
done
|
||||
|
|
15
lib/build.sh
15
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
|
||||
|
|
120
package.sh
120
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..."
|
||||
|
||||
local project_name=$(basename ${PROJECT_PATH})
|
||||
|
||||
# Create container & "$container_tag" variable
|
||||
create_container
|
||||
create_container ${project_name}
|
||||
|
||||
local project_name="$(basename "${PROJECT_PATH}")"
|
||||
local docker_opt="run -e \"DISTRIB=$BASE_IMAGE\" -e \"PROJECT_NAME=$project_name\""
|
||||
|
||||
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"
|
||||
|
||||
info "Done"
|
||||
|
||||
}
|
||||
|
||||
# Test for arguments
|
||||
if [ -z "$1" ] || [ -z "$2" ]; then
|
||||
show_usage
|
||||
exit 1
|
||||
if [[ ${PERSIST_CONTAINER} -eq 0 ]]
|
||||
then
|
||||
docker_opt="${docker_opt} --rm "
|
||||
else
|
||||
docker_opt="${docker_opt}"
|
||||
fi
|
||||
|
||||
PROJECT_PATH="$(readlink -f $1)"
|
||||
PROJECT_DIST="$(readlink -f $2)"
|
||||
BASE_IMAGE="${3:-debian:jessie}"
|
||||
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..."
|
||||
echo "docker ${docker_opt}"
|
||||
docker ${docker_opt}
|
||||
res=${?}
|
||||
|
||||
info "Done"
|
||||
return ${res}
|
||||
}
|
||||
|
||||
#
|
||||
# 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
|
||||
|
||||
main
|
||||
|
|
Loading…
Reference in New Issue