Merge branch 'feature/quilt' into develop
This commit is contained in:
commit
22f325f749
|
@ -1,3 +1,3 @@
|
||||||
dist
|
packages
|
||||||
*.log
|
*.log
|
||||||
*~
|
*~
|
||||||
|
|
57
README.md
57
README.md
|
@ -1,6 +1,6 @@
|
||||||
# Tamarin
|
# Tamarin
|
||||||
|
|
||||||
Usine à paquets Debian basée sur Docker.
|
Usine à paquets binaires Debian basée sur Docker.
|
||||||
|
|
||||||
## Dépendances
|
## Dépendances
|
||||||
|
|
||||||
|
@ -9,53 +9,18 @@ Vous devez avoir [docker](https://docs.docker.com/installation/) installé sur v
|
||||||
## Utilisation
|
## Utilisation
|
||||||
|
|
||||||
```
|
```
|
||||||
./package-project.sh <src> <dist> <docker_image>
|
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
|
## Licence
|
||||||
|
|
||||||
GPLv3
|
GPLv3
|
||||||
|
|
|
@ -22,7 +22,7 @@ else
|
||||||
tagbranch="build-tag-${BUILD_TAG}"
|
tagbranch="build-tag-${BUILD_TAG}"
|
||||||
git checkout -b ${tagbranch}
|
git checkout -b ${tagbranch}
|
||||||
set_opt "tag_branch" "${tag_branch}"
|
set_opt "tag_branch" "${tag_branch}"
|
||||||
tags="${BUILD_TAG}"
|
local tags="${BUILD_TAG}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -z ${tags} ]]
|
if [[ -z ${tags} ]]
|
||||||
|
@ -44,14 +44,28 @@ do
|
||||||
project_name=$(get_opt project_name)
|
project_name=$(get_opt project_name)
|
||||||
version=${tag#*/} #$(get_opt version 0.0.0)
|
version=${tag#*/} #$(get_opt version 0.0.0)
|
||||||
version=${version/_/-} #$(get_opt version 0.0.0)
|
version=${version/_/-} #$(get_opt version 0.0.0)
|
||||||
|
|
||||||
distribution=$(get_opt distribution UNRELEASED)
|
distribution=$(get_opt distribution UNRELEASED)
|
||||||
urgency=$(get_opt urgency low)
|
urgency=$(get_opt urgency low)
|
||||||
|
|
||||||
commit_count=$(git rev-list --count --first-parent HEAD)
|
commit_count=$(git rev-list --count --first-parent HEAD)
|
||||||
current_commit=$(git log -n 1 --pretty=format:"%h")
|
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
|
echo >> debian/changelog
|
||||||
|
|
|
@ -4,5 +4,5 @@ source "${TAMARIN_UTIL}"
|
||||||
|
|
||||||
if [ -f debian/control ]; then
|
if [ -f debian/control ]; then
|
||||||
info "Installing build dependencies..."
|
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
|
fi
|
|
@ -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
|
|
@ -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
|
|
|
@ -33,7 +33,8 @@ function build_project()
|
||||||
exec_hooks "prebuild" "${workspace}"
|
exec_hooks "prebuild" "${workspace}"
|
||||||
|
|
||||||
cd "${workspace}"
|
cd "${workspace}"
|
||||||
dpkg-buildpackage -us -uc 2> >(error) 1> >(info)
|
|
||||||
|
dpkg-buildpackage -b 2> >(error) 1> >(info)
|
||||||
|
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
fatal "The build process has not completed successfuly !"
|
fatal "The build process has not completed successfuly !"
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
HOOKS_DIR="${BASE_DIR}/hooks"
|
HOOKS_DIR="${BASE_DIR}/hooks"
|
||||||
OPT_FILE="${BASE_DIR}/tmp/.tamarin_opts"
|
OPT_FILE="${BASE_DIR}/tmp/.tamarin_opts"
|
||||||
|
OPT_PREFIX="tamarin_opt_"
|
||||||
|
|
||||||
function info {
|
function info {
|
||||||
if [ -z "$@" ]; then
|
if [ -z "$@" ]; then
|
||||||
|
@ -50,7 +51,7 @@ function log {
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_opt {
|
function get_opt {
|
||||||
local opt_name=${1}
|
local opt_name=${OPT_PREFIX}${1}
|
||||||
local default_value=${2}
|
local default_value=${2}
|
||||||
touch "${OPT_FILE}"
|
touch "${OPT_FILE}"
|
||||||
source "${OPT_FILE}"
|
source "${OPT_FILE}"
|
||||||
|
@ -61,8 +62,8 @@ function set_opt {
|
||||||
local opt_name=${1}
|
local opt_name=${1}
|
||||||
local opt_value=${2}
|
local opt_value=${2}
|
||||||
touch "${OPT_FILE}"
|
touch "${OPT_FILE}"
|
||||||
sed -i "s/^${opt_name}*$//" "${OPT_FILE}"
|
sed -i "s/^${OPT_PREFIX}${opt_name}*$//" "${OPT_FILE}"
|
||||||
echo "${opt_name}=\"${opt_value}\"" >> "${OPT_FILE}"
|
echo "${OPT_PREFIX}${opt_name}=\"${opt_value}\"" >> "${OPT_FILE}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function exec_hooks {
|
function exec_hooks {
|
||||||
|
|
15
package.sh
15
package.sh
|
@ -47,7 +47,7 @@ function create_container {
|
||||||
ENV DEBIAN_FRONTEND noninteractive
|
ENV DEBIAN_FRONTEND noninteractive
|
||||||
|
|
||||||
RUN apt-get update &&\
|
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 /root/.tamarin
|
||||||
RUN mkdir /project
|
RUN mkdir /project
|
||||||
|
@ -60,6 +60,8 @@ function create_container {
|
||||||
VOLUME /dist
|
VOLUME /dist
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
exec_hooks "containerbuild" "$temp_dir"
|
||||||
|
|
||||||
if [[ -z ${BUILD_DIR} ]]
|
if [[ -z ${BUILD_DIR} ]]
|
||||||
then
|
then
|
||||||
echo " CMD /root/.tamarin/lib/build.sh ${projectName} ${BUILD_BRANCH} /tmp ${BUILD_TAG}" >> "$temp_dir/Dockerfile"
|
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"
|
echo " CMD /root/.tamarin/lib/build.sh ${projectName} ${BUILD_BRANCH} /build ${BUILD_TAG}" >> "$temp_dir/Dockerfile"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exec_hooks "containerbuild" "$temp_dir"
|
|
||||||
|
|
||||||
# Build image
|
# Build image
|
||||||
tar -C "$temp_dir" -czh . | docker build -t "$container_tag" - 2> >(error) 1> >(info)
|
tar -C "$temp_dir" -czh . | docker build -t "$container_tag" - 2> >(error) 1> >(info)
|
||||||
|
|
||||||
|
@ -90,6 +90,9 @@ function main {
|
||||||
|
|
||||||
local docker_opt="run -e \"DISTRIB=$BASE_IMAGE\" -e \"PROJECT_NAME=$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)"
|
||||||
|
|
||||||
if [[ ${PERSIST_CONTAINER} -eq 0 ]]
|
if [[ ${PERSIST_CONTAINER} -eq 0 ]]
|
||||||
then
|
then
|
||||||
docker_opt="${docker_opt} --rm "
|
docker_opt="${docker_opt} --rm "
|
||||||
|
@ -99,13 +102,13 @@ function main {
|
||||||
|
|
||||||
if [[ -z ${BUILD_DIR} ]]
|
if [[ -z ${BUILD_DIR} ]]
|
||||||
then
|
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
|
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
|
fi
|
||||||
|
|
||||||
info "Switching to container..."
|
info "Switching to container..."
|
||||||
echo "docker ${docker_opt}"
|
debug "docker ${docker_opt}"
|
||||||
docker ${docker_opt}
|
docker ${docker_opt}
|
||||||
res=${?}
|
res=${?}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue