Compare commits
72 Commits
Author | SHA1 | Date | |
---|---|---|---|
9e9fdee0d6 | |||
8db349571a | |||
68ca0365ae | |||
6fe1d305e0 | |||
fdebf244d5 | |||
b49c8c8b02 | |||
766151eae3 | |||
f8195ba9f7 | |||
47c7d0ac3c | |||
4c4fd6d42c | |||
546e62e077 | |||
4b61e5dafc | |||
c83e6190c4 | |||
cad163ffd0 | |||
97fd00a3c7 | |||
fdba555beb | |||
253c77489b | |||
9a46f34f73 | |||
5a4c17a959 | |||
be739a965c | |||
e49636df62 | |||
878b8c48ce | |||
0d5470e1a7 | |||
ea5a73210f | |||
f1ce64b1be | |||
ef4c6d821f | |||
5fd65bbb89 | |||
db952bc2f7 | |||
09673ce967 | |||
f87c18f907 | |||
1c146441fb | |||
60b0eaad53 | |||
71f2bb767f | |||
948745877c | |||
422407a37c | |||
110097ec81 | |||
4e27cc8b6e | |||
f1bccc8e23 | |||
7f8a13bd52 | |||
16b0ef996d | |||
50f578216b | |||
7ead22e8ec | |||
17d371c804 | |||
caac9056fa | |||
6b8f6148bb | |||
7a89eab56e | |||
95afc85772 | |||
1fcc5bf08e | |||
f171e31a3c | |||
8d1a760093 | |||
9dc46f5665 | |||
222b6c8940 | |||
d99305182e | |||
6d5e898cb8 | |||
1d566f8de8 | |||
448a16f659 | |||
9780cafffd | |||
0bf686d5f3 | |||
e58ab60bd8 | |||
24dbf2fe47 | |||
97df663236 | |||
15643cf145 | |||
2375dd6571 | |||
38d236e09b | |||
ce05d9a339 | |||
82fb9d31e1 | |||
487c97e88c | |||
b88493523f | |||
8469bf2c08 | |||
86216e639e | |||
cc5df7cfcd | |||
0028db764a |
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,3 +1,7 @@
|
|||||||
packages
|
packages
|
||||||
*.log
|
*.log
|
||||||
*~
|
*~
|
||||||
|
__pycache__
|
||||||
|
*.pyc
|
||||||
|
*.changes
|
||||||
|
*.deb
|
||||||
|
3
Makefile
Normal file
3
Makefile
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
.PHONY: test
|
||||||
|
test:
|
||||||
|
python3 -m unittest discover "./test" "*_test.py"
|
34
README.md
34
README.md
@ -1,26 +1,34 @@
|
|||||||
# Tamarin
|
# Tamarin
|
||||||
|
|
||||||
Usine à paquets binaires Debian basée sur Docker.
|
Usine à paquets GNU/Linux
|
||||||
|
|
||||||
|
## Statut
|
||||||
|
|
||||||
|
Expérimental
|
||||||
|
|
||||||
|
## Formats de paquets/distributions supportés
|
||||||
|
|
||||||
|
- `.deb` (Debian, Ubuntu)
|
||||||
|
|
||||||
## Dépendances
|
## Dépendances
|
||||||
|
|
||||||
Vous devez avoir [docker](https://docs.docker.com/installation/) installé sur votre machine.
|
- [Python 3](https://www.python.org/downloads/)
|
||||||
|
- [Docker](>= 17.03)
|
||||||
|
|
||||||
## Utilisation
|
## 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
|
TODO
|
||||||
-a Optional : Architecture choice (-a i386 for example)
|
|
||||||
-d Optional : Destination of the builed packages (default ./packages)
|
### Les attributs de construction
|
||||||
-i Optional : Name of the Docker image to use for build (default: debian:jessie)
|
|
||||||
-k Optional : Keep the Docker container after build
|
TODO
|
||||||
-b Optional : Build directory (default /tmp)
|
|
||||||
-B Optional : Build branch (for git projects only) (default dist/ubuntu/precise/master)
|
|
||||||
```
|
|
||||||
|
|
||||||
## Licence
|
## Licence
|
||||||
|
|
||||||
|
@ -1,82 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
|
||||||
source "$DIR/lib/util.sh"
|
|
||||||
|
|
||||||
function show_usage {
|
|
||||||
echo
|
|
||||||
echo "Usage: $0 deb_file [image]"
|
|
||||||
echo
|
|
||||||
echo "Paramètres: "
|
|
||||||
echo
|
|
||||||
echo " - deb_file Chemin vers le paquet Debian dont on doit vérifier l'installation"
|
|
||||||
echo " - image Optionnel - Nom de l'image Docker à utiliser comme environnement pour tester l'installation. Défaut: debian:jessie"
|
|
||||||
echo
|
|
||||||
}
|
|
||||||
|
|
||||||
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)"
|
|
||||||
|
|
||||||
# Link lib folder
|
|
||||||
ln -s $(readlink -f "$DIR/lib") "$temp_dir/lib"
|
|
||||||
|
|
||||||
# Create Dockerfile
|
|
||||||
cat << EOF > "$temp_dir/Dockerfile"
|
|
||||||
FROM $BASE_IMAGE
|
|
||||||
|
|
||||||
ENV DEBIAN_FRONTEND noninteractive
|
|
||||||
|
|
||||||
RUN apt-get update && apt-get install --yes gdebi-core
|
|
||||||
|
|
||||||
ADD ./lib /root/.tamarin
|
|
||||||
RUN chmod +x /root/.tamarin/install.sh
|
|
||||||
|
|
||||||
VOLUME /deb
|
|
||||||
|
|
||||||
ENTRYPOINT ["/root/.tamarin/install.sh"]
|
|
||||||
|
|
||||||
EOF
|
|
||||||
|
|
||||||
# Build image
|
|
||||||
tar -C "$temp_dir" -czh . | docker build -t "$container_tag" - 2> >(error) 1> >(info)
|
|
||||||
|
|
||||||
# Delete temporary folder
|
|
||||||
rm -rf "$temp_dir"
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function main {
|
|
||||||
|
|
||||||
# Create container image
|
|
||||||
create_container
|
|
||||||
|
|
||||||
# Run container and install package
|
|
||||||
docker run -e "DISTRIB=$BASE_IMAGE" --rm -v="$DEB_DIR:/deb" "$container_tag" "/deb/$DEB_NAME"
|
|
||||||
|
|
||||||
# Check for return
|
|
||||||
if [ $? != 0 ]; then
|
|
||||||
fatal "Installation did not complete correctly !"
|
|
||||||
fi
|
|
||||||
|
|
||||||
info "Installation complete."
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
# Test for arguments
|
|
||||||
if [ -z "$1" ]; then
|
|
||||||
show_usage
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
DEB_PATH=$(readlink -f "$1")
|
|
||||||
DEB_NAME=$(basename "$DEB_PATH")
|
|
||||||
DEB_DIR=$(dirname "$DEB_PATH")
|
|
||||||
BASE_IMAGE="${2:-debian:jessie}"
|
|
||||||
|
|
||||||
main
|
|
4
hooks/build/debian/build
Executable file
4
hooks/build/debian/build
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
cd src
|
||||||
|
dpkg-buildpackage -b -a"${TAMARIN_TARGET_ARCH}"
|
14
hooks/common/run-project-hooks
Executable file
14
hooks/common/run-project-hooks
Executable file
@ -0,0 +1,14 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
step=$1
|
||||||
|
hook=src/.tamarin/$step
|
||||||
|
|
||||||
|
if [ ! -f "$hook" ] || [ ! -x "$hook" ]; then
|
||||||
|
tamarin_info "No project hook (or not executable) for \"$step\"... Skipping."
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
tamarin_info "Project hook found for \"$step\". Running it..."
|
||||||
|
"$hook"
|
7
hooks/containerbuild/debian/install-build-essential
Executable file
7
hooks/containerbuild/debian/install-build-essential
Executable file
@ -0,0 +1,7 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo 'ENV DEBIAN_FRONTEND=noninteractive' >> Dockerfile
|
||||||
|
echo 'RUN apt-get update && apt-get install --yes --no-install-recommends build-essential devscripts equivs python3' >> Dockerfile
|
||||||
|
echo 'ENV DEBIAN_FRONTEND=' >> Dockerfile
|
7
hooks/containerbuild/debian/install-git
Executable file
7
hooks/containerbuild/debian/install-git
Executable file
@ -0,0 +1,7 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo 'ENV DEBIAN_FRONTEND=noninteractive' >> Dockerfile
|
||||||
|
echo 'RUN apt-get update && apt-get install --yes --no-install-recommends git-core' >> Dockerfile
|
||||||
|
echo 'ENV DEBIAN_FRONTEND=' >> Dockerfile
|
28
hooks/containerbuild/debian/install-letsencrypt-ca
Executable file
28
hooks/containerbuild/debian/install-letsencrypt-ca
Executable file
@ -0,0 +1,28 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
DESTDIR=/usr/local/share/ca-certificates
|
||||||
|
UPDATE_CERTS_CMD=update-ca-certificates
|
||||||
|
CERTS="$(cat <<EOF
|
||||||
|
https://letsencrypt.org/certs/isrgrootx1.pem
|
||||||
|
https://letsencrypt.org/certs/isrg-root-x2.pem
|
||||||
|
https://letsencrypt.org/certs/lets-encrypt-r3.pem
|
||||||
|
https://letsencrypt.org/certs/lets-encrypt-e1.pem
|
||||||
|
https://letsencrypt.org/certs/lets-encrypt-r4.pem
|
||||||
|
https://letsencrypt.org/certs/lets-encrypt-e2.pem
|
||||||
|
EOF
|
||||||
|
)"
|
||||||
|
|
||||||
|
|
||||||
|
echo "ENV DEBIAN_FRONTEND=noninteractive" >> Dockerfile
|
||||||
|
echo "RUN apt-get update && apt-get install --yes --no-install-recommends wget openssl ca-certificates" >> Dockerfile
|
||||||
|
|
||||||
|
for cert in $CERTS; do
|
||||||
|
filename=$(basename "$cert")
|
||||||
|
echo "RUN wget -O '$DESTDIR/$filename' $cert" >> Dockerfile
|
||||||
|
echo "RUN openssl x509 -in '$DESTDIR/$filename' -inform PEM -out '$DESTDIR/$filename.crt'" >> Dockerfile
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "RUN $UPDATE_CERTS_CMD" >> Dockerfile
|
||||||
|
echo "ENV DEBIAN_FRONTEND=" >> Dockerfile
|
@ -1,3 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
echo "RUN apt-get update && apt-get install --yes --no-install-recommends git-core" >> Dockerfile
|
|
@ -1,9 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
source "${TAMARIN_UTIL}"
|
|
||||||
|
|
||||||
function move_output_to_dist {
|
function move_output_to_dist {
|
||||||
find '../' -maxdepth 1 -name "$1" -type f -print0 | xargs -0r mv -t /dist/
|
find . -maxdepth 1 -name "$1" -type f -print0 | xargs -0r mv -t /dist/
|
||||||
}
|
}
|
||||||
|
|
||||||
# Create new directory
|
# Create new directory
|
||||||
@ -15,5 +13,4 @@ move_output_to_dist "*.changes"
|
|||||||
move_output_to_dist "*.dsc"
|
move_output_to_dist "*.dsc"
|
||||||
move_output_to_dist "*.tar.{bz2,gz,lzma,xz}"
|
move_output_to_dist "*.tar.{bz2,gz,lzma,xz}"
|
||||||
|
|
||||||
# Configure files permissions
|
tamarin_success "Done :-)"
|
||||||
chown -R ${HOST_UID}:${HOST_GID} /dist
|
|
4
hooks/postbuild/debian/run-project-hooks
Executable file
4
hooks/postbuild/debian/run-project-hooks
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
$(readlink -f $DIR/../../common/run-project-hooks) postbuild
|
@ -1,23 +1,24 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
source "${TAMARIN_UTIL}"
|
|
||||||
|
cd src
|
||||||
|
|
||||||
if [ ! -f debian/changelog ]; then
|
if [ ! -f debian/changelog ]; then
|
||||||
info "No changelog. Skipping..."
|
tamarin_info "No changelog. Skipping..."
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $(get_opt no_version_suffix 'no') == 'yes' ]; then
|
if [ $(tamarin_db get no_version_suffix 'no') == 'yes' ]; then
|
||||||
info "Not adding version suffix."
|
tamarin_info "Not adding version suffix."
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -d .git ]; then
|
if [ -d .git ]; then
|
||||||
info "It seems to be a Git repository. Generating version suffix based on Git history..."
|
tamarin_info "It seems to be a Git repository. Generating version suffix based on Git history..."
|
||||||
commit_count=$(git rev-list --count HEAD)
|
commit_count=$(git rev-list --count HEAD)
|
||||||
current_commit=$(git log -n 1 --pretty=format:"%h")
|
current_commit=$(git log -n 1 --pretty=format:"%h")
|
||||||
version_suffix=tamarin${commit_count}~${current_commit}
|
version_suffix=tamarin${commit_count}~${current_commit}
|
||||||
else
|
else
|
||||||
info "Not a Git project. Fallback to timestamp for suffix generation..."
|
tamarin_info "Not a Git project. Fallback to timestamp for suffix generation..."
|
||||||
version_suffix=tamarin$(date +%Y%m%d%H%M)
|
version_suffix=tamarin$(date +%Y%m%d%H%M)
|
||||||
fi
|
fi
|
||||||
|
|
16
hooks/prebuild/debian/complete-project-db
Executable file
16
hooks/prebuild/debian/complete-project-db
Executable file
@ -0,0 +1,16 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
cd src
|
||||||
|
|
||||||
|
if [ ! -f debian/control ]; then
|
||||||
|
tamarin_error "No debian/control file found !"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
package_name=$(sed -n 's/^Source:[ \t]*\(.*\)$/\1/p' debian/control | tr -d '[:space:]')
|
||||||
|
project_name=$(tamarin_db get project_name)
|
||||||
|
|
||||||
|
if [ "${package_name}" != "${project_name}" ]; then
|
||||||
|
tamarin_warn "The project's name \"${project_name}\" differs from the package one (\"${package_name}\"). Using package's one..."
|
||||||
|
tamarin_db set project_name "${package_name}"
|
||||||
|
fi
|
7
hooks/prebuild/debian/copy-sources-to-workspace
Executable file
7
hooks/prebuild/debian/copy-sources-to-workspace
Executable file
@ -0,0 +1,7 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
tamarin_info "Copying sources to workspace 'src' directory..."
|
||||||
|
|
||||||
|
mkdir src
|
||||||
|
# Copying all read-only sources to the current workspace src
|
||||||
|
cp -r /src/. ./src
|
@ -1,30 +1,38 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
source "${TAMARIN_UTIL}"
|
|
||||||
|
cd src
|
||||||
|
|
||||||
if [ -f debian/changelog ] || [ ! -d .git ]; then
|
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
|
||||||
|
|
||||||
|
# Check ignore release tag
|
||||||
|
IGNORE_RELEASE_TAG=$(tamarin_db get ignore_release_tag "yes")
|
||||||
|
if [ "${IGNORE_RELEASE_TAG}" == "yes" ]; then
|
||||||
|
tamarin_warn "Release tag is ignored. Add 'ignore_release_tag=no' in .tamarinrc to enable."
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get commits log as changelog
|
# Get commits log as changelog
|
||||||
|
|
||||||
BUILD_TAG=$(get_opt build_tag "last")
|
BUILD_TAG=$(tamarin_db get build_tag "last")
|
||||||
|
|
||||||
echo "BUILD TAG IS ${BUILD_TAG}"
|
tamarin_debug "BUILD TAG IS ${BUILD_TAG}"
|
||||||
|
|
||||||
if [[ ${BUILD_TAG} == "last" ]]
|
if [[ ${BUILD_TAG} == "last" ]]
|
||||||
then
|
then
|
||||||
tags=$(git tag master -l "release/*"|sort -r)
|
tags=$(git describe --match "release/*" --abbrev=0)
|
||||||
else
|
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}"
|
tamarin_db set "tag_branch" "${tag_branch}"
|
||||||
local tags="${BUILD_TAG}"
|
local tags="${BUILD_TAG}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -z ${tags} ]]
|
if [[ -z ${tags} ]]
|
||||||
then
|
then
|
||||||
warn "No release tag found, you repo must have a tag like 'release/X.X'"
|
tamarin_warn "No release tag found, you repo must have a tag like 'release/X.X'"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -36,21 +44,21 @@ do
|
|||||||
|
|
||||||
# Set the top commiter as the maintainer of the project if not defined
|
# Set the top commiter as the maintainer of the project if not defined
|
||||||
top_contributor=$(git log --pretty=short | git shortlog -s -n -e | sed 's/^\s*[0-9]*\s*//g' | head -n 1)
|
top_contributor=$(git log --pretty=short | git shortlog -s -n -e | sed 's/^\s*[0-9]*\s*//g' | head -n 1)
|
||||||
maintainer=$(get_opt maintainer "${top_contributor}")
|
maintainer=$(tamarin_db get maintainer "${top_contributor}")
|
||||||
|
|
||||||
project_name=$(get_opt project_name)
|
project_name=$(tamarin_db get 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=$(tamarin_db get distribution UNRELEASED)
|
||||||
urgency=$(get_opt urgency low)
|
urgency=$(tamarin_db get urgency low)
|
||||||
|
|
||||||
package_version=${version}
|
package_version=${version}
|
||||||
|
|
||||||
# Define project_version opt if not defined
|
# Define project_version if not defined
|
||||||
if [ -z "$(get_opt project_version)" ]; then
|
if [ -z "$(tamarin_db get project_version)" ]; then
|
||||||
# Share computed project version
|
# Share computed project version
|
||||||
set_opt project_version "${version}"
|
tamarin_db set project_version "${version}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "${project_name} (${version}) ${distribution}; urgency=${urgency}" >> debian/changelog
|
echo "${project_name} (${version}) ${distribution}; urgency=${urgency}" >> debian/changelog
|
@ -1,14 +1,15 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
source "${TAMARIN_UTIL}"
|
|
||||||
|
cd src
|
||||||
|
|
||||||
if [ -f debian/changelog ] || [ ! -d .git ]; then
|
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
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
changelog="debian/changelog"
|
changelog="debian/changelog"
|
||||||
project_name=$(get_opt project_name)
|
project_name=$(tamarin_db get project_name)
|
||||||
project_version=$(get_opt project_version 0.0.0)
|
project_version=$(tamarin_db get project_version 0.0.0)
|
||||||
date=$(date -R)
|
date=$(date -R)
|
||||||
top_contributor=$(git log --pretty=short | git shortlog -s -n -e | sed 's/^\s*[0-9]*\s*//g' | head -n 1)
|
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)
|
current_commit=$(git log -n 1 --pretty=format:%h)
|
||||||
@ -18,3 +19,8 @@ echo >> ${changelog}
|
|||||||
echo " * Package built with Tamarin. Based on commit ${current_commit}." >> ${changelog}
|
echo " * Package built with Tamarin. Based on commit ${current_commit}." >> ${changelog}
|
||||||
echo >> ${changelog}
|
echo >> ${changelog}
|
||||||
echo " -- ${top_contributor} ${date}" >> ${changelog}
|
echo " -- ${top_contributor} ${date}" >> ${changelog}
|
||||||
|
|
||||||
|
tamarin_info "Generated dummy changelog:"
|
||||||
|
tamarin_info " "
|
||||||
|
cat ${changelog} | tamarin_info
|
||||||
|
tamarin_info " "
|
@ -1,5 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
cd src
|
||||||
|
|
||||||
if [ -f debian/control ]; then
|
if [ -f debian/control ]; then
|
||||||
echo "Installing build dependencies..."
|
echo "Installing build dependencies..."
|
||||||
apt-get update
|
apt-get update
|
@ -1,3 +1,3 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
echo $1
|
tamarin_db load
|
4
hooks/prebuild/debian/run-project-hooks
Executable file
4
hooks/prebuild/debian/run-project-hooks
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
$(readlink -f $DIR/../../common/run-project-hooks) prebuild
|
39
hooks/prebuild/eole/add-package-version-suffix
Executable file
39
hooks/prebuild/eole/add-package-version-suffix
Executable file
@ -0,0 +1,39 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
cd src
|
||||||
|
|
||||||
|
if [ ! -f debian/changelog ]; then
|
||||||
|
tamarin_info "No changelog. Skipping adding suffix to package version"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $(tamarin_db get no_version_suffix 'no') == 'yes' ]; then
|
||||||
|
tamarin_info "Not adding version suffix."
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
tamarin_info "Suffixing package version"
|
||||||
|
if [ -d .git ]; then
|
||||||
|
tamarin_info "It seems to be a Git repository. Generating version suffix based on Git history..."
|
||||||
|
release_tag=$(git describe --match "release/*" --abbrev=0 2>/dev/null)
|
||||||
|
if [ -z "${release_tag}" ]
|
||||||
|
then
|
||||||
|
dev_commit_count=$(git rev-list --count --no-merges develop)
|
||||||
|
else
|
||||||
|
dev_commit_count=$(git rev-list --count ${release_tag}..master)
|
||||||
|
fi
|
||||||
|
if [ ${dev_commit_count} -gt 0 ]
|
||||||
|
then
|
||||||
|
build_level=$(tamarin_db get build_level 'dev')
|
||||||
|
version_suffix="~$build_level+${dev_commit_count}-$(git log -n1 --format=%h)"
|
||||||
|
else
|
||||||
|
version_suffix=''
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
tamarin_info "Not a Git project. Fallback to timestamp for suffix generation..."
|
||||||
|
version_suffix=tamarin$(date +%Y%m%d%H%M)
|
||||||
|
fi
|
||||||
|
|
||||||
|
tamarin_info "Suffixing package version with $version_suffix"
|
||||||
|
sed -i "0,/(\(.*\))/s/(\(.*\))/(\1${version_suffix})/" debian/changelog
|
||||||
|
cp debian/changelog /dist/changelog
|
276
hooks/prebuild/eole/create-changelog
Executable file
276
hooks/prebuild/eole/create-changelog
Executable file
@ -0,0 +1,276 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
cd src
|
||||||
|
if [ -f debian/changelog ] || [ ! -d .git ]; then
|
||||||
|
tamarin_info "Not a Git repository or Debian changelog already exists !"
|
||||||
|
exit
|
||||||
|
else
|
||||||
|
tamarin_info "Creating changelog with commits information."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Get pkg tags as tie points in commit history
|
||||||
|
pkg_tags="$(git for-each-ref --format '%(refname)' refs/tags | tac)"
|
||||||
|
|
||||||
|
# Set starting commit
|
||||||
|
ceiling_commit=$(git describe --match "build/*" --abbrev=0 2>/dev/null)
|
||||||
|
if [ -z "$ceiling_commit" ]
|
||||||
|
then
|
||||||
|
ceiling_commit="HEAD"
|
||||||
|
fi
|
||||||
|
first_commit=$(git rev-list --max-parents=0 HEAD)
|
||||||
|
|
||||||
|
# Get commits log as changelog
|
||||||
|
|
||||||
|
current_release_tag=$(git describe --match "release/*" --abbrev=0 2>/dev/null)
|
||||||
|
|
||||||
|
if [[ -z ${current_release_tag} ]]
|
||||||
|
then
|
||||||
|
tamarin_warn "No release tag found, you repo should have a tag like 'release/*'"
|
||||||
|
tamarin_info "Assuming tag release/0.0.0 on first commit of branch master"
|
||||||
|
current_release="release/0.0.0"
|
||||||
|
current_release_tag=${first_commit}
|
||||||
|
else
|
||||||
|
current_release=$current_release_tag
|
||||||
|
fi
|
||||||
|
|
||||||
|
touch debian/changelog
|
||||||
|
|
||||||
|
project_name=$(tamarin_db get project_name)
|
||||||
|
distribution=$(tamarin_db get distribution UNRELEASED)
|
||||||
|
urgency=$(tamarin_db get urgency low)
|
||||||
|
package_level=$(tamarin_db get package_level dev)
|
||||||
|
|
||||||
|
function get_hash {
|
||||||
|
# Return commit hash from various pointer
|
||||||
|
pointer="$1"
|
||||||
|
echo "$(git log -n1 --format=%H ${pointer})"
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_short_hash {
|
||||||
|
# Return commit short hash from various pointer
|
||||||
|
pointer="$1"
|
||||||
|
echo "$(git log -n1 --format=%h ${pointer})"
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_previous_pkg_tag {
|
||||||
|
# Return previous pkg/* tag or current tag if no previous pkg/* exists.
|
||||||
|
commit="$1"
|
||||||
|
echo "$(git describe --abbrev=0 --match='pkg/*' $commit 2>/dev/null)"
|
||||||
|
}
|
||||||
|
|
||||||
|
function parse_tag {
|
||||||
|
tag="$1"
|
||||||
|
flavor="${tag%%/*}"
|
||||||
|
extended_version="${tag##*/}"
|
||||||
|
if [ "$flavor" = "pkg" ]
|
||||||
|
then
|
||||||
|
exploded_version="$(echo $extended_version | sed "s/\([a-z0-9.+]\+\)-\([0-9]\+\)\(-[a-z]\++[0-9]\+\)\?\(-\([0-9]\+\)-\(g[a-z0-9]\+\)\)\?$/version:\1 revision:\2 modification:\3 distance:\5 anchor:\6/")"
|
||||||
|
elif [ "$flavor" = "release" ]
|
||||||
|
then
|
||||||
|
exploded_version="$(echo $extended_version | sed "s/\([a-z0-9.+]\+\)\(-\([0-9]\+\)-\(g[a-z0-9]\+\)\)\?$/version:\1 distance:\3 anchor:\4/")"
|
||||||
|
fi
|
||||||
|
echo $exploded_version
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_distance_from_tag {
|
||||||
|
description_tag="$1"
|
||||||
|
tag=${description_tag%-*-*}
|
||||||
|
anchor="$2"
|
||||||
|
if [[ "$(get_hash $tag)" =~ "$(get_hash $anchor)" ]]
|
||||||
|
then
|
||||||
|
echo 0
|
||||||
|
else
|
||||||
|
distance="$(parse_tag $description_tag)"
|
||||||
|
distance="${distance#*distance:}"
|
||||||
|
distance="${distance%% *}"
|
||||||
|
echo $distance
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_upstream_version_from_tag {
|
||||||
|
tag="$1"
|
||||||
|
upstream="$(parse_tag $tag)"
|
||||||
|
upstream="${upstream#*version:}"
|
||||||
|
upstream="${upstream%% *}"
|
||||||
|
echo "$upstream"
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_package_version_from_tag {
|
||||||
|
tag="$1"
|
||||||
|
package="$(parse_tag $tag)"
|
||||||
|
package="${package#*revision:}"
|
||||||
|
package="${package%% *}"
|
||||||
|
echo "$package"
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_distribution_from_tag {
|
||||||
|
# tag pkg like pkg/<level>/<distrib>/<version>
|
||||||
|
# <distrib> may be composed
|
||||||
|
tag="$1"
|
||||||
|
distribution="${tag#pkg/*/}"
|
||||||
|
distribution="${distribution%/*}"
|
||||||
|
distribution="${distribution/\//-}"
|
||||||
|
echo $distribution
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_previous_release_tag {
|
||||||
|
# Return previous pkg/* tag or current tag if no previous pkg/* exists.
|
||||||
|
commit="$1"
|
||||||
|
echo "$(git describe --abbrev=0 --always --match='release/*' $commit)"
|
||||||
|
}
|
||||||
|
|
||||||
|
function on_pkg_tag {
|
||||||
|
# Return 1 if current commit is tagged with pkg/* tag.
|
||||||
|
commit="$1"
|
||||||
|
nearest_old_pkg_tag="$(get_previous_pkg_tag $commit)"
|
||||||
|
if [ -n "${nearest_old_pkg_tag}" ] && [ "$(get_hash ${commit})" = "$(get_hash ${nearest_old_pkg_tag})" ]
|
||||||
|
then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function next_step {
|
||||||
|
# Return previous pkg/* tag or first commit if no pkg/* tag exists
|
||||||
|
commit="$1"
|
||||||
|
if [ "$(get_hash $commit)" = "$(get_hash $first_commit)" ]
|
||||||
|
then
|
||||||
|
echo $commit
|
||||||
|
elif on_pkg_tag $commit
|
||||||
|
then
|
||||||
|
nearest_old_pkg_tag="$(get_previous_pkg_tag ${commit}^1)"
|
||||||
|
else
|
||||||
|
nearest_old_pkg_tag="$(get_previous_pkg_tag ${commit})"
|
||||||
|
fi
|
||||||
|
if [[ "$nearest_old_pkg_tag" =~ 'pkg/' ]]
|
||||||
|
then
|
||||||
|
echo $nearest_old_pkg_tag
|
||||||
|
else
|
||||||
|
echo $first_commit
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function date_from_commit {
|
||||||
|
# Return date suitable for changelog entry signature
|
||||||
|
commit="$1"
|
||||||
|
if [ "$(get_hash ${commit})" = "$(get_hash HEAD)" ]
|
||||||
|
then
|
||||||
|
package_date=$(date --rfc-2822)
|
||||||
|
else
|
||||||
|
maintainer_commit="$(get_previous_pkg_tag $commit)"
|
||||||
|
package_date="$(git tag -l --format='%(creator)' ${maintainer_commit})"
|
||||||
|
package_date="${package_date##*> }"
|
||||||
|
package_date="$(date --rfc-2822 -d @${package_date% *})"
|
||||||
|
fi
|
||||||
|
echo "$package_date"
|
||||||
|
}
|
||||||
|
|
||||||
|
function packager_from_commit {
|
||||||
|
# Return Name <mail> id format, suitable for changelog entry signature
|
||||||
|
commit="$1"
|
||||||
|
if on_pkg_tag "${commit}"
|
||||||
|
then
|
||||||
|
maintainer_commit="$(get_previous_pkg_tag $commit)"
|
||||||
|
maintainer="$(git tag -l --format='%(creator)' ${maintainer_commit})"
|
||||||
|
maintainer="${maintainer%>*}>"
|
||||||
|
else
|
||||||
|
maintainer="$(git log -n1 --format='%cn <%ce>')"
|
||||||
|
fi
|
||||||
|
maintainer=$(tamarin_db get maintainer "${maintainer}")
|
||||||
|
echo "$maintainer"
|
||||||
|
}
|
||||||
|
|
||||||
|
function next_version {
|
||||||
|
set -x
|
||||||
|
commit="$1"
|
||||||
|
# upstream version is given by most recent of release or pkg tag
|
||||||
|
previous_pkg="$(git describe --long --match='pkg/*' $commit 2>/dev/null)"
|
||||||
|
previous_release="$(git describe --long --match='release/*' $commit 2>/dev/null)"
|
||||||
|
if [ -n "$previous_release" ] && [ -n "$previous_pkg" ]
|
||||||
|
then
|
||||||
|
distance_from_pkg=$(get_distance_from_tag "$previous_pkg" "$commit")
|
||||||
|
distance_from_release=$(get_distance_from_tag "$previous_release" "$commit")
|
||||||
|
if [ $distance_from_release -le $distance_from_pkg ]
|
||||||
|
then
|
||||||
|
distance=$distance_from_release
|
||||||
|
version="$(get_upstream_version_from_tag $previous_release)-1"
|
||||||
|
else
|
||||||
|
distance=$distance_from_pkg
|
||||||
|
version="$(get_upstream_version_from_tag $previous_pkg)-$(expr $(get_package_version_from_tag $previous_pkg) + 1)"
|
||||||
|
fi
|
||||||
|
elif [ -n "$previous_release" ]
|
||||||
|
then
|
||||||
|
distance_from_release=$(get_distance_from_tag "$previous_release" "$commit")
|
||||||
|
distance=$distance_from_release
|
||||||
|
version="$(get_upstream_version_from_tag $previous_release)-1"
|
||||||
|
elif [ -n "$previous_pkg" ]
|
||||||
|
then
|
||||||
|
distance_from_pkg=$(get_distance_from_tag "$previous_pkg" "$commit")
|
||||||
|
distance=$distance_from_pkg
|
||||||
|
version="$(get_upstream_version_from_tag $previous_pkg)-$(expr $(get_package_version_from_tag $previous_pkg) + 1)"
|
||||||
|
else
|
||||||
|
distance=$(git rev-list --no-merges --count ${commit}..${first_commit})
|
||||||
|
version="0.0.0-1"
|
||||||
|
fi
|
||||||
|
if [ "$package_level" = 'dev' ] || [ "$package_level" = 'staging' ]
|
||||||
|
then
|
||||||
|
version="${version}~${package_level}+${distance}"
|
||||||
|
fi
|
||||||
|
echo $version
|
||||||
|
set +x
|
||||||
|
}
|
||||||
|
|
||||||
|
function gen_changelog_entry {
|
||||||
|
ceiling_commit=$1
|
||||||
|
floor_commit="$(next_step "${ceiling_commit}")"
|
||||||
|
if [ "$(get_hash ${ceiling_commit})" = "$(get_hash ${floor_commit})" ]
|
||||||
|
then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
if on_pkg_tag $ceiling_commit
|
||||||
|
then
|
||||||
|
ceiling_commit="$(get_previous_pkg_tag $ceiling_commit)"
|
||||||
|
version="$(get_upstream_version_from_tag $ceiling_commit)-$(get_package_version_from_tag $ceiling_commit)"
|
||||||
|
distribution="$(get_distribution_from_tag $ceiling_commit)"
|
||||||
|
else
|
||||||
|
tamarin_info "current commit $ceiling_commit"
|
||||||
|
version=$(next_version $ceiling_commit)
|
||||||
|
distribution="UNRELEASED"
|
||||||
|
fi
|
||||||
|
#current_release="$(git describe --abbrev=0 --always --match='release/*' $ceiling_commit)"
|
||||||
|
tamarin_info "Création de l’entrée de changelog entre ${ceiling_commit} et ${floor_commit}"
|
||||||
|
|
||||||
|
maintainer="$(packager_from_commit ${ceiling_commit})"
|
||||||
|
package_date="$(date_from_commit ${ceiling_commit})"
|
||||||
|
version=${version/_/-}
|
||||||
|
changelog_entry="${project_name} (${version}) ${distribution}; urgency=${urgency}"
|
||||||
|
echo "$changelog_entry" >> debian/changelog
|
||||||
|
echo >> debian/changelog
|
||||||
|
for commit in $(git log --no-merges --format='%H' ${floor_commit}..${ceiling_commit})
|
||||||
|
do
|
||||||
|
subject="$(git log -n1 --format=%s ${commit})"
|
||||||
|
echo " * ${subject}" >> debian/changelog
|
||||||
|
#ceiling_commit="$(git log -n1 --format='%H' ${commit}^1)"
|
||||||
|
done
|
||||||
|
echo >> debian/changelog
|
||||||
|
changelog_sign=" -- ${maintainer} ${package_date}"
|
||||||
|
echo "$changelog_sign" >> debian/changelog
|
||||||
|
echo >> debian/changelog
|
||||||
|
ceiling_commit=${floor_commit}
|
||||||
|
}
|
||||||
|
|
||||||
|
function gen_changelog() {
|
||||||
|
limit=10
|
||||||
|
while gen_changelog_entry $ceiling_commit
|
||||||
|
do
|
||||||
|
limit=`expr $limit - 1`
|
||||||
|
echo $changelog_entry
|
||||||
|
if [ "$limit" -le 0 ]
|
||||||
|
then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
gen_changelog
|
||||||
|
cp debian/changelog /dist/changelog
|
31
lib/build.py
Normal file
31
lib/build.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import sys, os, argparse, tempfile
|
||||||
|
sys.path.append(os.path.dirname(__file__) + '/lib')
|
||||||
|
import tamarin
|
||||||
|
|
||||||
|
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__':
|
||||||
|
|
||||||
|
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)
|
47
lib/build.sh
47
lib/build.sh
@ -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
|
|
53
lib/buildtools/tamarin_db
Executable file
53
lib/buildtools/tamarin_db
Executable file
@ -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
|
9
lib/buildtools/tamarin_debug
Executable file
9
lib/buildtools/tamarin_debug
Executable file
@ -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
|
9
lib/buildtools/tamarin_error
Executable file
9
lib/buildtools/tamarin_error
Executable file
@ -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
|
9
lib/buildtools/tamarin_info
Executable file
9
lib/buildtools/tamarin_info
Executable file
@ -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
|
23
lib/buildtools/tamarin_log
Executable file
23
lib/buildtools/tamarin_log
Executable file
@ -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
|
9
lib/buildtools/tamarin_success
Executable file
9
lib/buildtools/tamarin_success
Executable file
@ -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
|
9
lib/buildtools/tamarin_warn
Executable file
9
lib/buildtools/tamarin_warn
Executable file
@ -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
|
@ -1,12 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
|
||||||
source "${DIR}/util.sh"
|
|
||||||
|
|
||||||
info "Updating packages definition..."
|
|
||||||
apt-get update 2> >(stderr) 1> >(stdout)
|
|
||||||
|
|
||||||
info "Installing package $1..."
|
|
||||||
gdebi --n "$1" 2> >(stderr) 1> >(stdout)
|
|
76
lib/tamarin.py
Normal file
76
lib/tamarin.py
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
import os, glob, subprocess, configparser, codecs, sys
|
||||||
|
|
||||||
|
def run_profile_hooks(profile, step, **kwargs):
|
||||||
|
hooks_dir = get_hooks_dir()
|
||||||
|
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)
|
||||||
|
run([hook_path], **kwargs)
|
||||||
|
|
||||||
|
def get_base_dir():
|
||||||
|
return os.path.realpath(os.path.dirname(os.path.abspath(__file__)) + "/..")
|
||||||
|
|
||||||
|
def get_hooks_dir():
|
||||||
|
return os.path.realpath(os.path.dirname(os.path.abspath(__file__)) + "/../hooks")
|
||||||
|
|
||||||
|
def get_lib_dir():
|
||||||
|
return os.path.realpath(os.path.dirname(os.path.abspath(__file__)) + "/../lib")
|
||||||
|
|
||||||
|
def get_utils_dir():
|
||||||
|
return os.path.realpath(os.path.dirname(os.path.abspath(__file__)) + "/../utils")
|
||||||
|
|
||||||
|
def load_profile(profile_name, debug=False):
|
||||||
|
profile_filename = profile_name+".conf"
|
||||||
|
for profile_file in get_available_profiles():
|
||||||
|
if profile_filename == os.path.basename(profile_file):
|
||||||
|
config = configparser.ConfigParser()
|
||||||
|
with codecs.open(profile_file, encoding = 'utf-8', mode = 'r') as handle:
|
||||||
|
config.read_file(handle)
|
||||||
|
return config
|
||||||
|
return None
|
||||||
|
|
||||||
|
def get_profiles_dir():
|
||||||
|
return os.path.realpath(os.path.dirname(os.path.abspath(__file__)) + "/../profiles")
|
||||||
|
|
||||||
|
def get_available_profiles():
|
||||||
|
return glob.glob(get_profiles_dir() + '/*.conf')
|
||||||
|
|
||||||
|
def get_available_profile_names():
|
||||||
|
profile_files = get_available_profiles()
|
||||||
|
return [os.path.splitext(os.path.basename(f))[0] for f in profile_files]
|
||||||
|
|
||||||
|
def get_workspace_dir():
|
||||||
|
"""Return the absolute path to the tamarin workspace ($HOME/.tamarin)"""
|
||||||
|
home = os.environ["HOME"]
|
||||||
|
return os.path.join(os.sep, home, '.tamarin')
|
||||||
|
|
||||||
|
def get_workspace_subdir(subdir):
|
||||||
|
"""Return the absolute path to a subdirectory in tamarin workspace"""
|
||||||
|
dir_path = os.path.join(os.sep, get_workspace_dir(), subdir)
|
||||||
|
os.makedirs(dir_path, exist_ok=True)
|
||||||
|
return dir_path
|
||||||
|
|
||||||
|
def run(cmd, captureOutput=False, pty=False, debug=False, **kwargs):
|
||||||
|
"""Execute an arbitrary command on the system"""
|
||||||
|
if debug:
|
||||||
|
print(" ".join(cmd) if isinstance(cmd, list) else cmd)
|
||||||
|
stdin=subprocess.PIPE
|
||||||
|
kwargs['shell'] = False if isinstance(cmd, list) else True
|
||||||
|
if pty:
|
||||||
|
kwargs['stdin'] = sys.stdin
|
||||||
|
if captureOutput:
|
||||||
|
return subprocess.check_output(cmd, **kwargs)
|
||||||
|
else:
|
||||||
|
return subprocess.check_call(cmd, **kwargs)
|
||||||
|
|
||||||
|
def run_docker(args, captureOutput=False, **kwargs):
|
||||||
|
if isinstance(args, list):
|
||||||
|
cmd = ["docker"] + args
|
||||||
|
else:
|
||||||
|
cmd = "docker " + args
|
||||||
|
return run(cmd, captureOutput=captureOutput, **kwargs)
|
154
lib/util.sh
154
lib/util.sh
@ -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
|
|
||||||
|
|
||||||
}
|
|
241
package
241
package
@ -1,182 +1,139 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
set -e
|
import argparse, sys, shutil, os, subprocess
|
||||||
|
|
||||||
TAMARIN_VERSION=0.0.1
|
sys.path.append(os.path.dirname(__file__) + '/lib')
|
||||||
TAMARIN_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
|
||||||
|
|
||||||
BASE_DIR="$TAMARIN_DIR" source "$TAMARIN_DIR/lib/util.sh"
|
import tamarin
|
||||||
DEFAULT_64_IMAGE="debian:jessie"
|
|
||||||
DEFAULT_32_IMAGE="32bit/debian:jessie"
|
|
||||||
|
|
||||||
function show_usage {
|
def create_args_parser():
|
||||||
echo
|
'''Return a new configured ArgumentParser'''
|
||||||
echo "Usage: $0 -p project_path [-a arch] [-d destination] [-i image] [-k]"
|
profile_names = tamarin.get_available_profile_names()
|
||||||
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
|
parser = argparse.ArgumentParser(description="Generate packages for various GNU/Linux distributions")
|
||||||
function create_container {
|
|
||||||
|
|
||||||
# Escape image name
|
# Define available/required arguments and flags
|
||||||
local escaped_basename=$(echo "$BASE_IMAGE" | sed 's/[^a-z0-9\-\_\.]/\_/gi')
|
parser.add_argument("project_directory", help="The path to your project to package")
|
||||||
# Generate container tag
|
parser.add_argument("-o", "--output", help="The path to the generated packages destination directory", default=".")
|
||||||
container_tag="tamarin:${escaped_basename}_$(date +%s)"
|
parser.add_argument("-p", "--profile", help="The profile to use to package this project (default: debian)", choices=profile_names, default='debian')
|
||||||
# Create temporary dir for the Dockerfile
|
parser.add_argument("-a", "--architecture", help="The target architecture for the package (default: amd64)", default='amd64')
|
||||||
local temp_dir="$(mktemp -d)"
|
parser.add_argument("-b", "--base", help="Use the specified image instead of the profile's one", default='')
|
||||||
|
parser.add_argument("--rebuild", help="Ignore cache and rebuild container's image", action="store_true", default=False)
|
||||||
|
parser.add_argument("--debug", help="Will add extra output and start the container in interactive mode", action="store_true", default=False)
|
||||||
|
parser.add_argument("--cleanup", help="Clear the workspace and remove obsolete Docker images before build", action="store_true", default=False)
|
||||||
|
parser.add_argument("--override-docker-args", help="Override all 'docker run' arguments. Use '[IMAGE_TAG]', '[PROFILE]' and '[ARCH]' to insert the corresponding values into your command.", default="")
|
||||||
|
parser.add_argument("--prepare-only", help="Only prepare build environment for the given profile", action="store_true", default=False)
|
||||||
|
parser.add_argument("--no-lib-mounts", help="Disable Tamarin library volumes mount", action="store_true", default=False)
|
||||||
|
|
||||||
local projectName=${1}
|
return parser
|
||||||
|
|
||||||
# Link lib & hooks folders
|
def build_image(build_workspace, base_image, profile_name, profile, debug=False, rebuild=False):
|
||||||
ln -s $(readlink -f "$TAMARIN_DIR/lib") "$temp_dir/lib"
|
shutil.copytree(tamarin.get_base_dir(), os.path.join(build_workspace, '.tamarin'))
|
||||||
ln -s $(readlink -f "$TAMARIN_DIR/hooks") "$temp_dir/hooks"
|
|
||||||
|
|
||||||
# Create Dockerfile
|
with open("{:s}/Dockerfile".format(build_workspace), 'w') as dockerfile:
|
||||||
cat << EOF > "$temp_dir/Dockerfile"
|
dockerfile.write("FROM {:s}\n".format(base_image))
|
||||||
FROM ${BASE_IMAGE}
|
dockerfile.write("COPY .tamarin /tamarin\n")
|
||||||
|
|
||||||
ENV DEBIAN_FRONTEND noninteractive
|
# Configure "containerbuild" hooks environment
|
||||||
|
hooks_env = os.environ.copy()
|
||||||
|
hooks_env["PATH"] = os.environ['PATH'] + ':' + tamarin.get_lib_dir()
|
||||||
|
|
||||||
RUN apt-get update &&\
|
# Run hooks
|
||||||
apt-get install --yes --no-install-recommends build-essential devscripts equivs
|
tamarin.run_profile_hooks(profile, 'containerbuild', cwd=build_workspace, env=hooks_env, debug=debug)
|
||||||
|
|
||||||
RUN mkdir /root/.tamarin
|
image_tag = "tamarin:{:s}_{:s}_{:d}".format(profile_name, base_image.replace(':', '_').replace('/', '_'), os.getpid())
|
||||||
RUN mkdir /project
|
|
||||||
|
|
||||||
ADD ./lib /root/.tamarin/lib
|
build_args = [ "build", "-t", image_tag ]
|
||||||
ADD ./hooks /hooks
|
|
||||||
RUN chmod +x /root/.tamarin/lib/build.sh
|
|
||||||
|
|
||||||
VOLUME /src
|
if rebuild:
|
||||||
VOLUME /dist
|
build_args += [ "--no-cache" ]
|
||||||
|
|
||||||
EOF
|
tamarin.run_docker(build_args + [build_workspace], debug=debug)
|
||||||
|
|
||||||
exec_hooks "containerbuild" "$temp_dir"
|
return image_tag
|
||||||
|
|
||||||
echo "CMD /root/.tamarin/lib/build.sh ${projectName} ${BUILD_BRANCH} /tmp ${BUILD_TAG}" >> "$temp_dir/Dockerfile"
|
def cleanup(build_workspace=None, debug=False):
|
||||||
|
|
||||||
# Build image
|
if build_workspace == None:
|
||||||
tar -C "$temp_dir" -czh . | docker build -t "$container_tag" - 2> >(stderr) 1> >(stdout)
|
build_workspace = tamarin.get_workspace_subdir('tmp')
|
||||||
|
|
||||||
# Delete temporary folder
|
# Suppression de l'espace de travail de build
|
||||||
rm -rf "$temp_dir"
|
shutil.rmtree(build_workspace, ignore_errors=True)
|
||||||
|
|
||||||
}
|
def validate_args(args):
|
||||||
|
'''TODO'''
|
||||||
|
|
||||||
# Main function
|
if __name__ == "__main__":
|
||||||
function main {
|
|
||||||
|
|
||||||
info "Building container from $BASE_IMAGE..."
|
parser = create_args_parser()
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
local project_name=$(basename ${PROJECT_PATH})
|
if args.cleanup:
|
||||||
|
cleanup(debug=args.debug)
|
||||||
|
|
||||||
# Create container & "$container_tag" variable
|
# Verify project directory
|
||||||
create_container ${project_name}
|
project_dir = os.path.abspath(args.project_directory)
|
||||||
|
output_dir = os.path.abspath(args.output)
|
||||||
|
|
||||||
local docker_opt="run -e \"DISTRIB=$BASE_IMAGE\" -e \"PROJECT_NAME=$project_name\""
|
# Load build profile
|
||||||
|
profile = tamarin.load_profile(args.profile, debug=args.debug)
|
||||||
|
|
||||||
# Expose host uid & gid
|
workspace = tamarin.get_workspace_dir()
|
||||||
docker_opt="${docker_opt} -e HOST_UID=$(id -u) -e HOST_GID=$(id -g)"
|
|
||||||
|
|
||||||
# Expose host proxy variables
|
pid = os.getpid()
|
||||||
docker_opt="${docker_opt} -e HTTP_PROXY=${HTTP_PROXY} -e HTTPS_PROXY=${HTTPS_PROXY}"
|
build_workspace = tamarin.get_workspace_subdir('tmp/build_{:d}'.format(pid))
|
||||||
docker_opt="${docker_opt} -e http_proxy=${http_proxy} -e https_proxy=${https_proxy}"
|
|
||||||
|
|
||||||
# Target architecture
|
shutil.copytree(tamarin.get_utils_dir(), os.path.join(build_workspace, 'utils'))
|
||||||
docker_opt="${docker_opt} -e TARGET_ARCH=${TARGET_ARCH}"
|
|
||||||
|
|
||||||
# If running in terminal, set docker to interactive
|
base_image = args.base if args.base != '' else profile['profile']['default_image']
|
||||||
if [[ -t 1 ]]; then
|
|
||||||
docker_opt="${docker_opt} -it"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ ${PERSIST_CONTAINER} -eq 0 ]]
|
image_tag = build_image(build_workspace, base_image, args.profile, profile, debug=args.debug, rebuild=args.rebuild)
|
||||||
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"
|
if args.prepare_only:
|
||||||
|
exit()
|
||||||
|
|
||||||
info "Switching to container..."
|
kwargs = dict()
|
||||||
debug "docker ${docker_opt}"
|
kwargs['debug'] = args.debug
|
||||||
docker ${docker_opt}
|
|
||||||
res=${?}
|
|
||||||
|
|
||||||
success "Done"
|
docker_args = []
|
||||||
return ${res}
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
# Append custom arguments
|
||||||
# Parsing options
|
if args.override_docker_args != "":
|
||||||
#
|
docker_args = args.override_docker_args.replace('[IMAGE_TAG]', image_tag)
|
||||||
while getopts "vkp:d:i:B:t:a:o:" option
|
docker_args = docker_args.replace('[PROFILE]', args.profile)
|
||||||
do
|
docker_args = docker_args.replace('[ARCH]', args.architecture)
|
||||||
case $option in
|
else:
|
||||||
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
|
docker_args += [ "run", "--rm" ]
|
||||||
[[ -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
|
# volumes definition
|
||||||
info "32bit architecture specified and no specific image given, switching to default 32bit image..."
|
docker_args += [
|
||||||
BASE_IMAGE=${DEFAULT_32_IMAGE}
|
"-v", "{:s}:/src:ro".format(project_dir),
|
||||||
fi
|
"-v", "{:s}:/dist".format(output_dir),
|
||||||
|
]
|
||||||
|
|
||||||
[[ -z ${BASE_IMAGE} ]] && BASE_IMAGE=${DEFAULT_64_IMAGE}
|
if not args.no_lib_mounts:
|
||||||
|
docker_args += [
|
||||||
|
"-v", "{:s}:/tamarin/hooks:ro".format(tamarin.get_hooks_dir()),
|
||||||
|
"-v", "{:s}:/tamarin/lib:ro".format(tamarin.get_lib_dir()),
|
||||||
|
"-v", "{:s}:/tamarin/profiles:ro".format(tamarin.get_profiles_dir()),
|
||||||
|
"-v", "{:s}:/tamarin/utils:ro".format(tamarin.get_utils_dir())
|
||||||
|
]
|
||||||
|
|
||||||
#
|
# Use environment proxy if defined
|
||||||
# Warn user about "proxy"
|
for proxy_var in ['HTTP_PROXY', 'HTTPS_PROXY', 'http_proxy', 'https_proxy']:
|
||||||
#
|
if proxy_var in os.environ:
|
||||||
|
docker_args += ["-e", "{:s}={:s}".format(proxy_var, os.environ[proxy_var])]
|
||||||
|
|
||||||
if [[ -n ${http_proxy} ]]
|
if args.debug:
|
||||||
then
|
kwargs['pty'] = True
|
||||||
warn "You have a proxy defined please make sure docker deamon is configured to use this proxy"
|
docker_args += ["-it", image_tag, "/bin/sh"]
|
||||||
fi
|
helper_cmd = " ".join(["/usr/bin/python3", "/tamarin/lib/build.py", args.profile, args.architecture])
|
||||||
|
print("Executer '{:s}' pour lancer la construction du paquet.".format(helper_cmd))
|
||||||
|
else:
|
||||||
|
docker_args += [image_tag, "/usr/bin/python3", "/tamarin/lib/build.py", args.profile, args.architecture]
|
||||||
|
|
||||||
main
|
# Start container
|
||||||
|
tamarin.run_docker(docker_args, **kwargs)
|
||||||
|
|
||||||
|
cleanup(build_workspace, debug=args.debug)
|
||||||
|
33
profiles/debian.conf
Normal file
33
profiles/debian.conf
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
# Configuration générale du profil
|
||||||
|
[profile]
|
||||||
|
# Image Docker par défaut
|
||||||
|
default_image=reg.cadoles.com/proxy_cache/library/debian:bookworm
|
||||||
|
|
||||||
|
# Configuration de l'étape de pré-construction du conteneur
|
||||||
|
[containerbuild]
|
||||||
|
hooks=
|
||||||
|
containerbuild/debian/install-build-essential,
|
||||||
|
containerbuild/debian/install-git,
|
||||||
|
containerbuild/debian/install-letsencrypt-ca
|
||||||
|
|
||||||
|
# Configuration de l'étape de pré-construction du paquet
|
||||||
|
[prebuild]
|
||||||
|
hooks=
|
||||||
|
prebuild/debian/copy-sources-to-workspace,
|
||||||
|
prebuild/debian/run-project-hooks,
|
||||||
|
prebuild/debian/load-project-db,
|
||||||
|
prebuild/debian/complete-project-db,
|
||||||
|
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=
|
||||||
|
postbuild/debian/run-project-hooks,
|
||||||
|
postbuild/debian/export-dist
|
30
profiles/eole-2.7.0.conf
Normal file
30
profiles/eole-2.7.0.conf
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
# Configuration générale du profil
|
||||||
|
[profile]
|
||||||
|
# Image Docker par défaut
|
||||||
|
default_image=ubuntu:bionic
|
||||||
|
|
||||||
|
# Configuration de l'étape de pré-construction du conteneur
|
||||||
|
[containerbuild]
|
||||||
|
hooks=
|
||||||
|
containerbuild/debian/install-build-essential,
|
||||||
|
containerbuild/debian/install-git,
|
||||||
|
|
||||||
|
# Configuration de l'étape de pré-construction du paquet
|
||||||
|
[prebuild]
|
||||||
|
hooks=
|
||||||
|
prebuild/debian/copy-sources-to-workspace,
|
||||||
|
prebuild/debian/run-project-hooks,
|
||||||
|
prebuild/debian/load-project-db,
|
||||||
|
prebuild/debian/complete-project-db,
|
||||||
|
prebuild/eole/create-changelog,
|
||||||
|
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=
|
||||||
|
postbuild/debian/run-project-hooks,
|
||||||
|
postbuild/debian/export-dist
|
30
profiles/eole-2.7.1.conf
Normal file
30
profiles/eole-2.7.1.conf
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
# Configuration générale du profil
|
||||||
|
[profile]
|
||||||
|
# Image Docker par défaut
|
||||||
|
default_image=ubuntu:bionic
|
||||||
|
|
||||||
|
# Configuration de l'étape de pré-construction du conteneur
|
||||||
|
[containerbuild]
|
||||||
|
hooks=
|
||||||
|
containerbuild/debian/install-build-essential,
|
||||||
|
containerbuild/debian/install-git,
|
||||||
|
|
||||||
|
# Configuration de l'étape de pré-construction du paquet
|
||||||
|
[prebuild]
|
||||||
|
hooks=
|
||||||
|
prebuild/debian/copy-sources-to-workspace,
|
||||||
|
prebuild/debian/run-project-hooks,
|
||||||
|
prebuild/debian/load-project-db,
|
||||||
|
prebuild/debian/complete-project-db,
|
||||||
|
prebuild/eole/create-changelog,
|
||||||
|
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=
|
||||||
|
postbuild/debian/run-project-hooks,
|
||||||
|
postbuild/debian/export-dist
|
30
profiles/eole-2.7.2.conf
Normal file
30
profiles/eole-2.7.2.conf
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
# Configuration générale du profil
|
||||||
|
[profile]
|
||||||
|
# Image Docker par défaut
|
||||||
|
default_image=ubuntu:bionic
|
||||||
|
|
||||||
|
# Configuration de l'étape de pré-construction du conteneur
|
||||||
|
[containerbuild]
|
||||||
|
hooks=
|
||||||
|
containerbuild/debian/install-build-essential,
|
||||||
|
containerbuild/debian/install-git,
|
||||||
|
|
||||||
|
# Configuration de l'étape de pré-construction du paquet
|
||||||
|
[prebuild]
|
||||||
|
hooks=
|
||||||
|
prebuild/debian/copy-sources-to-workspace,
|
||||||
|
prebuild/debian/run-project-hooks,
|
||||||
|
prebuild/debian/load-project-db,
|
||||||
|
prebuild/debian/complete-project-db,
|
||||||
|
prebuild/eole/create-changelog,
|
||||||
|
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=
|
||||||
|
postbuild/debian/run-project-hooks,
|
||||||
|
postbuild/debian/export-dist
|
30
profiles/eole-2.8.0.conf
Normal file
30
profiles/eole-2.8.0.conf
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
# Configuration générale du profil
|
||||||
|
[profile]
|
||||||
|
# Image Docker par défaut
|
||||||
|
default_image=ubuntu:focal
|
||||||
|
|
||||||
|
# Configuration de l'étape de pré-construction du conteneur
|
||||||
|
[containerbuild]
|
||||||
|
hooks=
|
||||||
|
containerbuild/debian/install-build-essential,
|
||||||
|
containerbuild/debian/install-git,
|
||||||
|
|
||||||
|
# Configuration de l'étape de pré-construction du paquet
|
||||||
|
[prebuild]
|
||||||
|
hooks=
|
||||||
|
prebuild/debian/copy-sources-to-workspace,
|
||||||
|
prebuild/debian/run-project-hooks,
|
||||||
|
prebuild/debian/load-project-db,
|
||||||
|
prebuild/debian/complete-project-db,
|
||||||
|
prebuild/eole/create-changelog,
|
||||||
|
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=
|
||||||
|
postbuild/debian/run-project-hooks,
|
||||||
|
postbuild/debian/export-dist
|
30
profiles/eole-2.8.1.conf
Normal file
30
profiles/eole-2.8.1.conf
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
# Configuration générale du profil
|
||||||
|
[profile]
|
||||||
|
# Image Docker par défaut
|
||||||
|
default_image=ubuntu:focal
|
||||||
|
|
||||||
|
# Configuration de l'étape de pré-construction du conteneur
|
||||||
|
[containerbuild]
|
||||||
|
hooks=
|
||||||
|
containerbuild/debian/install-build-essential,
|
||||||
|
containerbuild/debian/install-git,
|
||||||
|
|
||||||
|
# Configuration de l'étape de pré-construction du paquet
|
||||||
|
[prebuild]
|
||||||
|
hooks=
|
||||||
|
prebuild/debian/copy-sources-to-workspace,
|
||||||
|
prebuild/debian/run-project-hooks,
|
||||||
|
prebuild/debian/load-project-db,
|
||||||
|
prebuild/debian/complete-project-db,
|
||||||
|
prebuild/eole/create-changelog,
|
||||||
|
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=
|
||||||
|
postbuild/debian/run-project-hooks,
|
||||||
|
postbuild/debian/export-dist
|
31
profiles/eole-2.9.0.conf
Normal file
31
profiles/eole-2.9.0.conf
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
# Configuration générale du profil
|
||||||
|
[profile]
|
||||||
|
# Image Docker par défaut
|
||||||
|
default_image=ubuntu:jammy
|
||||||
|
|
||||||
|
# Configuration de l'étape de pré-construction du conteneur
|
||||||
|
[containerbuild]
|
||||||
|
hooks=
|
||||||
|
containerbuild/debian/install-build-essential,
|
||||||
|
containerbuild/debian/install-git,
|
||||||
|
containerbuild/eole-2.9.0/configure-additional-repository,
|
||||||
|
|
||||||
|
# Configuration de l'étape de pré-construction du paquet
|
||||||
|
[prebuild]
|
||||||
|
hooks=
|
||||||
|
prebuild/debian/copy-sources-to-workspace,
|
||||||
|
prebuild/debian/run-project-hooks,
|
||||||
|
prebuild/debian/load-project-db,
|
||||||
|
prebuild/debian/complete-project-db,
|
||||||
|
prebuild/eole/create-changelog,
|
||||||
|
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=
|
||||||
|
postbuild/debian/run-project-hooks,
|
||||||
|
postbuild/debian/export-dist
|
5
test/data/debian/dummy-project/debian/changelog
Normal file
5
test/data/debian/dummy-project/debian/changelog
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
dummy-project (0.0.1) unstable; urgency=low
|
||||||
|
|
||||||
|
* Dev release
|
||||||
|
|
||||||
|
-- William Petit <wpetit@cadoles.com> Fri, 16 Oct 2015 15:57:03 +0200
|
1
test/data/debian/dummy-project/debian/compat
Normal file
1
test/data/debian/dummy-project/debian/compat
Normal file
@ -0,0 +1 @@
|
|||||||
|
9
|
13
test/data/debian/dummy-project/debian/control
Normal file
13
test/data/debian/dummy-project/debian/control
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
Source: dummy-project
|
||||||
|
Section: unknown
|
||||||
|
Priority: optional
|
||||||
|
Maintainer: William Petit <wpetit@cadoles.com>
|
||||||
|
Build-Depends: debhelper (>= 8.0.0)
|
||||||
|
Standards-Version: 3.9.4
|
||||||
|
Homepage:
|
||||||
|
Vcs-Git: https://forge.cadoles.com/wpetit/tamarin.git
|
||||||
|
Vcs-Browser: https://forge.cadoles.com/wpetit/tamarin
|
||||||
|
|
||||||
|
Package: dummy-project
|
||||||
|
Architecture: any
|
||||||
|
Description: Projet test pour la construction de paquets via Tamarin
|
8
test/data/debian/dummy-project/debian/rules
Normal file
8
test/data/debian/dummy-project/debian/rules
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#!/usr/bin/make -f
|
||||||
|
# -*- makefile -*-
|
||||||
|
|
||||||
|
# Uncomment this to turn on verbose mode.
|
||||||
|
export DH_VERBOSE=1
|
||||||
|
|
||||||
|
%:
|
||||||
|
dh $@
|
1
test/data/debian/dummy-project/debian/source/format
Normal file
1
test/data/debian/dummy-project/debian/source/format
Normal file
@ -0,0 +1 @@
|
|||||||
|
3.0 (quilt)
|
16
test/package_test.py
Normal file
16
test/package_test.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import unittest, os
|
||||||
|
from importlib.machinery import SourceFileLoader
|
||||||
|
|
||||||
|
package = SourceFileLoader('package', os.path.dirname(__file__) + '/../package').load_module()
|
||||||
|
|
||||||
|
class TestPackage(unittest.TestCase):
|
||||||
|
|
||||||
|
def test_args_parser(self):
|
||||||
|
parser = package.create_args_parser()
|
||||||
|
|
||||||
|
def test_download_and_extract_rkt(self):
|
||||||
|
"""TODO"""
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
2
utils/sshForJenkins.sh
Normal file
2
utils/sshForJenkins.sh
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
exec ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null "$@"
|
Reference in New Issue
Block a user