diff --git a/README.md b/README.md index fd502a3..b823ac8 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,38 @@ # Tamarin -Usine à paquets binaires Debian basée sur Docker. +Usine à paquets expérimentale basée sur rkt/acbuild. + +## Formats de paquets/distributions supportés + +- `.deb` (Debian, Ubuntu) ## Dépendances -Vous devez avoir [docker](https://docs.docker.com/installation/) installé sur votre machine. +- [Python 3](https://www.python.org/downloads/) +- Un noyau Linux > 2.6.24 (avec support des cgroups) -## Utilisation +**Optionnel mais conseillé** +- [systemd](https://freedesktop.org/wiki/Software/systemd/) + +## Usage + +```bash +./package --help ``` -Usage: ./package.sh -p project_path [-d destination] [-i image] [-k] +## Fonctionnement -Parameters: +### Les profils de construction - -p Path to the project to build - -a Optional : Architecture choice (-a i386 for example) - -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) -``` +TODO + +### Les attributs de construction + +TODO + +### Répertoire de travail et mise en cache des images + +TODO ## Licence diff --git a/hooks/build/debian/build b/hooks/build/debian/build new file mode 100755 index 0000000..1f47226 --- /dev/null +++ b/hooks/build/debian/build @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +cd src +dpkg-buildpackage -b -a"${TAMARIN_TARGET_ARCH}" diff --git a/hooks/containerbuild/debian/install-build-essential b/hooks/containerbuild/debian/install-build-essential index 0ac1731..ed0cbfb 100755 --- a/hooks/containerbuild/debian/install-build-essential +++ b/hooks/containerbuild/debian/install-build-essential @@ -1,14 +1,8 @@ #!/usr/bin/env bash -HAS_SYSTEMD=$(which systemctl) -ENGINE=chroot -if [ ! -z "${HAS_SYSTEMD}" ]; then - ENGINE=systemd-nspawn -fi - ${TAMARIN_ACBUILD} environment add DEBIAN_FRONTEND noninteractive -if [ "${ENGINE}" == 'chroot' ]; then +if [ "${TAMARIN_ACBUILD_ENGINE}" == 'chroot' ]; then # Ugly fix for Python installation in chrooted environment (require /dev/urandom) head -c 65536 /dev/urandom > ./urandom ${TAMARIN_ACBUILD} copy ./urandom /dev/urandom @@ -16,15 +10,15 @@ fi sudo -E /usr/bin/env bash - <> debian/changelog diff --git a/hooks/06-create-dummy-changelog-prebuild b/hooks/prebuild/debian/create-dummy-changelog similarity index 74% rename from hooks/06-create-dummy-changelog-prebuild rename to hooks/prebuild/debian/create-dummy-changelog index 288e586..9b97488 100755 --- a/hooks/06-create-dummy-changelog-prebuild +++ b/hooks/prebuild/debian/create-dummy-changelog @@ -1,14 +1,15 @@ #!/usr/bin/env bash -source "${TAMARIN_UTIL}" + +cd src if [ -f debian/changelog ] || [ ! -d .git ]; then - info "Not a Git repository or Debian changelog already exists !" + tamarin_info "Not a Git repository or Debian changelog already exists !" exit fi changelog="debian/changelog" -project_name=$(get_opt project_name) -project_version=$(get_opt project_version 0.0.0) +project_name=$(tamarin_db get project_name) +project_version=$(tamarin_db get project_version 0.0.0) date=$(date -R) top_contributor=$(git log --pretty=short | git shortlog -s -n -e | sed 's/^\s*[0-9]*\s*//g' | head -n 1) current_commit=$(git log -n 1 --pretty=format:%h) diff --git a/hooks/10-install-build-depends-prebuild b/hooks/prebuild/debian/install-build-depends similarity index 96% rename from hooks/10-install-build-depends-prebuild rename to hooks/prebuild/debian/install-build-depends index e63e432..0ff2014 100755 --- a/hooks/10-install-build-depends-prebuild +++ b/hooks/prebuild/debian/install-build-depends @@ -1,5 +1,7 @@ #!/bin/bash +cd src + if [ -f debian/control ]; then echo "Installing build dependencies..." apt-get update diff --git a/hooks/prebuild/debian/load-project-db b/hooks/prebuild/debian/load-project-db new file mode 100755 index 0000000..0f7d99b --- /dev/null +++ b/hooks/prebuild/debian/load-project-db @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +tamarin_db load diff --git a/lib/build.py b/lib/build.py index e067568..1f2d7de 100644 --- a/lib/build.py +++ b/lib/build.py @@ -1,3 +1,32 @@ +import sys, os, argparse, tempfile +sys.path.append(os.path.dirname(__file__) + '/lib') +import tamarin, system, rkt + +def get_args_parser(): + parser = argparse.ArgumentParser(description="Tamarin's container entrypoint") + # Define available/required arguments and flags + parser.add_argument("profile", help="The selected profile to use for the build") + parser.add_argument("arch", help="The selected profile to use for the build") + return parser + +def get_buildtools_dir(): + return os.path.realpath(os.path.dirname(os.path.abspath(__file__)) + "/buildtools") + if __name__ == '__main__': - print('Test') + + parser = get_args_parser() + args = parser.parse_args() + + profile = tamarin.load_profile(args.profile) + + workspace = tempfile.mkdtemp(prefix="tamarin_") + + env = os.environ.copy() + env['TAMARIN_TARGET_ARCH'] = args.arch + env['TAMARIN_WORKSPACE'] = workspace + env['PATH'] = env['PATH'] + ':' + get_buildtools_dir() + + tamarin.run_profile_hooks(profile, 'prebuild', cwd=workspace, env=env) + tamarin.run_profile_hooks(profile, 'build', cwd=workspace, env=env) + tamarin.run_profile_hooks(profile, 'postbuild', cwd=workspace, env=env) diff --git a/lib/build.sh b/lib/build.sh deleted file mode 100755 index b7bb8a2..0000000 --- a/lib/build.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env bash - -LIB_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) -export TAMARIN_UTIL="${LIB_DIR}/util.sh" - -source "${TAMARIN_UTIL}" - -DIST_DIR="${BASE_DIR}/dist" -SRC_DIR="${BASE_DIR}/src" -PROJECT_NAME=${1} -BUILD_BRANCH=${2} -BUILD_TAG=${4} - -function build_project() -{ - - info "Building project '${PROJECT_NAME}' for ${TARGET_ARCH} architecture..." - - # Initalize opts - set_opt project_name "${PROJECT_NAME}" - set_opt build_branch "${BUILD_BRANCH}" - set_opt build_tag "${BUILD_TAG}" - - local workspace=$(mktemp -d)/${PROJECT_NAME} - info "Build dir is ${workspace}" - mkdir -p "${workspace}" - - # Copy sources to workspace - cd ${SRC_DIR} - cp -r ${SRC_DIR}/. "${workspace}" - - cd "$workspace" - - load_local_opts - exec_hooks "prebuild" "${workspace}" - - dpkg-buildpackage -b -a"${TARGET_ARCH}" 2> >(stderr) 1> >(stdout) - - if [ $? != 0 ]; then - fatal "The build process has not completed successfuly !" - fi - - exec_hooks "postbuild" "${workspace}" - -} - -build_project diff --git a/lib/buildtools/tamarin_db b/lib/buildtools/tamarin_db new file mode 100755 index 0000000..3446635 --- /dev/null +++ b/lib/buildtools/tamarin_db @@ -0,0 +1,53 @@ +#!/usr/bin/env bash + +PROJECT_DB_FILE="/src/.tamarinrc" +GLOBAL_DB_FILE="${TAMARIN_WORKSPACE}/.tamarinrc" +KEY_PREFIX="tamarin_db_" + +function tamarin_load_project_db { + if [ -e "${PROJECT_DB_FILE}" ]; then + tamarin_info "Loading project database..." + while read line; do + if [[ ! "${line}" =~ ^\s*# ]]; then + set -- $(echo $line | tr '=' ' ') + local key=$1 + local value=$2 + tamarin_debug "Load $key=$value" + tamarin_db_set $key $value + fi + done < "${PROJECT_DB_FILE}" + fi +} + +function tamarin_db_get { + local opt_name=${KEY_PREFIX}${1} + local default_value=${2} + touch "${GLOBAL_DB_FILE}" + source "${GLOBAL_DB_FILE}" + echo ${!opt_name:-${default_value}} +} + +function tamarin_db_set { + local opt_name=${1} + local opt_value=${2} + mkdir -p "$(dirname ${GLOBAL_DB_FILE})" + touch "${GLOBAL_DB_FILE}" + sed -i "s/^${KEY_PREFIX}${opt_name}*$//" "${GLOBAL_DB_FILE}" + echo "local ${KEY_PREFIX}${opt_name}=\"${opt_value}\"" >> "${GLOBAL_DB_FILE}" +} + +case $1 in + set) + tamarin_db_set ${@:2} + ;; + get) + tamarin_db_get ${@:2} + ;; + load) + tamarin_load_project_db + ;; + *) + tamarin_error "Invalid action '$1'. Must be get, set or load !" + exit 1 + ;; +esac diff --git a/lib/buildtools/tamarin_debug b/lib/buildtools/tamarin_debug new file mode 100755 index 0000000..4266a19 --- /dev/null +++ b/lib/buildtools/tamarin_debug @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +if [ -z "$@" ]; then + while read str; do + tamarin_log DEBUG "${str}" + done +else + tamarin_log DEBUG "$@" +fi diff --git a/lib/buildtools/tamarin_error b/lib/buildtools/tamarin_error new file mode 100755 index 0000000..9be8c07 --- /dev/null +++ b/lib/buildtools/tamarin_error @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +if [ -z "$@" ]; then + while read str; do + tamarin_log ERROR "${str}" + done +else + tamarin_log ERROR "$@" +fi diff --git a/lib/buildtools/tamarin_info b/lib/buildtools/tamarin_info new file mode 100755 index 0000000..518aa98 --- /dev/null +++ b/lib/buildtools/tamarin_info @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +if [ -z "$@" ]; then + while read str; do + tamarin_log INFO "${str}" + done +else + tamarin_log INFO "$@" +fi diff --git a/lib/buildtools/tamarin_log b/lib/buildtools/tamarin_log new file mode 100755 index 0000000..b8c6072 --- /dev/null +++ b/lib/buildtools/tamarin_log @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +# Colors + +COLOR_INFO='\e[0;36m' +COLOR_ERROR='\e[0;31m' +COLOR_WARN='\e[0;33m' +COLOR_SUCCESS='\e[0;32m' +COLOR_DEBUG='\e[0;35m' + +function log { + local args=( $@ ) + local color=COLOR_${args[0]} + echo -e "${!color}[${args[0]}] $(remove_ansi ${args[@]:1})\e[0m" +} + +function remove_ansi { + echo "$@" | sed 's,\x1B\[[0-9;]*[a-zA-Z],,g' +} + +if [ $# -ne 0 ]; then + log $@ +fi diff --git a/lib/buildtools/tamarin_success b/lib/buildtools/tamarin_success new file mode 100755 index 0000000..4484f97 --- /dev/null +++ b/lib/buildtools/tamarin_success @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +if [ -z "$@" ]; then + while read str; do + tamarin_log SUCCESS "${str}" + done +else + tamarin_log SUCCESS "$@" +fi diff --git a/lib/buildtools/tamarin_warn b/lib/buildtools/tamarin_warn new file mode 100755 index 0000000..4935b7e --- /dev/null +++ b/lib/buildtools/tamarin_warn @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +if [ -z "$@" ]; then + while read str; do + tamarin_log WARN "${str}" + done +else + tamarin_log WARN "$@" +fi diff --git a/lib/tamarin.py b/lib/tamarin.py index ed8c708..164866a 100644 --- a/lib/tamarin.py +++ b/lib/tamarin.py @@ -1,13 +1,20 @@ import os, glob, subprocess, configparser import web, system +import codecs def run_profile_hooks(profile, step, cwd=None, env=None): hooks_dir = get_hooks_dir() - step_hooks = profile[step]["hooks"].split(",") - for hook_name in step_hooks: - hook_path = os.path.join(hooks_dir, hook_name) - print(hook_path) - subprocess.call(hook_path, cwd=cwd, stdin=subprocess.PIPE, env=env) + step_hooks = profile[step]["hooks"] + if not step_hooks: + return + for hook_name in step_hooks.split(","): + trimmed_hook_name = hook_name.strip(' \t\n\r') + if not trimmed_hook_name: + continue + hook_path = os.path.join(hooks_dir, trimmed_hook_name) + code = subprocess.call(hook_path, cwd=cwd, stdin=subprocess.PIPE, env=env) + if code != 0: + raise Exception("Hook '{:s}' exited with a non zero code ({:d}) !".format(trimmed_hook_name, code)) def get_hooks_dir(): return os.path.realpath(os.path.dirname(os.path.abspath(__file__)) + "/../hooks") @@ -20,8 +27,9 @@ def load_profile(profile_name): for profile_file in get_available_profiles(): if profile_filename == os.path.basename(profile_file): config = configparser.ConfigParser() - config.read(profile_file) - return config + with codecs.open(profile_file, encoding = 'utf-8', mode = 'r') as handle: + config.read_file(handle) + return config return None def get_profiles_dir(): diff --git a/lib/util.sh b/lib/util.sh deleted file mode 100644 index e0f0857..0000000 --- a/lib/util.sh +++ /dev/null @@ -1,154 +0,0 @@ -#!/usr/bin/env bash - -HOOKS_DIR="${BASE_DIR}/hooks" -DEFAULT_OPTS_FILE="${BASE_DIR}/tmp/default_opts" -OPT_FILE="${BASE_DIR}/tmp/tamarin/opts" -OPT_PREFIX="tamarin_opt_" -LOCAL_OPTS_FILE=".tamarinrc" - -# Colors - -COLOR_INFO='\e[0;36m' -COLOR_FATAL='\e[0;31m' -COLOR_WARN='\e[0;33m' -COLOR_SUCCESS='\e[0;32m' -COLOR_ERR='\e[0;37m' -COLOR_OUT='\e[0;37m' -COLOR_DEBUG='\e[0;35m' - -function stderr { - if [ -z "$@" ]; then - while read str; do - log ERR "${str}" - done - else - log stderr "$@" - fi -} - -function stdout { - if [ -z "$@" ]; then - while read str; do - log OUT "${str}" - done - else - log OUT "$@" - fi -} - -function info { - if [ -z "$@" ]; then - while read str; do - log INFO "${str}" - done - else - log INFO "$@" - fi -} - -function warn { - if [ -z "$@" ]; then - while read str; do - log WARN "${str}" - done - else - log WARN "$@" - fi -} - -function debug { - if [ -z "$@" ]; then - while read str; do - log DEBUG "${str}" - done - else - log DEBUG "$@" - fi -} - -function fatal { - if [ -z "$@" ]; then - while read str; do - log FATAL "${str}" >&2 - done - else - log FATAL "$@" >&2 - fi - exit 1 -} - -function success { - if [ -z "$@" ]; then - while read str; do - log SUCCESS "${str}" - done - else - log SUCCESS "$@" - fi -} - -function log { - local args=( $@ ) - local color=COLOR_${args[0]} - echo -e "${!color}[${args[0]}] $(remove_ansi ${args[@]:1})\e[0m" -} - -function remove_ansi { - echo "$@" | sed 's,\x1B\[[0-9;]*[a-zA-Z],,g' -} - -function load_local_opts { - if [ -e "${LOCAL_OPTS_FILE}" ]; then - info "Loading local opts..." - while read line; do - if [[ ! "${line}" =~ ^\s*# ]]; then - set -- $(echo $line | tr '=' ' ') - local key=$1 - local value=$2 - debug "Load opt $key=$value" - set_opt $key $value - fi - done < "${LOCAL_OPTS_FILE}" - fi -} - -function get_opt { - local opt_name=${OPT_PREFIX}${1} - local default_value=${2} - touch "${OPT_FILE}" - source "${OPT_FILE}" - echo ${!opt_name:-${default_value}} -} - -function set_opt { - local opt_name=${1} - local opt_value=${2} - mkdir -p "$(dirname ${OPT_FILE})" - touch "${OPT_FILE}" - sed -i "s/^${OPT_PREFIX}${opt_name}*$//" "${OPT_FILE}" - echo "local ${OPT_PREFIX}${opt_name}=\"${opt_value}\"" >> "${OPT_FILE}" -} - -function exec_hooks { - - local hook=${1} - local workspace=${2} - - local hook_scripts=$( find "${HOOKS_DIR}" -type f -name "*${hook}" -executable | sort ) - - for hook_script in ${hook_scripts}; do - - info "[>> ${hook}] ${hook_script}" - - ( cd "${workspace}" && "${hook_script}" ) 2> >(stderr) 1> >(stdout) - - # If the script did not execute properly, we stop here - if [ $? != 0 ]; then - fatal "The '${hook_script}' hook script did not finished properly !" - fi - - info "[<< ${hook}] ${hook_script}" - - done - -} diff --git a/package b/package index 9214d3d..cec8153 100755 --- a/package +++ b/package @@ -10,11 +10,13 @@ def configure_args_parser(): profile_names = tamarin.get_available_profile_names() - parser = argparse.ArgumentParser(description="Generate packages for various GNU/Linux distribution") + parser = argparse.ArgumentParser(description="Generate packages for various GNU/Linux distributions") # Define available/required arguments and flags - parser.add_argument("project_path", help="The path to your project to package") + parser.add_argument("project_directory", help="The path to your project to package") + parser.add_argument("-o", "--output", help="The path to the generated packages destination directory", default=".") parser.add_argument("-p", "--profile", help="The profile to use to package this project (default: debian)", choices=profile_names, default='debian') + parser.add_argument("-a", "--architecture", help="The target architecture for the package (default: amd64)", default='amd64') parser.add_argument("--rebuild", help="Ignore cache and rebuild container's image", action="store_true", default=False) return parser @@ -24,6 +26,10 @@ if __name__ == "__main__": parser = configure_args_parser() args = parser.parse_args() + # Verify project directory + project_dir = os.path.abspath(args.project_directory) + output_dir = os.path.abspath(args.output) + # Load build profile profile = tamarin.load_profile(args.profile) @@ -86,14 +92,18 @@ if __name__ == "__main__": # Build image tamarin.run_acbuild(acbuild_flags+["set-name", "image_{:d}".format(pid)]) - tamarin.run_acbuild(acbuild_flags+["copy-to-dir", tamarin.get_hooks_dir(), '/tamarin']) - tamarin.run_acbuild(acbuild_flags+["copy-to-dir", tamarin.get_lib_dir(), '/tamarin']) + tamarin.run_acbuild(acbuild_flags+["mount", "add", "src", "/src", "--read-only"]) + tamarin.run_acbuild(acbuild_flags+["mount", "add", "dist", "/dist"]) + tamarin.run_acbuild(acbuild_flags+["mount", "add", "tamarin-hooks", "/tamarin/hooks", "--read-only"]) + tamarin.run_acbuild(acbuild_flags+["mount", "add", "tamarin-lib", "/tamarin/lib", "--read-only"]) + tamarin.run_acbuild(acbuild_flags+["mount", "add", "tamarin-profiles", "/tamarin/profiles", "--read-only"]) # Execute containerbuild hooks - cpb_hooks_env = os.environ.copy() - cpb_hooks_env["PATH"] = os.environ['PATH'] + ':' + local_acbuild_dir - cpb_hooks_env["TAMARIN_ACBUILD"] = " ".join([system.which('acbuild', local_acbuild_dir)]+acbuild_flags) - tamarin.run_profile_hooks(profile, 'containerbuild', cwd=build_workspace, env=cpb_hooks_env) + cb_hooks_env = os.environ.copy() + cb_hooks_env["PATH"] = os.environ['PATH'] + ':' + local_acbuild_dir + cb_hooks_env["TAMARIN_ACBUILD"] = " ".join([system.which('acbuild', local_acbuild_dir)]+acbuild_flags) + cb_hooks_env["TAMARIN_ACBUILD_ENGINE"] = "chroot" if system.which('systemd-nspawn') == "" else "systemd-nspawn" + tamarin.run_profile_hooks(profile, 'containerbuild', cwd=build_workspace, env=cb_hooks_env) # Cache image shutil.copyfile(aci_file, cached_image_file) @@ -103,7 +113,13 @@ if __name__ == "__main__": "run", "--insecure-options=image", aci_file, "--net=host", - "--exec", "/usr/bin/python3", "--", "/tamarin/lib/build.py" + "--volume=src,kind=host,source={:s}".format(project_dir), + "--volume=dist,kind=host,source={:s}".format(output_dir), + "--volume=tamarin-hooks,kind=host,source={:s}".format(tamarin.get_hooks_dir()), + "--volume=tamarin-lib,kind=host,source={:s}".format(tamarin.get_lib_dir()), + "--volume=tamarin-profiles,kind=host,source={:s}".format(tamarin.get_profiles_dir()), + "--interactive", "--exec", "/bin/bash" + #"--exec", "/usr/bin/python3", "--", "/tamarin/lib/build.py", args.profile, args.architecture ], as_root=True) # Cleanup diff --git a/package.sh b/package.sh deleted file mode 100755 index a898714..0000000 --- a/package.sh +++ /dev/null @@ -1,182 +0,0 @@ -#!/usr/bin/env bash - -set -e - -TAMARIN_VERSION=0.0.1 -TAMARIN_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) - -BASE_DIR="$TAMARIN_DIR" source "$TAMARIN_DIR/lib/util.sh" -DEFAULT_64_IMAGE="debian:jessie" -DEFAULT_32_IMAGE="32bit/debian:jessie" - -function show_usage { - echo - echo "Usage: $0 -p project_path [-a arch] [-d destination] [-i image] [-k]" - echo - echo "Parameters: " - echo - echo " -p Path to the project to build" - echo " -v Optional : Show Tamarin version" - echo " -a Optional : Target architecture (default amd64)" - 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 branch (for git projects only) (default dist/ubuntu/precise/master)" - echo - exit 2 -} - -# Create a build container based on the $BASE_IMAGE argument -function create_container { - - # Escape image name - local escaped_basename=$(echo "$BASE_IMAGE" | sed 's/[^a-z0-9\-\_\.]/\_/gi') - # Generate container tag - container_tag="tamarin:${escaped_basename}_$(date +%s)" - # Create temporary dir for the Dockerfile - local temp_dir="$(mktemp -d)" - - local projectName=${1} - - # Link lib & hooks folders - ln -s $(readlink -f "$TAMARIN_DIR/lib") "$temp_dir/lib" - ln -s $(readlink -f "$TAMARIN_DIR/hooks") "$temp_dir/hooks" - - # Create Dockerfile - cat << EOF > "$temp_dir/Dockerfile" - FROM ${BASE_IMAGE} - - ENV DEBIAN_FRONTEND noninteractive - - RUN apt-get update &&\ - apt-get install --yes --no-install-recommends build-essential devscripts equivs - - RUN mkdir /root/.tamarin - RUN mkdir /project - - ADD ./lib /root/.tamarin/lib - ADD ./hooks /hooks - RUN chmod +x /root/.tamarin/lib/build.sh - - VOLUME /src - VOLUME /dist - -EOF - - exec_hooks "containerbuild" "$temp_dir" - - echo "CMD /root/.tamarin/lib/build.sh ${projectName} ${BUILD_BRANCH} /tmp ${BUILD_TAG}" >> "$temp_dir/Dockerfile" - - # Build image - tar -C "$temp_dir" -czh . | docker build -t "$container_tag" - 2> >(stderr) 1> >(stdout) - - # Delete temporary folder - rm -rf "$temp_dir" - -} - -# Main function -function main { - - info "Building container from $BASE_IMAGE..." - - local project_name=$(basename ${PROJECT_PATH}) - - # Create container & "$container_tag" variable - create_container ${project_name} - - local docker_opt="run -e \"DISTRIB=$BASE_IMAGE\" -e \"PROJECT_NAME=$project_name\"" - - # Expose host uid & gid - docker_opt="${docker_opt} -e HOST_UID=$(id -u) -e HOST_GID=$(id -g)" - - # Expose host proxy variables - docker_opt="${docker_opt} -e HTTP_PROXY=${HTTP_PROXY} -e HTTPS_PROXY=${HTTPS_PROXY}" - docker_opt="${docker_opt} -e http_proxy=${http_proxy} -e https_proxy=${https_proxy}" - - # Target architecture - docker_opt="${docker_opt} -e TARGET_ARCH=${TARGET_ARCH}" - - # If running in terminal, set docker to interactive - if [[ -t 1 ]]; then - docker_opt="${docker_opt} -it" - fi - - if [[ ${PERSIST_CONTAINER} -eq 0 ]] - then - docker_opt="${docker_opt} --rm " - else - docker_opt="${docker_opt}" - fi - - docker_opt="${docker_opt} -v $PROJECT_PATH:/src:ro -v $PROJECT_DEST:/dist:rw $container_tag" - - info "Switching to container..." - debug "docker ${docker_opt}" - docker ${docker_opt} - res=${?} - - success "Done" - return ${res} -} - -# -# Parsing options -# -while getopts "vkp:d:i:B:t:a:o:" 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_BRANCH=${OPTARG} - ;; - t) - BUILD_TAG=${OPTARG} - ;; - a) - TARGET_ARCH=${OPTARG} - ;; - v) - echo "Tamarin v${TAMARIN_VERSION}" - exit - ;; - *) - show_usage - ;; - esac -done - -[[ -z ${PROJECT_PATH} ]] && show_usage -[[ -z ${PROJECT_DEST} ]] && PROJECT_DEST=$(readlink -f "./packages") -[[ -z ${BUILD_BRANCH} ]] && BUILD_BRANCH="dist/ubuntu/precise/master" -[[ -z ${PERSIST_CONTAINER} ]] && PERSIST_CONTAINER=0 -[[ -z ${TARGET_ARCH} ]] && TARGET_ARCH=amd64 - -if [[ "${TARGET_ARCH}" =~ ^i[0-9]86$ ]] && [ -z "${BASE_IMAGE}" ]; then - info "32bit architecture specified and no specific image given, switching to default 32bit image..." - BASE_IMAGE=${DEFAULT_32_IMAGE} -fi - -[[ -z ${BASE_IMAGE} ]] && BASE_IMAGE=${DEFAULT_64_IMAGE} - -# -# Warn user about "proxy" -# - -if [[ -n ${http_proxy} ]] -then - warn "You have a proxy defined please make sure docker deamon is configured to use this proxy" -fi - -main diff --git a/profiles/debian.conf b/profiles/debian.conf index 3a8a572..cc33185 100644 --- a/profiles/debian.conf +++ b/profiles/debian.conf @@ -5,18 +5,22 @@ default_image=docker://debian:jessie # Configuration de l'étape de pré-construction du conteneur [containerbuild] -hooks=containerbuild/debian/install-build-essential,containerbuild/debian/install-git +hooks=containerbuild/debian/install-build-essential, + containerbuild/debian/install-git # Configuration de l'étape de pré-construction du paquet [prebuild] -hooks=05-create-changelog-prebuild,06-create-dummy-changelog-prebuild,07-add-version-suffix-prebuild,10-install-build-depends-prebuild +hooks=prebuild/debian/load-project-db, + prebuild/debian/copy-sources-to-workspace, + prebuild/debian/create-changelog, + prebuild/debian/create-dummy-changelog, + prebuild/debian/add-package-version-suffix, + prebuild/debian/install-build-depends + +# Configuration de l'étape de construction du paquet +[build] +hooks=build/debian/build # Configuration de l'étape de post-construction du paquet [postbuild] -hooks=99-export-dist-postbuild - -[preinstall] -hooks= - -[postinstall] -hooks= +hooks=postbuild/debian/export-dist-postbuild