Base nouveau process d'empaquetage

This commit is contained in:
wpetit 2015-08-04 17:45:10 +02:00
parent 977776da2e
commit 51198bb298
5 changed files with 62 additions and 38 deletions

View File

@ -37,11 +37,12 @@ function main {
current_version=$(echo "$MANIFEST" | jq -r ".version" | sed 's/null//')
current_changelog=$(echo "$MANIFEST" | jq -r ".changelog" | sed 's/null//')
current_maintainer=$(echo "$MANIFEST" | jq -r ".maintainer" | sed 's/null//')
timestamp=$(date +%Y%m%d%H%M)
# Complete manifest
# Add commit number to version
MANIFEST=$(echo "$MANIFEST" | jq -r ".version = \"${current_version:-0.0.0}~$current_commit\"")
MANIFEST=$(echo "$MANIFEST" | jq -r ".version = \"${current_version:-0.0.0}+$timestamp~$current_commit\"")
# Set name if not defined
MANIFEST=$(echo "$MANIFEST" | jq -r ".name = \"${current_name:-$repo_name}\"")
# Set maintainer if not defined

View File

@ -1,5 +1,7 @@
#!/usr/bin/env bash
#set -x
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source "${DIR}/util.sh"
@ -9,7 +11,9 @@ SRC_DIR="${BASE_DIR}/src"
function get_project_opt {
filter=${1}
manifest_path=${SRC_DIR}/tamarin.json
jq -r "${filter}" ${manifest_path} | sed 's/null//g'
if [ -e "${manifest_path}" ]; then
jq -r "${filter}" ${manifest_path} | sed 's/null//g'
fi
}
function get_build_dir {
@ -25,10 +29,15 @@ function exec_hook {
hook_name=${1}
build_dir=${2}
hook_script="${SRC_DIR}/$(get_project_opt .hooks.${hook_name})"
hook_script="$(get_project_opt .hooks.${hook_name} | sed 's/null//')"
# Test hook script existence
if [ ! -f "${hook_script}" ]; then
# if [ ! -f "${hook_script}" ]; then
# info "No ${hook_name} hook."
# return
# fi
if [ -z "${hook_script}" ]; then
info "No ${hook_name} hook."
return
fi
@ -36,10 +45,10 @@ function exec_hook {
info "Executing ${hook_name} hook..."
# Ensure the hook script is executable
chmod +x "${hook_script}"
#chmod +x "${hook_script}"
# Execute hook in a subshell
( cd ${SRC_DIR} && DESTDIR="${build_dir}" SRCDIR="${SRC_DIR}" exec "${hook_script}" )
( cd ${SRC_DIR} && DESTDIR="${build_dir}" SRCDIR="${SRC_DIR}" ${hook_script} )
# If the script did not execute properly, we stop here
if [ $? != 0 ]; then
@ -70,7 +79,18 @@ function create_debian_control_file {
package_arch=$(get_project_opt .arch)
echo "Architecture: ${package_arch:-all}" >> "${control_file}"
dependencies=$( get_project_opt ".dependencies | .[\"${DISTRIB}\"] | @sh" | sed "s/' '/, /g" | sed "s/'//g" )
dependencies=$(get_project_opt ".dependencies | .[\"${DISTRIB}\"]")
if [ ! -z "${dependencies}" ]; then
dependencies=""
for depKey in $(get_project_opt ".dependencies | .[\"${DISTRIB}\"] | keys | @sh"); do
depKey=$(echo ${depKey} | sed "s/^'\(.*\)'$/\1/");
depValue=$(get_project_opt ".dependencies | .[\"${DISTRIB}\"] | .[\"${depKey}\"]" | sed "s/^'\(.*\)'$/\1/")
dependencies="${depKey} ($depValue), ${dependencies}"
done
fi
dependencies=$(echo ${dependencies} | sed 's/,$//')
debug "Package dependencies: ${dependencies:-None}"
@ -119,7 +139,8 @@ function create_debian_changelog {
debian_dir="${1}"
changelog="${debian_dir}/changelog"
logs="$(get_project_opt '.changelog | map(.+"\n") | add')"
logs="$(get_project_opt '.changelog' | sed 's/null//')"
logs="$(echo ${logs:-[]} | jq 'map(.+"\n") | add' | sed 's/null/No information/g')"
package_name=$(get_project_opt .name)
package_version=$(get_project_opt .version)
maintainer=$(get_project_opt .maintainer)
@ -133,7 +154,7 @@ function create_debian_changelog {
echo >> "${changelog}"
echo "-- ${maintainer} $(date -R)" >> "${changelog}"
echo "-- ${maintainer:-Unknown} $(date -R)" >> "${changelog}"
}
@ -153,40 +174,43 @@ function create_debian_metadata {
function build_project {
project_name="$(get_project_opt '.name')"
info "Building project '${PROJECT_NAME}'..."
info "Building project '${project_name}'..."
build_dir="$(get_build_dir "${project_name}")"
build_dir="$(get_build_dir '${PROJECT_NAME}')"
debug "Build dir: ${build_dir}"
# We don't generate Debian metadata files if a debian directory is present
if [ ! -d "${SRC_DIR}/DEBIAN" ] && [ ! -d "${SRC_DIR}/debian" ]; then
if [ ! -d "${SRC_DIR}/debian" ]; then
info "No Debian directory detected in sources."
info "Generating Debian metadata files from manifest..."
info "Generating Debian metadata files from Tamarin manifest..."
create_debian_metadata "${build_dir}"
else
info "A Debian directory is already present in sources."
fi
exec_hook "preBuild" "${build_dir}"
exec_hook "prebuild" "${build_dir}"
# Ensure $DIST_DIR exists
mkdir -p "${DIST_DIR}"
cd "${build_dir}/.."
dpkg-deb --build "${project_name}" ${DIST_DIR}
info "Package created ! (${build_dir}/${project_name}.deb)"
cd ${SRC_DIR}
dpkg-buildpackage -us -uc
if [ $? != 0 ]; then
fatal "The build process has not completed successfuly !"
fi
cd ${SRC_DIR}
# Create new directory
mkdir -p "${DIST_DIR}/${PROJECT_NAME}/"
exec_hook "postBuild" "${build_dir}"
# Move generated files
mv ../*.deb "${DIST_DIR}/${PROJECT_NAME}/"
mv ../*.changes "${DIST_DIR}/${PROJECT_NAME}/"
mv ../*.dsc "${DIST_DIR}/${PROJECT_NAME}/"
mv ../*.tar.xz "${DIST_DIR}/${PROJECT_NAME}/"
exec_hook "postbuild" "${build_dir}"
}
@ -194,7 +218,7 @@ function main {
manifest_path=${SRC_DIR}/tamarin.json
if [ ! -f "${manifest_path}" ] && [ ! -d "${SRC_DIR}/debian" ] && [ ! -d "${SRC_DIR}/DEBIAN" ]; then
if [ ! -f "${manifest_path}" ] && [ ! -d "${SRC_DIR}/debian" ]; then
fatal "There is no 'tamarin.json' nor debian packaging files in the project directory !"
fi

View File

@ -0,0 +1 @@
#!/bin/bash

View File

@ -7,13 +7,13 @@ source "$DIR/lib/util.sh"
function show_usage {
echo
echo "Usage: $0 <src> <dist> <image>"
echo "Usage: $0 src dist [image]"
echo
echo "Paramètres: "
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> Nom de l'image Docker à utiliser comme base pourl'environnement de build. Exemple: debian:jessie"
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 Nom de l'image Docker à utiliser comme base pourl'environnement de build. Défaut: debian:jessie"
echo
}
@ -37,7 +37,7 @@ function create_container {
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update &&\
apt-get install jq
apt-get install --yes jq build-essential dh-make
ADD ./lib /root/.tamarin
RUN chmod +x /root/.tamarin/build.sh
@ -64,23 +64,22 @@ function main {
info "Building container from $BASE_IMAGE..."
container_tag="$(create_container)"
project_name="$(basename "${PROJECT_PATH}")"
info "Launching container..."
docker run -e "DISTRIB=$BASE_IMAGE" --rm -v="$PROJECT_PATH:/src" -v="$PROJECT_DIST:/dist" "$container_tag"
info "Cleaning container data..."
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" ] || [ -z "$3" ]; then
if [ -z "$1" ] || [ -z "$2" ]; then
show_usage
exit 1
fi
PROJECT_PATH="$(readlink -f $1)"
PROJECT_DIST="$(readlink -f $2)"
BASE_IMAGE="$3"
BASE_IMAGE="${3:-debian:jessie}"
main

View File

@ -1,14 +1,13 @@
{
"name": "hello-world",
"dependencies": {
"debian:jessie": [
"apache2 (>= 2.4)",
"php5 (>= 5.4)"
]
"debian:jessie": {
"apache2": ">= 2.4",
"php5": ">= 5.4"
}
},
"hooks": {
"preBuild": "./scripts/pre-build.sh",
"postBuild": "./scripts/post-build.sh",
"preInstall": "./scripts/pre-install.sh",
"preRemove": "",
"postInstall": "",