diff --git a/.gitignore b/.gitignore index 6f2dbb9..4463bf0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -dist +packages *.log *~ diff --git a/README.md b/README.md index efa5557..5656cb3 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Tamarin -Usine à paquets Debian basée sur Docker. +Usine à paquets binaires Debian basée sur Docker. ## Dépendances @@ -9,53 +9,18 @@ Vous devez avoir [docker](https://docs.docker.com/installation/) installé sur v ## Utilisation ``` -./package-project.sh +Usage: ./package.sh -p project_path [-d destination] [-i image] [-k] + +Parameters: + + -p Path to the project to build + -d Optional : Destination of the builed packages (default ./packages) + -i Optional : Name of the Docker image to use for build (default: debian:jessie) + -k Optional : Keep the Docker container after build + -b Optional : Build directory (default /tmp) + -B Optional : Build branch (for git projects only) (default dist/ubuntu/precise/master) ``` -**Exemple:** *en étant placé dans le répertoire du projet Tamarin* -``` -./package-project.sh ./src-example ./dist "debian:jessie" -``` - -## Le fichier manifeste `tamarin.json` - -La génération des fichiers de métadonnées nécessaires à la construction du paquet peut être semi-automatisé via l'ajout d'un fichier manifeste `tamarin.json` à la racine du projet. - -Si le répertoire `DEBIAN` est déjà présent à la racine du projet, Tamarin n'effectuera pas cette étape. - -Ce fichier à la structure suivante: - -```js -{ - "name": "hello-world", // Nom du projet - "version": "0.0.0", // Version - "dependencies": { // Dépendances du projet suivant la distribution cible - "debian:jessie": [ - "apache2 (>= 2.4)", - "php5 (>= 5.4)" - ] - }, - "hooks": { // Hooks liés au cycle de vie du paquet - "preBuild": "./scripts/pre-build.sh", - "postBuild": "./scripts/post-build.sh", - "preInstall": "", - "preRemove": "", - "postInstall": "", - "postRemove": "" - } -} -``` -### Les hooks - -|Hook |Contexte |Description| -|------------|---------------------------------------------------|-----------| -|preBuild |Exécuté dans le conteneur de construction du paquet|TODO| -|postBuild |Exécuté dans le conteneur de construction du paquet|TODO| -|preInstall |Exécuté juste avant l'installation du paquet |TODO| -|postInstall |Exécuté juste après l'installation du paquet |TODO| -|preRemove |Exécuté juste avant la suppression du paquet |TODO| -|postRemove |Exécuté juste après la suppression du paquet |TODO| - ## Licence GPLv3 diff --git a/hooks/git/create-changelog-prebuild b/hooks/00-create-changelog-prebuild similarity index 72% rename from hooks/git/create-changelog-prebuild rename to hooks/00-create-changelog-prebuild index f99d912..debe135 100755 --- a/hooks/git/create-changelog-prebuild +++ b/hooks/00-create-changelog-prebuild @@ -20,9 +20,9 @@ then else info "DEBUG DEBUG DEBUG " tagbranch="build-tag-${BUILD_TAG}" - git checkout -b ${tagbranch} + git checkout -b ${tagbranch} set_opt "tag_branch" "${tag_branch}" - tags="${BUILD_TAG}" + local tags="${BUILD_TAG}" fi if [[ -z ${tags} ]] @@ -44,14 +44,28 @@ do 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} + version_suffix=tamarin${commit_count}~${current_commit} + package_version=${version}-${version_suffix} - echo "${project_name} (${version}.tamarin${version_suffix}) ${distribution}; urgency=${urgency}" >> debian/changelog + # Define package_version opt if not defined + if [ -z "$(get_opt package_version)" ]; then + # Share computed package version + set_opt package_version "${package_version}" + fi + + # Define project_version opt if not defined + if [ -z "$(get_opt project_version)" ]; then + # Share computed project version + set_opt project_version "${version}" + fi + + echo "${project_name} (${package_version}) ${distribution}; urgency=${urgency}" >> debian/changelog echo >> debian/changelog diff --git a/hooks/debian/install-build-depends-prebuild b/hooks/00-install-build-depends-prebuild similarity index 54% rename from hooks/debian/install-build-depends-prebuild rename to hooks/00-install-build-depends-prebuild index 8b6fe2d..8864ee6 100755 --- a/hooks/debian/install-build-depends-prebuild +++ b/hooks/00-install-build-depends-prebuild @@ -4,5 +4,5 @@ source "${TAMARIN_UTIL}" if [ -f debian/control ]; then info "Installing build dependencies..." - mk-build-deps -t "apt-get --force-yes -y" --install debian/control + mk-build-deps -r -t "apt-get --force-yes -y --no-install-recommends" --install debian/control fi diff --git a/hooks/99-export-dist-postbuild b/hooks/99-export-dist-postbuild new file mode 100755 index 0000000..923ef78 --- /dev/null +++ b/hooks/99-export-dist-postbuild @@ -0,0 +1,19 @@ +#!/bin/bash + +source "${TAMARIN_UTIL}" + +function move_output_to_dist { + find '../' -maxdepth 1 -name "$1" -type f -print0 | xargs -0r mv -t /dist/ +} + +# Create new directory +mkdir -p /dist + +# Move generated files +move_output_to_dist "*.deb" +move_output_to_dist "*.changes" +move_output_to_dist "*.dsc" +move_output_to_dist "*.tar.{bz2,gz,lzma,xz}" + +# Configure files permissions +chown -R ${HOST_UID}:${HOST_GID} /dist diff --git a/hooks/git/install-git-containerbuild b/hooks/install-git-containerbuild similarity index 100% rename from hooks/git/install-git-containerbuild rename to hooks/install-git-containerbuild diff --git a/hooks/tamarin/export-dist-postbuild b/hooks/tamarin/export-dist-postbuild deleted file mode 100755 index cd06a60..0000000 --- a/hooks/tamarin/export-dist-postbuild +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -# Create new directory -mkdir -p /dist - -# Move generated files -mv ../*.deb /dist -mv ../*.changes /dist -mv ../*.dsc /dist -mv ../*.tar.xz /dist diff --git a/lib/build.sh b/lib/build.sh index a3f3ffc..fb1d796 100755 --- a/lib/build.sh +++ b/lib/build.sh @@ -33,7 +33,8 @@ function build_project() exec_hooks "prebuild" "${workspace}" cd "${workspace}" - dpkg-buildpackage -us -uc 2> >(error) 1> >(info) + + dpkg-buildpackage -b 2> >(error) 1> >(info) if [ $? != 0 ]; then fatal "The build process has not completed successfuly !" diff --git a/lib/util.sh b/lib/util.sh index cb404e2..9faca65 100644 --- a/lib/util.sh +++ b/lib/util.sh @@ -2,6 +2,7 @@ HOOKS_DIR="${BASE_DIR}/hooks" OPT_FILE="${BASE_DIR}/tmp/.tamarin_opts" +OPT_PREFIX="tamarin_opt_" function info { if [ -z "$@" ]; then @@ -50,7 +51,7 @@ function log { } function get_opt { - local opt_name=${1} + local opt_name=${OPT_PREFIX}${1} local default_value=${2} touch "${OPT_FILE}" source "${OPT_FILE}" @@ -61,8 +62,8 @@ function set_opt { local opt_name=${1} local opt_value=${2} touch "${OPT_FILE}" - sed -i "s/^${opt_name}*$//" "${OPT_FILE}" - echo "${opt_name}=\"${opt_value}\"" >> "${OPT_FILE}" + sed -i "s/^${OPT_PREFIX}${opt_name}*$//" "${OPT_FILE}" + echo "${OPT_PREFIX}${opt_name}=\"${opt_value}\"" >> "${OPT_FILE}" } function exec_hooks { diff --git a/package.sh b/package.sh index 8df1e37..5b503ac 100755 --- a/package.sh +++ b/package.sh @@ -47,7 +47,7 @@ function create_container { ENV DEBIAN_FRONTEND noninteractive RUN apt-get update &&\ - apt-get install --yes build-essential devscripts equivs git-buildpackage + apt-get install --yes --no-install-recommends build-essential devscripts equivs RUN mkdir /root/.tamarin RUN mkdir /project @@ -60,6 +60,8 @@ function create_container { VOLUME /dist EOF + exec_hooks "containerbuild" "$temp_dir" + if [[ -z ${BUILD_DIR} ]] then echo " CMD /root/.tamarin/lib/build.sh ${projectName} ${BUILD_BRANCH} /tmp ${BUILD_TAG}" >> "$temp_dir/Dockerfile" @@ -68,8 +70,6 @@ EOF echo " CMD /root/.tamarin/lib/build.sh ${projectName} ${BUILD_BRANCH} /build ${BUILD_TAG}" >> "$temp_dir/Dockerfile" fi - exec_hooks "containerbuild" "$temp_dir" - # Build image tar -C "$temp_dir" -czh . | docker build -t "$container_tag" - 2> >(error) 1> >(info) @@ -90,22 +90,25 @@ function main { local docker_opt="run -e \"DISTRIB=$BASE_IMAGE\" -e \"PROJECT_NAME=$project_name\"" - if [[ ${PERSIST_CONTAINER} -eq 0 ]] + # Expose host uid & gid + docker_opt="${docker_opt} -e HOST_UID=$(id -u) -e HOST_GID=$(id -g)" + + 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" + docker_opt="${docker_opt} -v=\"$PROJECT_PATH:/src:ro\" -v=\"$PROJECT_DEST:/dist:rw\" $container_tag" else - docker_opt="${docker_opt} -v=\"$PROJECT_PATH:/src\" -v=\"$PROJECT_DEST:/dist\" -v=\"${BUILD_DIR}:/build\" $container_tag" + docker_opt="${docker_opt} -v=\"$PROJECT_PATH:/src:ro\" -v=\"$PROJECT_DEST:/dist:rw\" -v=\"${BUILD_DIR}:/build\" $container_tag" fi info "Switching to container..." - echo "docker ${docker_opt}" + debug "docker ${docker_opt}" docker ${docker_opt} res=${?} @@ -114,8 +117,8 @@ function main { } # -# Parsing options -# +# Parsing options +# while getopts "kp:d:i:b:B:t:" option do case $option in