Build source with docker technology
authorEduardo Ramos Testillano (eramedu) <eduardo.ramos.testillano@ericsson.com>
Mon, 13 Apr 2020 00:55:02 +0000 (02:55 +0200)
committerEduardo Ramos Testillano (eramedu) <eduardo.ramos.testillano@ericsson.com>
Fri, 17 Apr 2020 19:28:08 +0000 (21:28 +0200)
.gitignore
README.md
docker-images/anna-build-nodb/Dockerfile [new file with mode: 0644]
docker-images/anna-build-nodb/deps/build.sh [new file with mode: 0755]
tools/build-with-docker [new file with mode: 0755]
tools/version [new file with mode: 0755]

index 9f57f12..d25c0b9 100644 (file)
@@ -29,3 +29,5 @@ cmake_install.cmake
 build/
 Testing/
 install_manifest.txt
+CMakeDoxyfile.in
+CMakeDoxygenDefaults.cmake
index 8826728..2ab6c14 100644 (file)
--- 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 (file)
index 0000000..bbf7e45
--- /dev/null
@@ -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 (executable)
index 0000000..1243d5c
--- /dev/null
@@ -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 (executable)
index 0000000..e0227ac
--- /dev/null
@@ -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 (executable)
index 0000000..33bbb4c
--- /dev/null
@@ -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}
+
+