Base nouveau process d'empaquetage
This commit is contained in:
parent
977776da2e
commit
51198bb298
|
@ -37,11 +37,12 @@ function main {
|
||||||
current_version=$(echo "$MANIFEST" | jq -r ".version" | sed 's/null//')
|
current_version=$(echo "$MANIFEST" | jq -r ".version" | sed 's/null//')
|
||||||
current_changelog=$(echo "$MANIFEST" | jq -r ".changelog" | sed 's/null//')
|
current_changelog=$(echo "$MANIFEST" | jq -r ".changelog" | sed 's/null//')
|
||||||
current_maintainer=$(echo "$MANIFEST" | jq -r ".maintainer" | sed 's/null//')
|
current_maintainer=$(echo "$MANIFEST" | jq -r ".maintainer" | sed 's/null//')
|
||||||
|
timestamp=$(date +%Y%m%d%H%M)
|
||||||
|
|
||||||
# Complete manifest
|
# Complete manifest
|
||||||
|
|
||||||
# Add commit number to version
|
# 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
|
# Set name if not defined
|
||||||
MANIFEST=$(echo "$MANIFEST" | jq -r ".name = \"${current_name:-$repo_name}\"")
|
MANIFEST=$(echo "$MANIFEST" | jq -r ".name = \"${current_name:-$repo_name}\"")
|
||||||
# Set maintainer if not defined
|
# Set maintainer if not defined
|
||||||
|
|
68
lib/build.sh
68
lib/build.sh
|
@ -1,5 +1,7 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
#set -x
|
||||||
|
|
||||||
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||||
source "${DIR}/util.sh"
|
source "${DIR}/util.sh"
|
||||||
|
|
||||||
|
@ -9,7 +11,9 @@ SRC_DIR="${BASE_DIR}/src"
|
||||||
function get_project_opt {
|
function get_project_opt {
|
||||||
filter=${1}
|
filter=${1}
|
||||||
manifest_path=${SRC_DIR}/tamarin.json
|
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 {
|
function get_build_dir {
|
||||||
|
@ -25,10 +29,15 @@ function exec_hook {
|
||||||
hook_name=${1}
|
hook_name=${1}
|
||||||
build_dir=${2}
|
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
|
# 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."
|
info "No ${hook_name} hook."
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
@ -36,10 +45,10 @@ function exec_hook {
|
||||||
info "Executing ${hook_name} hook..."
|
info "Executing ${hook_name} hook..."
|
||||||
|
|
||||||
# Ensure the hook script is executable
|
# Ensure the hook script is executable
|
||||||
chmod +x "${hook_script}"
|
#chmod +x "${hook_script}"
|
||||||
|
|
||||||
# Execute hook in a subshell
|
# 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 the script did not execute properly, we stop here
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
|
@ -70,7 +79,18 @@ function create_debian_control_file {
|
||||||
package_arch=$(get_project_opt .arch)
|
package_arch=$(get_project_opt .arch)
|
||||||
echo "Architecture: ${package_arch:-all}" >> "${control_file}"
|
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}"
|
debug "Package dependencies: ${dependencies:-None}"
|
||||||
|
|
||||||
|
@ -119,7 +139,8 @@ function create_debian_changelog {
|
||||||
debian_dir="${1}"
|
debian_dir="${1}"
|
||||||
changelog="${debian_dir}/changelog"
|
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_name=$(get_project_opt .name)
|
||||||
package_version=$(get_project_opt .version)
|
package_version=$(get_project_opt .version)
|
||||||
maintainer=$(get_project_opt .maintainer)
|
maintainer=$(get_project_opt .maintainer)
|
||||||
|
@ -133,7 +154,7 @@ function create_debian_changelog {
|
||||||
|
|
||||||
echo >> "${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 {
|
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}"
|
debug "Build dir: ${build_dir}"
|
||||||
|
|
||||||
# We don't generate Debian metadata files if a debian directory is present
|
# 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 "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}"
|
create_debian_metadata "${build_dir}"
|
||||||
else
|
else
|
||||||
info "A Debian directory is already present in sources."
|
info "A Debian directory is already present in sources."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exec_hook "preBuild" "${build_dir}"
|
exec_hook "prebuild" "${build_dir}"
|
||||||
|
|
||||||
# Ensure $DIST_DIR exists
|
# Ensure $DIST_DIR exists
|
||||||
mkdir -p "${DIST_DIR}"
|
mkdir -p "${DIST_DIR}"
|
||||||
|
|
||||||
cd "${build_dir}/.."
|
cd ${SRC_DIR}
|
||||||
dpkg-deb --build "${project_name}" ${DIST_DIR}
|
dpkg-buildpackage -us -uc
|
||||||
|
|
||||||
info "Package created ! (${build_dir}/${project_name}.deb)"
|
|
||||||
|
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
fatal "The build process has not completed successfuly !"
|
fatal "The build process has not completed successfuly !"
|
||||||
fi
|
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
|
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 !"
|
fatal "There is no 'tamarin.json' nor debian packaging files in the project directory !"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
#!/bin/bash
|
|
@ -7,13 +7,13 @@ source "$DIR/lib/util.sh"
|
||||||
|
|
||||||
function show_usage {
|
function show_usage {
|
||||||
echo
|
echo
|
||||||
echo "Usage: $0 <src> <dist> <image>"
|
echo "Usage: $0 src dist [image]"
|
||||||
echo
|
echo
|
||||||
echo "Paramètres: "
|
echo "Paramètres: "
|
||||||
echo
|
echo
|
||||||
echo " - <src> Chemin vers le répertoire des sources du projet à empaqueter"
|
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 " - 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 " - image Nom de l'image Docker à utiliser comme base pourl'environnement de build. Défaut: debian:jessie"
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ function create_container {
|
||||||
ENV DEBIAN_FRONTEND noninteractive
|
ENV DEBIAN_FRONTEND noninteractive
|
||||||
|
|
||||||
RUN apt-get update &&\
|
RUN apt-get update &&\
|
||||||
apt-get install jq
|
apt-get install --yes jq build-essential dh-make
|
||||||
|
|
||||||
ADD ./lib /root/.tamarin
|
ADD ./lib /root/.tamarin
|
||||||
RUN chmod +x /root/.tamarin/build.sh
|
RUN chmod +x /root/.tamarin/build.sh
|
||||||
|
@ -64,23 +64,22 @@ function main {
|
||||||
|
|
||||||
info "Building container from $BASE_IMAGE..."
|
info "Building container from $BASE_IMAGE..."
|
||||||
container_tag="$(create_container)"
|
container_tag="$(create_container)"
|
||||||
|
project_name="$(basename "${PROJECT_PATH}")"
|
||||||
|
|
||||||
info "Launching container..."
|
info "Launching container..."
|
||||||
docker run -e "DISTRIB=$BASE_IMAGE" --rm -v="$PROJECT_PATH:/src" -v="$PROJECT_DIST:/dist" "$container_tag"
|
docker run -e "DISTRIB=$BASE_IMAGE" -e "PROJECT_NAME=$project_name" --rm -v="$PROJECT_PATH:/src" -v="$PROJECT_DIST:/dist" "$container_tag"
|
||||||
|
|
||||||
info "Cleaning container data..."
|
|
||||||
|
|
||||||
info "Done"
|
info "Done"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Test for arguments
|
# Test for arguments
|
||||||
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
|
if [ -z "$1" ] || [ -z "$2" ]; then
|
||||||
show_usage
|
show_usage
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
PROJECT_PATH="$(readlink -f $1)"
|
PROJECT_PATH="$(readlink -f $1)"
|
||||||
PROJECT_DIST="$(readlink -f $2)"
|
PROJECT_DIST="$(readlink -f $2)"
|
||||||
BASE_IMAGE="$3"
|
BASE_IMAGE="${3:-debian:jessie}"
|
||||||
|
|
||||||
main
|
main
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
{
|
{
|
||||||
"name": "hello-world",
|
"name": "hello-world",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"debian:jessie": [
|
"debian:jessie": {
|
||||||
"apache2 (>= 2.4)",
|
"apache2": ">= 2.4",
|
||||||
"php5 (>= 5.4)"
|
"php5": ">= 5.4"
|
||||||
]
|
}
|
||||||
},
|
},
|
||||||
"hooks": {
|
"hooks": {
|
||||||
"preBuild": "./scripts/pre-build.sh",
|
"preBuild": "./scripts/pre-build.sh",
|
||||||
"postBuild": "./scripts/post-build.sh",
|
|
||||||
"preInstall": "./scripts/pre-install.sh",
|
"preInstall": "./scripts/pre-install.sh",
|
||||||
"preRemove": "",
|
"preRemove": "",
|
||||||
"postInstall": "",
|
"postInstall": "",
|
||||||
|
|
Loading…
Reference in New Issue