Mise en place hooks debian + début script check-install

This commit is contained in:
wpetit 2015-07-02 17:01:26 +02:00
parent a45d9c5fa3
commit afe7725c1b
6 changed files with 135 additions and 17 deletions

71
check-install.sh Executable file
View File

@ -0,0 +1,71 @@
#!/usr/bin/env bash
source ./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> Nom de l'image Docker à utiliser comme environnement pour tester l'installation"
echo
}
function create_container {
# Escape image name
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
temp_dir="$(mktemp -d)"
# Create Dockerfile
cat << EOF > "$temp_dir/Dockerfile"
FROM $BASE_IMAGE
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update
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" - 1>&2
# Delete temporary folder
rm -rf "$temp_dir"
# Return newly created container's tag
echo $container_tag
}
function main {
container_tag=$(create_container)
docker run -e "DISTRIB=$BASE_IMAGE" --rm -v="$DEB_DIR:/deb" "$container_tag" "/deb/$DEB_NAME"
}
# Test for arguments
if [ -z "$1" ] || [ -z "$2" ]; then
show_usage
exit 1
fi
DEB_PATH=$(readlink -f "$1")
DEB_NAME=$(basename "$DEB_PATH")
DEB_DIR=$(dirname "$DEB_PATH")
BASE_IMAGE="$2"
main

View File

@ -49,12 +49,11 @@ function exec_hook {
} }
function create_debian_metadata { function create_debian_control_file {
build_dir="${1}" debian_dir="${1}"
mkdir -p "${build_dir}/DEBIAN"
control_file="${build_dir}/DEBIAN/control" control_file="${debian_dir}/control"
touch "${control_file}" touch "${control_file}"
package_name=$(get_project_opt .name) package_name=$(get_project_opt .name)
@ -69,8 +68,8 @@ function create_debian_metadata {
package_priority=$(get_project_opt .priority) package_priority=$(get_project_opt .priority)
echo "Priority: ${package_priority:-optional}" >> "${control_file}" echo "Priority: ${package_priority:-optional}" >> "${control_file}"
package_arch=$(get_project_opt .priority) package_arch=$(get_project_opt .package_arch)
echo "Architecture: ${package_arch:-any}" >> "${control_file}" echo "Architecture: ${package_arch:-all}" >> "${control_file}"
dependencies=$( get_project_opt ".dependencies | .[\"${DISTRIB}\"] | @sh" | sed "s/' '/, /g" | sed "s/'//g" ) dependencies=$( get_project_opt ".dependencies | .[\"${DISTRIB}\"] | @sh" | sed "s/' '/, /g" | sed "s/'//g" )
@ -86,6 +85,49 @@ function create_debian_metadata {
} }
function create_debian_hooks {
debian_dir="${1}"
pre_install="$(get_project_opt .hooks.preInstall)"
if [ ! -z "${pre_install}" ]; then
cp "${SRC_DIR}/${pre_install}" "${debian_dir}/preinst"
chmod +x "${debian_dir}/preinst"
fi
post_install="$(get_project_opt .hooks.postInstall)"
if [ ! -z "${post_install}" ]; then
cp "${SRC_DIR}/${post_install}" "${debian_dir}/postinst"
chmod +x "${debian_dir}/postinst"
fi
pre_remove="$(get_project_opt .hooks.preRemove)"
if [ ! -z "${pre_remove}" ]; then
cp "${SRC_DIR}/${pre_remove}" "${debian_dir}/prerm"
chmod +x "${debian_dir}/prerm"
fi
post_remove="$(get_project_opt .hooks.postRemove)"
if [ ! -z "${post_remove}" ]; then
cp "${SRC_DIR}/${post_remove}" "${debian_dir}/postrm"
chmod +x "${debian_dir}/postrm"
fi
}
function create_debian_metadata {
build_dir="${1}"
debian_dir="${build_dir}/DEBIAN"
# Ensure debian dir exists
mkdir -p "${debian_dir}"
create_debian_control_file "${debian_dir}"
create_debian_hooks "${debian_dir}"
}
function build_project { function build_project {
project_name="$(get_project_opt '.name')" project_name="$(get_project_opt '.name')"
@ -107,8 +149,11 @@ function build_project {
exec_hook "preBuild" "${build_dir}" exec_hook "preBuild" "${build_dir}"
# Ensure $DIST_DIR exists
mkdir -p "${DIST_DIR}"
cd "${build_dir}/.." cd "${build_dir}/.."
dpkg-deb --build "${project_name}" dpkg-deb --build "${project_name}" ${DIST_DIR}
info "Package created ! (${build_dir}/${project_name}.deb)" info "Package created ! (${build_dir}/${project_name}.deb)"
@ -117,14 +162,10 @@ function build_project {
exit 1 exit 1
fi fi
cd / cd ${SRC_DIR}
exec_hook "postBuild" "${build_dir}" exec_hook "postBuild" "${build_dir}"
# Copie du paquet nouvellement créé dans le répertoire "dist"
mkdir -p "${DIST_DIR}"
cp "${build_dir}/../${project_name}.deb" "${DIST_DIR}/${project_name}.deb"
} }
function main { function main {

3
lib/install.sh Normal file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env bash
dpkg --install "$1" || apt-get install -f

View File

@ -22,7 +22,7 @@ function create_container {
# Escape image name # Escape image name
escaped_basename=$(echo "$BASE_IMAGE" | sed 's/[^a-z0-9\-\_\.]/\_/gi') escaped_basename=$(echo "$BASE_IMAGE" | sed 's/[^a-z0-9\-\_\.]/\_/gi')
# Generate container tag # Generate container tag
container_tag="bricklayer:${escaped_basename}_$(date +%s)" container_tag="tamarin:${escaped_basename}_$(date +%s)"
# Create temporary dir for the Dockerfile # Create temporary dir for the Dockerfile
temp_dir="$(mktemp -d)" temp_dir="$(mktemp -d)"
@ -38,13 +38,13 @@ function create_container {
RUN apt-get update &&\ RUN apt-get update &&\
apt-get install jq apt-get install jq
ADD ./lib /bricklayer ADD ./lib /root/.tamarin
RUN chmod +x /bricklayer/build.sh RUN chmod +x /root/.tamarin/build.sh
VOLUME /src VOLUME /src
VOLUME /dist VOLUME /dist
CMD /bricklayer/build.sh CMD /root/.tamarin/build.sh
EOF EOF
# Build image # Build image

View File

@ -0,0 +1,3 @@
#!/bin/sh
echo "Test pre-install"

View File

@ -9,7 +9,7 @@
"hooks": { "hooks": {
"preBuild": "./scripts/pre-build.sh", "preBuild": "./scripts/pre-build.sh",
"postBuild": "./scripts/post-build.sh", "postBuild": "./scripts/post-build.sh",
"preInstall": "", "preInstall": "./scripts/pre-install.sh",
"preRemove": "", "preRemove": "",
"postInstall": "", "postInstall": "",
"postRemove": "" "postRemove": ""