From e31ebfea329ee799aed4c46d706b511843584fce Mon Sep 17 00:00:00 2001
From: Seva <seva@binarytrails.net>
Date: Mon, 17 Jun 2019 13:04:27 -0400
Subject: [PATCH] docker: finalize restinio conan setup

---
 docker/DockerfileDeps               | 37 ++++++++++--------
 docker/DockerfileDepsLlvm           | 35 ++++++++---------
 docker/conan/restinio/conanfile.py  | 59 +++++++++++++++++++++++++++++
 docker/conan/restinio/conanfile.txt | 11 ++++++
 4 files changed, 109 insertions(+), 33 deletions(-)
 create mode 100644 docker/conan/restinio/conanfile.py
 create mode 100644 docker/conan/restinio/conanfile.txt

diff --git a/docker/DockerfileDeps b/docker/DockerfileDeps
index aadf1071..2cfc89b0 100644
--- a/docker/DockerfileDeps
+++ b/docker/DockerfileDeps
@@ -1,23 +1,28 @@
 FROM ubuntu:16.04
 MAINTAINER Adrien Béraud <adrien.beraud@savoirfairelinux.com>
-RUN apt-get update && apt-get install -y build-essential cmake git wget libncurses5-dev libreadline-dev nettle-dev libgnutls28-dev libuv1-dev cython3 python3-dev libcppunit-dev libjsoncpp-dev libasio-dev libssl-dev python3-setuptools python3-pip && apt-get clean
+RUN apt-get update && apt-get install -y \
+        build-essential cmake git wget libncurses5-dev libreadline-dev nettle-dev \
+        libgnutls28-dev libuv1-dev cython3 python3-dev libcppunit-dev libjsoncpp-dev \
+        libasio-dev libssl-dev python3-setuptools python3-pip \
+    && apt-get clean
 
 #patch for https://github.com/Stiffstream/restinio-conan-example/issues/2
-RUN pip3 install --upgrade cmake && cmake --version
+RUN pip3 install --upgrade cmake
 #install conan & add restinio remotes
 RUN pip3 install conan && \
     conan remote add stiffstream https://api.bintray.com/conan/stiffstream/public && \
     conan remote add public-conan https://api.bintray.com/conan/bincrafters/public-conan
-#clone & setup restinio docker project
-RUN git clone https://github.com/binarytrails/restinio-conan.git
+#setup restinio docker project
+RUN mkdir restinio-conan
+COPY conan/restinio/conanfile.txt restinio-conan/conanfile.txt
+COPY conan/restinio/conanfile.py restinio-conan/conanfile.py
 #build restinio from source
-RUN echo "*** Building RESTinio ***" \
-	&& cd restinio-conan \
-	&& mkdir build \
-	&& cd build \
-	&& conan install -o restinio:boost_libs=none --build=missing ..  \
-    && conan install .. --build=missing
-    #&& conan package --package-folder /usr .
+RUN echo "*** Installing RESTinio & dependencies ***" \
+    && cd restinio-conan \
+    && conan source . \
+    && conan install -o restinio:boost_libs=none --build=missing . \
+    && conan package . -pf /usr/local \
+    && cd ../ && rm -rf restinio*
 #build http_parser fork
 RUN echo "*** Building http_parser for custom HTTP methods ***" \
     && git clone https://github.com/eao197/http-parser.git \
@@ -26,8 +31,8 @@ RUN echo "*** Building http_parser for custom HTTP methods ***" \
 
 #build msgpack from source
 RUN wget https://github.com/msgpack/msgpack-c/releases/download/cpp-2.1.5/msgpack-2.1.5.tar.gz \
-	&& tar -xzf msgpack-2.1.5.tar.gz \
-	&& cd msgpack-2.1.5 && mkdir build && cd build \
-	&& cmake -DMSGPACK_CXX11=ON -DMSGPACK_BUILD_EXAMPLES=OFF -DCMAKE_INSTALL_PREFIX=/usr .. \
-	&& make -j8 && make install \
-	&& cd ../.. && rm -rf msgpack-2.1.5 msgpack-2.1.5.tar.gz
+    && tar -xzf msgpack-2.1.5.tar.gz \
+    && cd msgpack-2.1.5 && mkdir build && cd build \
+    && cmake -DMSGPACK_CXX11=ON -DMSGPACK_BUILD_EXAMPLES=OFF -DCMAKE_INSTALL_PREFIX=/usr .. \
+    && make -j8 && make install \
+    && cd ../.. && rm -rf msgpack-2.1.5 msgpack-2.1.5.tar.gz
diff --git a/docker/DockerfileDepsLlvm b/docker/DockerfileDepsLlvm
index fe7fa58c..9c5b5906 100644
--- a/docker/DockerfileDepsLlvm
+++ b/docker/DockerfileDepsLlvm
@@ -1,28 +1,29 @@
 FROM ubuntu:16.04
 MAINTAINER Adrien Béraud <adrien.beraud@savoirfairelinux.com>
 RUN apt-get update \
-	&& apt-get install -y llvm llvm-dev clang make cmake git wget libncurses5-dev libreadline-dev nettle-dev libgnutls28-dev libuv1-dev libmsgpack-dev libjsoncpp-dev libasio-dev cython3 python3-dev python3-setuptools libcppunit-dev python3-pip \
-	&& apt-get remove -y gcc g++ && apt-get autoremove -y && apt-get clean
+    && apt-get install -y llvm llvm-dev clang make cmake git wget libncurses5-dev libreadline-dev nettle-dev libgnutls28-dev libuv1-dev libmsgpack-dev libjsoncpp-dev libasio-dev cython3 python3-dev python3-setuptools libcppunit-dev python3-pip \
+    && apt-get remove -y gcc g++ && apt-get autoremove -y && apt-get clean
 
 ENV CC cc
 ENV CXX c++
 
 #patch for https://github.com/Stiffstream/restinio-conan-example/issues/2
-RUN pip3 install --upgrade cmake && cmake --version
+RUN pip3 install --upgrade cmake
 #install conan & add restinio remotes
 RUN pip3 install conan && \
     conan remote add stiffstream https://api.bintray.com/conan/stiffstream/public && \
     conan remote add public-conan https://api.bintray.com/conan/bincrafters/public-conan
-#clone & setup restinio docker project
-RUN git clone https://github.com/binarytrails/restinio-conan.git
+#setup restinio docker project
+RUN mkdir restinio-conan
+COPY conan/restinio/conanfile.txt restinio-conan/conanfile.txt
+COPY conan/restinio/conanfile.py restinio-conan/conanfile.py
 #build restinio from source
-RUN echo "*** Building RESTinio ***" \
-	&& cd restinio-conan \
-	&& mkdir build \
-	&& cd build \
-	&& conan install -o restinio:boost_libs=none --build=missing ..  \
-    && conan install .. --build=missing
-    #&& conan package --package-folder /usr .
+RUN echo "*** Installing RESTinio & dependencies ***" \
+    && cd restinio-conan \
+    && conan source . \
+    && conan install -o restinio:boost_libs=none --build=missing . \
+    && conan package . -pf /usr/local \
+    && cd ../ && rm -rf restinio*
 #build http_parser fork
 RUN echo "*** Building http_parser for custom HTTP methods ***" \
     && git clone https://github.com/eao197/http-parser.git \
@@ -31,8 +32,8 @@ RUN echo "*** Building http_parser for custom HTTP methods ***" \
 
 #build msgpack from source
 RUN wget https://github.com/msgpack/msgpack-c/releases/download/cpp-2.1.5/msgpack-2.1.5.tar.gz \
-	&& tar -xzf msgpack-2.1.5.tar.gz \
-	&& cd msgpack-2.1.5 && mkdir build && cd build \
-	&& cmake -DMSGPACK_CXX11=ON -DMSGPACK_BUILD_EXAMPLES=OFF -DCMAKE_INSTALL_PREFIX=/usr .. \
-	&& make -j8 && make install \
-	&& cd ../.. && rm -rf msgpack-2.1.5 msgpack-2.1.5.tar.gz
+    && tar -xzf msgpack-2.1.5.tar.gz \
+    && cd msgpack-2.1.5 && mkdir build && cd build \
+    && cmake -DMSGPACK_CXX11=ON -DMSGPACK_BUILD_EXAMPLES=OFF -DCMAKE_INSTALL_PREFIX=/usr .. \
+    && make -j8 && make install \
+    && cd ../.. && rm -rf msgpack-2.1.5 msgpack-2.1.5.tar.gz
diff --git a/docker/conan/restinio/conanfile.py b/docker/conan/restinio/conanfile.py
new file mode 100644
index 00000000..a434c5ac
--- /dev/null
+++ b/docker/conan/restinio/conanfile.py
@@ -0,0 +1,59 @@
+from conans import ConanFile, CMake, tools
+import os
+
+
+class SobjectizerConan(ConanFile):
+    name = "restinio"
+    version = "0.5.1"
+
+    license = "BSD-3-Clause"
+    url = "https://github.com/Stiffstream/restinio-conan"
+
+    description = (
+            "RESTinio is a header-only C++14 library that gives you "
+            "an embedded HTTP/Websocket server."
+    )
+
+    settings = "os", "compiler", "build_type", "arch"
+    options = {'boost_libs': ['none', 'static', 'shared']}
+    default_options = {'boost_libs': 'none'}
+    generators = "cmake"
+    source_subfolder = "restinio"
+    build_policy = "missing"
+
+    def requirements(self):
+        self.requires.add("http-parser/2.8.1@bincrafters/stable")
+        self.requires.add("fmt/5.3.0@bincrafters/stable")
+
+        if self.options.boost_libs == "none":
+            self.requires.add("asio/1.12.2@bincrafters/stable")
+        else:
+            self.requires.add("boost/1.69.0@conan/stable")
+            if self.options.boost_libs == "shared":
+                self.options["boost"].shared = True
+            else:
+                self.options["boost"].shared = False
+
+    def source(self):
+        source_url = "https://bitbucket.org/sobjectizerteam/restinio/downloads"
+        tools.get("{0}/restinio-{1}.zip".format(source_url, self.version))
+        extracted_dir = "restinio-" + self.version
+        os.rename(extracted_dir, self.source_subfolder)
+
+    def _configure_cmake(self):
+        cmake = CMake(self)
+        cmake.definitions['RESTINIO_INSTALL'] = True
+        cmake.definitions['RESTINIO_FIND_DEPS'] = False
+        cmake.definitions['RESTINIO_USE_BOOST_ASIO'] = self.options.boost_libs
+        cmake.configure(source_folder = self.source_subfolder + "/dev/restinio")
+        return cmake
+
+    def package(self):
+        cmake = self._configure_cmake()
+        self.output.info(cmake.definitions)
+        cmake.install()
+
+    def package_info(self):
+        self.info.header_only()
+        if self.options.boost_libs != "none":
+            self.cpp_info.defines.append("RESTINIO_USE_BOOST_ASIO")
diff --git a/docker/conan/restinio/conanfile.txt b/docker/conan/restinio/conanfile.txt
new file mode 100644
index 00000000..472fd614
--- /dev/null
+++ b/docker/conan/restinio/conanfile.txt
@@ -0,0 +1,11 @@
+[requires]
+restinio/0.5.1@stiffstream/stable
+
+[generators]
+cmake
+
+[options]
+
+[imports]
+bin, *.dll -> ./bin # Copies all dll files from packages bin folder to my "bin" folder
+lib, *.dylib* -> ./bin # Copies all dylib files from packages lib folder to my "bin" folder
-- 
GitLab