From 0d5e391e974cde55438ffdfdbc07219ed0d10bcb Mon Sep 17 00:00:00 2001 From: William Petit Date: Wed, 23 Sep 2015 16:54:53 +0200 Subject: [PATCH 1/4] Export des fichiers avec les droits de l'utilisteur du HOST --- .gitignore | 2 +- hooks/git/install-git-containerbuild | 2 +- hooks/tamarin/export-dist-postbuild | 16 ++++++++++++---- lib/build.sh | 3 ++- package.sh | 19 +++++++++++-------- 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 6f2dbb9..4463bf0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -dist +packages *.log *~ diff --git a/hooks/git/install-git-containerbuild b/hooks/git/install-git-containerbuild index 585549f..223f1d8 100755 --- a/hooks/git/install-git-containerbuild +++ b/hooks/git/install-git-containerbuild @@ -1,3 +1,3 @@ #!/usr/bin/env bash -echo "RUN apt-get install --yes --no-install-recommends git-core" >> Dockerfile +echo "RUN apt-get install --yes --no-install-recommends git-core git-buildpackage" >> Dockerfile diff --git a/hooks/tamarin/export-dist-postbuild b/hooks/tamarin/export-dist-postbuild index cd06a60..779e02e 100755 --- a/hooks/tamarin/export-dist-postbuild +++ b/hooks/tamarin/export-dist-postbuild @@ -1,10 +1,18 @@ #!/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 -mv ../*.deb /dist -mv ../*.changes /dist -mv ../*.dsc /dist -mv ../*.tar.xz /dist +move_output_to_dist "*.deb" +move_output_to_dist "*.changes" +move_output_to_dist "*.dsc" +move_output_to_dist "*.tar.{bz2,gz,lzma,xz}" + +chown -R ${HOST_UID}:${HOST_GID} /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/package.sh b/package.sh index 8df1e37..ec09d45 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 @@ -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 From 5bd63ab0efff2a6b391118722068ccdd6b568467 Mon Sep 17 00:00:00 2001 From: William Petit Date: Wed, 23 Sep 2015 17:42:08 +0200 Subject: [PATCH 2/4] =?UTF-8?q?WIP=20g=C3=A9n=C3=A9ration=20tarball=20sour?= =?UTF-8?q?ces?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hooks/{git => 00-git}/create-changelog-prebuild | 8 ++++++-- hooks/{git => 00-git}/install-git-containerbuild | 0 hooks/01-debian/create-orig-archive-prebuild | 10 ++++++++++ .../install-build-depends-prebuild | 0 hooks/{tamarin => 02-tamarin}/export-dist-postbuild | 1 + lib/build.sh | 2 +- 6 files changed, 18 insertions(+), 3 deletions(-) rename hooks/{git => 00-git}/create-changelog-prebuild (86%) rename hooks/{git => 00-git}/install-git-containerbuild (100%) create mode 100755 hooks/01-debian/create-orig-archive-prebuild rename hooks/{debian => 01-debian}/install-build-depends-prebuild (100%) rename hooks/{tamarin => 02-tamarin}/export-dist-postbuild (92%) diff --git a/hooks/git/create-changelog-prebuild b/hooks/00-git/create-changelog-prebuild similarity index 86% rename from hooks/git/create-changelog-prebuild rename to hooks/00-git/create-changelog-prebuild index f99d912..e5a8c11 100755 --- a/hooks/git/create-changelog-prebuild +++ b/hooks/00-git/create-changelog-prebuild @@ -20,7 +20,7 @@ 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}" fi @@ -51,7 +51,11 @@ do 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 + package_version=${version}.tamarin${version_suffix} + # Share computed package version + set_opt package_version ${package_version} + + echo "${project_name} (${package_version}) ${distribution}; urgency=${urgency}" >> debian/changelog echo >> debian/changelog diff --git a/hooks/git/install-git-containerbuild b/hooks/00-git/install-git-containerbuild similarity index 100% rename from hooks/git/install-git-containerbuild rename to hooks/00-git/install-git-containerbuild diff --git a/hooks/01-debian/create-orig-archive-prebuild b/hooks/01-debian/create-orig-archive-prebuild new file mode 100755 index 0000000..91a8633 --- /dev/null +++ b/hooks/01-debian/create-orig-archive-prebuild @@ -0,0 +1,10 @@ +#!/bin/bash + +source "${TAMARIN_UTIL}" + +project_name=$(get_opt project_name) +src_tarball="../${project_name}_${package_version}.orig.tar.gz" + +info "Creating sources tarball ${src_tarball}" + +tar -czf "${src_tarball}" . diff --git a/hooks/debian/install-build-depends-prebuild b/hooks/01-debian/install-build-depends-prebuild similarity index 100% rename from hooks/debian/install-build-depends-prebuild rename to hooks/01-debian/install-build-depends-prebuild diff --git a/hooks/tamarin/export-dist-postbuild b/hooks/02-tamarin/export-dist-postbuild similarity index 92% rename from hooks/tamarin/export-dist-postbuild rename to hooks/02-tamarin/export-dist-postbuild index 779e02e..923ef78 100755 --- a/hooks/tamarin/export-dist-postbuild +++ b/hooks/02-tamarin/export-dist-postbuild @@ -15,4 +15,5 @@ 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/lib/build.sh b/lib/build.sh index fb1d796..3c79750 100755 --- a/lib/build.sh +++ b/lib/build.sh @@ -34,7 +34,7 @@ function build_project() cd "${workspace}" - dpkg-buildpackage -b 2> >(error) 1> >(info) + dpkg-buildpackage -us -uc 2> >(error) 1> >(info) if [ $? != 0 ]; then fatal "The build process has not completed successfuly !" From 2cff8041dce4d6f3628eeb49333cb3ed37bac36a Mon Sep 17 00:00:00 2001 From: William Petit Date: Wed, 23 Sep 2015 21:21:30 +0200 Subject: [PATCH 3/4] Build quilt packages --- ...-prebuild => 00-create-changelog-prebuild} | 25 +++++++++++++++---- hooks/00-detect-debian-format-prebuild | 15 +++++++++++ ...uild => 00-install-build-depends-prebuild} | 2 +- ...ebuild => 01-create-orig-archive-prebuild} | 6 +++-- ...ist-postbuild => 99-export-dist-postbuild} | 0 hooks/{00-git => }/install-git-containerbuild | 2 +- lib/util.sh | 7 +++--- package.sh | 4 +-- 8 files changed, 47 insertions(+), 14 deletions(-) rename hooks/{00-git/create-changelog-prebuild => 00-create-changelog-prebuild} (72%) create mode 100755 hooks/00-detect-debian-format-prebuild rename hooks/{01-debian/install-build-depends-prebuild => 00-install-build-depends-prebuild} (54%) rename hooks/{01-debian/create-orig-archive-prebuild => 01-create-orig-archive-prebuild} (52%) rename hooks/{02-tamarin/export-dist-postbuild => 99-export-dist-postbuild} (100%) rename hooks/{00-git => }/install-git-containerbuild (72%) diff --git a/hooks/00-git/create-changelog-prebuild b/hooks/00-create-changelog-prebuild similarity index 72% rename from hooks/00-git/create-changelog-prebuild rename to hooks/00-create-changelog-prebuild index e5a8c11..b60404e 100755 --- a/hooks/00-git/create-changelog-prebuild +++ b/hooks/00-create-changelog-prebuild @@ -22,7 +22,7 @@ else tagbranch="build-tag-${BUILD_TAG}" git checkout -b ${tagbranch} set_opt "tag_branch" "${tag_branch}" - tags="${BUILD_TAG}" + local tags="${BUILD_TAG}" fi if [[ -z ${tags} ]] @@ -44,16 +44,31 @@ 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} - package_version=${version}.tamarin${version_suffix} - # Share computed package version - set_opt package_version ${package_version} + # 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 package version + set_opt project_version "${version}" + fi + + # Native packages should not have a revision number + if [ $(get_opt package_format) == 'native' ]; then + package_version=$(echo ${version} | grep -oE '^[0-9.]+') + fi echo "${project_name} (${package_version}) ${distribution}; urgency=${urgency}" >> debian/changelog diff --git a/hooks/00-detect-debian-format-prebuild b/hooks/00-detect-debian-format-prebuild new file mode 100755 index 0000000..880b10d --- /dev/null +++ b/hooks/00-detect-debian-format-prebuild @@ -0,0 +1,15 @@ +#!/bin/bash + +source "${TAMARIN_UTIL}" + +if [ -f "debian/source/format" ]; then + format=$(cat debian/source/format) + case ${format} in + "3.0 (native)") + set_opt package_format "native" + ;; + "3.0 (quilt)") + set_opt package_format "quilt" + ;; + esac +fi diff --git a/hooks/01-debian/install-build-depends-prebuild b/hooks/00-install-build-depends-prebuild similarity index 54% rename from hooks/01-debian/install-build-depends-prebuild rename to hooks/00-install-build-depends-prebuild index 8b6fe2d..8864ee6 100755 --- a/hooks/01-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/01-debian/create-orig-archive-prebuild b/hooks/01-create-orig-archive-prebuild similarity index 52% rename from hooks/01-debian/create-orig-archive-prebuild rename to hooks/01-create-orig-archive-prebuild index 91a8633..48bdd0a 100755 --- a/hooks/01-debian/create-orig-archive-prebuild +++ b/hooks/01-create-orig-archive-prebuild @@ -1,9 +1,11 @@ -#!/bin/bash +#!/usr/bin/env bash source "${TAMARIN_UTIL}" project_name=$(get_opt project_name) -src_tarball="../${project_name}_${package_version}.orig.tar.gz" +project_version=$(get_opt project_version) + +src_tarball="../${project_name}_${project_version}.orig.tar.gz" info "Creating sources tarball ${src_tarball}" diff --git a/hooks/02-tamarin/export-dist-postbuild b/hooks/99-export-dist-postbuild similarity index 100% rename from hooks/02-tamarin/export-dist-postbuild rename to hooks/99-export-dist-postbuild diff --git a/hooks/00-git/install-git-containerbuild b/hooks/install-git-containerbuild similarity index 72% rename from hooks/00-git/install-git-containerbuild rename to hooks/install-git-containerbuild index 223f1d8..585549f 100755 --- a/hooks/00-git/install-git-containerbuild +++ b/hooks/install-git-containerbuild @@ -1,3 +1,3 @@ #!/usr/bin/env bash -echo "RUN apt-get install --yes --no-install-recommends git-core git-buildpackage" >> Dockerfile +echo "RUN apt-get install --yes --no-install-recommends git-core" >> Dockerfile 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 ec09d45..5b503ac 100755 --- a/package.sh +++ b/package.sh @@ -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) From 913945a08c8504fadc9591d39260898160d9b498 Mon Sep 17 00:00:00 2001 From: William Petit Date: Wed, 23 Sep 2015 21:59:29 +0200 Subject: [PATCH 4/4] Empaquetage paquets binaires OK --- README.md | 57 +++++--------------------- hooks/00-create-changelog-prebuild | 7 +--- hooks/00-detect-debian-format-prebuild | 15 ------- hooks/01-create-orig-archive-prebuild | 12 ------ lib/build.sh | 2 +- 5 files changed, 13 insertions(+), 80 deletions(-) delete mode 100755 hooks/00-detect-debian-format-prebuild delete mode 100755 hooks/01-create-orig-archive-prebuild 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/00-create-changelog-prebuild b/hooks/00-create-changelog-prebuild index b60404e..debe135 100755 --- a/hooks/00-create-changelog-prebuild +++ b/hooks/00-create-changelog-prebuild @@ -61,15 +61,10 @@ do # Define project_version opt if not defined if [ -z "$(get_opt project_version)" ]; then - # Share computed package version + # Share computed project version set_opt project_version "${version}" fi - # Native packages should not have a revision number - if [ $(get_opt package_format) == 'native' ]; then - package_version=$(echo ${version} | grep -oE '^[0-9.]+') - fi - echo "${project_name} (${package_version}) ${distribution}; urgency=${urgency}" >> debian/changelog echo >> debian/changelog diff --git a/hooks/00-detect-debian-format-prebuild b/hooks/00-detect-debian-format-prebuild deleted file mode 100755 index 880b10d..0000000 --- a/hooks/00-detect-debian-format-prebuild +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -source "${TAMARIN_UTIL}" - -if [ -f "debian/source/format" ]; then - format=$(cat debian/source/format) - case ${format} in - "3.0 (native)") - set_opt package_format "native" - ;; - "3.0 (quilt)") - set_opt package_format "quilt" - ;; - esac -fi diff --git a/hooks/01-create-orig-archive-prebuild b/hooks/01-create-orig-archive-prebuild deleted file mode 100755 index 48bdd0a..0000000 --- a/hooks/01-create-orig-archive-prebuild +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash - -source "${TAMARIN_UTIL}" - -project_name=$(get_opt project_name) -project_version=$(get_opt project_version) - -src_tarball="../${project_name}_${project_version}.orig.tar.gz" - -info "Creating sources tarball ${src_tarball}" - -tar -czf "${src_tarball}" . diff --git a/lib/build.sh b/lib/build.sh index 3c79750..fb1d796 100755 --- a/lib/build.sh +++ b/lib/build.sh @@ -34,7 +34,7 @@ function build_project() 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 !"