From bd64a436427ec210c909afa372fcbb4af87edaf3 Mon Sep 17 00:00:00 2001 From: "Eduardo Ramos Testillano (eramedu)" Date: Mon, 13 Apr 2020 02:55:02 +0200 Subject: [PATCH] Build source with docker technology --- .gitignore | 2 + README.md | 10 +++++ docker-images/anna-build-nodb/Dockerfile | 18 ++++++++ docker-images/anna-build-nodb/deps/build.sh | 10 +++++ tools/build-with-docker | 46 +++++++++++++++++++++ tools/version | 21 ++++++++++ 6 files changed, 107 insertions(+) create mode 100644 docker-images/anna-build-nodb/Dockerfile create mode 100755 docker-images/anna-build-nodb/deps/build.sh create mode 100755 tools/build-with-docker create mode 100755 tools/version diff --git a/.gitignore b/.gitignore index 9f57f12..d25c0b9 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,5 @@ cmake_install.cmake build/ Testing/ install_manifest.txt +CMakeDoxyfile.in +CMakeDoxygenDefaults.cmake diff --git a/README.md b/README.md index 8826728..2ab6c14 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,16 @@ You could use my pre-commit specific template if you want to do some basic check ## Build project +### With docker + +Architectures 'x86_64' and 'armv7l' are supported. Execute: + + > tools/build-with-docker + +Note: database resources building is unsupported at the moment using docker. + +### Natively + This is a CMake based building suite. Install cmake: diff --git a/docker-images/anna-build-nodb/Dockerfile b/docker-images/anna-build-nodb/Dockerfile new file mode 100644 index 0000000..bbf7e45 --- /dev/null +++ b/docker-images/anna-build-nodb/Dockerfile @@ -0,0 +1,18 @@ +FROM ubuntu + +RUN apt-get update && apt-get install -y \ + g++ \ + libssl-dev \ + libxml2-dev \ + libldap2-dev \ + libpcap-dev \ + libgtest-dev \ + doxygen \ + graphviz \ + make \ + cmake + +# Helper tools +COPY deps/build.sh /usr/local/bin + +ENTRYPOINT ["build.sh"] diff --git a/docker-images/anna-build-nodb/deps/build.sh b/docker-images/anna-build-nodb/deps/build.sh new file mode 100755 index 0000000..1243d5c --- /dev/null +++ b/docker-images/anna-build-nodb/deps/build.sh @@ -0,0 +1,10 @@ +#!/bin/sh +if [ -x ./`basename $0` ] +then + exec ./`basename $0` $@ +else + cmake -DSKIP_DATABASE_BUILD=1 $@ . + make -j `grep processor /proc/cpuinfo | wc -l` $2 + make doc +fi +exit $? diff --git a/tools/build-with-docker b/tools/build-with-docker new file mode 100755 index 0000000..e0227ac --- /dev/null +++ b/tools/build-with-docker @@ -0,0 +1,46 @@ +#!/bin/bash + +############# +# VARIABLES # +############# + +REPO_DIR="$(git rev-parse --show-toplevel 2>/dev/null)" +[ -z "$REPO_DIR" ] && { echo "You must execute under a valid git repository !" ; exit 1 ; } + +############# +# FUNCTIONS # +############# + +# $1: image directory +build_image() { + local imgdir=$1 + + local imgname=$(basename ${imgdir}) + local imgtag=${TAG} + + echo "Building ${imgname}:${imgtag} ..." + cd ${imgdir} + + # Dockerfile for other contexts: + local dck_opt= + local preferred=Dockerfile.$(arch) + [ -f ${preferred} ] && { dck_opt="-f ${preferred}" ; echo "Selected '${preferred}' for current architecture." ; } + [ -z "${dck_opt}" -a ! -f Dockerfile ] && { echo "No Dockerfile for this directory. Ignoring ..." ; cd - >/dev/null ; return 1 ; } + + docker build -t ${imgname}:${imgtag} ${dck_opt} . + [ $? -ne 0 ] && { echo "An error ocurred. Aborting ..." ; cd - >/dev/null ; return 1 ; } + cd - >/dev/null +} + +############# +# EXECUTION # +############# + +TAG=$(${REPO_DIR}/tools/version) + +# Build compilation image: +build_image ${REPO_DIR}/docker-images/anna-build-nodb # this image has neither oracle nor mysql installed + +# Build source with previous compilation image: +docker run --rm -it -u $(id -u):$(id -g) -v ${REPO_DIR}:/code -w /code anna-build-nodb:${TAG} + diff --git a/tools/version b/tools/version new file mode 100755 index 0000000..33bbb4c --- /dev/null +++ b/tools/version @@ -0,0 +1,21 @@ +#!/bin/bash + +############# +# VARIABLES # +############# + +REPO_DIR="$(git rev-parse --show-toplevel 2>/dev/null)" +[ -z "$REPO_DIR" ] && { echo "You must execute under a valid git repository !" ; exit 1 ; } + +############# +# EXECUTION # +############# + +# Get version from CMakeLists.txt: +major=$(grep -w "VERSION_MAJOR" ${REPO_DIR}/CMakeLists.txt | egrep -o '[0-9]+') +minor=$(grep -w "VERSION_MINOR" ${REPO_DIR}/CMakeLists.txt | egrep -o '[0-9]+') +patch=$(grep -w "VERSION_PATCH" ${REPO_DIR}/CMakeLists.txt | egrep -o '[0-9]+') + +echo ${major}.${minor}.${patch} + + -- 2.20.1