Skip to content

Commit

Permalink
Merge pull request #7 from EtixLabs/feature/docker-deployment
Browse files Browse the repository at this point in the history
Deployment / CPack / Docker / Boost / Versionning
  • Loading branch information
Ullaakut committed May 20, 2016
2 parents e4ba477 + 7744618 commit fdb146f
Show file tree
Hide file tree
Showing 30 changed files with 440 additions and 168 deletions.
78 changes: 75 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,19 @@
## limitations under the License.

cmake_minimum_required (VERSION 2.8.1)
cmake_policy(SET CMP0042 NEW)
cmake_policy(SET CMP0048 OLD)

set (PROJECT_NAME cameradar)

project (${PROJECT_NAME})

set (${PROJECT_NAME}_VERSION_MAJOR 0)
set (${PROJECT_NAME}_VERSION_MINOR 1)
set (${PROJECT_NAME}_VERSION_PATCH 0)
set (${PROJECT_NAME}_SUFFIX "-beta")
set (${PROJECT_NAME}_VERSION "${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}.${${PROJECT_NAME}_VERSION_PATCH}${${PROJECT_NAME}_SUFFIX}")

find_package(Git REQUIRED)

# compiler flags
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") #enable C++14
Expand All @@ -36,17 +48,77 @@ set (CAMERADAR_CACHE_MANAGERS "")
set(DEPS_DIR ${CMAKE_SOURCE_DIR}/deps)

# output path for cache managers
set (CCTV_CACHE_MANAGER_OUTPUT_FOLDER cache_managers)
set (CCTV_CACHE_MANAGER_OUTPUT_PATH ${CMAKE_BINARY_DIR}/${CCTV_CACHE_MANAGER_OUTPUT_FOLDER})
set (CAMERADAR_CACHE_MANAGER_OUTPUT_FOLDER cache_managers)
set (CAMERADAR_CACHE_MANAGER_OUTPUT_PATH ${CMAKE_BINARY_DIR}/${CAMERADAR_CACHE_MANAGER_OUTPUT_FOLDER})

set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

# the place where the version.h file is generated, used from the main.cpp of cameradar
set (VERSION_INCLUDE_DIR ${PROJECT_BINARY_DIR})

# get the git revision
message (STATUS "retrieve current git revision SHA1 of cameradar")
execute_process(
COMMAND "git" "rev-parse" "HEAD"
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE CAMERADAR_GIT_SHA1
)

# remove last character of the git output (\n)
string(LENGTH ${CAMERADAR_GIT_SHA1} CAMERADAR_GIT_SHA1_LEN)
math(EXPR CAMERADAR_GIT_SHA1_LEN "${CAMERADAR_GIT_SHA1_LEN} - 1")
string(SUBSTRING ${CAMERADAR_GIT_SHA1} 0 ${CAMERADAR_GIT_SHA1_LEN} CAMERADAR_GIT_SHA1)

# print the SHA1
message (STATUS "current cameradar git revision SHA1 is ${CAMERADAR_GIT_SHA1}")

# generate build number from the current timestamp
string(TIMESTAMP CAMERADAR_VERSION_BUILD "%Y%m%d%H%M%S" "UTC")

# print version
message (STATUS "current cameradar build version will be ${CAMERADAR_VERSION_BUILD}")

configure_file (
"${PROJECT_SOURCE_DIR}/version.h.in"
"${PROJECT_BINARY_DIR}/version.h"
)

include_directories (
"cameradar_standalone/include"
"deps/jsoncpp/src/deps.jsoncpp/include"
"deps/boost/src/deps.boost/include"
)

#build cache managers
add_subdirectory (deps)
add_subdirectory (cameradar_standalone)
add_subdirectory (cache_managers)

set (${CAMERADAR_BINARIES} "")
install (PROGRAMS ${CAMERADAR_BINARIES} DESTINATION bin)

install (FILES ${CAMERADAR_CACHE_MANAGERS} DESTINATION cache_managers)

set (${CAMERADAR_LIBRARIES} "")
list (APPEND CAMERADAR_LIBRARIES ${CAMERADAR_INSTALL_DEPENDENCIES} ${CAMERADAR_LIBRARIES})
install (FILES ${CAMERADAR_LIBRARIES} DESTINATION libraries)

install (DIRECTORY ${CMAKE_SOURCE_DIR}/deps/licenses DESTINATION libraries)


# cpack configuration
include (InstallRequiredSystemLibraries)
set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "cameradar")
set (CPACK_PACKAGE_VENDOR "Etix Labs")
set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "cameradar tool")
set (CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}_${${PROJECT_NAME}_VERSION}_${CMAKE_BUILD_TYPE}_${CMAKE_SYSTEM_NAME}")
set (CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
set (CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set (CPACK_PACKAGE_VERSION_MAJOR "0")
set (CPACK_PACKAGE_VERSION_MINOR "1")
set (CPACK_PACKAGE_VERSION_PATCH "0")
set (CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME}_${${PROJECT_NAME}_VERSION}")
set (CPACK_GENERATOR "TGZ")
set (CPACK_SOURCE_GENERATOR "TGZ")

include(CPack)
51 changes: 49 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@ Of course, you can also call for individual tasks if you plug in a Database to C

## Table of content

- [Installation](#installation)
- [Quick install](#quick-install)
- [Dependencies](#quick-install###dependencies)
- [Five steps guide](#quick-install###five-steps-guide)
- [Manual installation](#manual-installation)
- [Dependencies](#manual-installation###dependencies)
- [Steps](#manual-installation###Steps)
- [Advanced docker deployment](#advanced-docker-deployment)
- [Dependencies](#advanced-docker-deployment###dependencies)
- [Deploy a custom version of Cameradar](#advanced-docker-deployment###deploy-a-custom-version-of-cameradar)
- [Configuration](#configuration)
- [Output](#output)
- [Check camera access](#check-camera-access)
Expand All @@ -28,7 +36,27 @@ Of course, you can also call for individual tasks if you plug in a Database to C
- [Next improvements](#next-improvements)
- [License](#license)

## Installation
## Quick install

The quick install uses docker to build Cameradar without polluting your machine with dependencies and makes it easy to deploy Cameradar in a few commands.

### Dependencies

The only dependencies are `docker` and `docker-compose`.

### Five steps guide

1. `git clone [email protected]:EtixLabs/cameradar.git`
2. Go into the Cameradar repository, then to the `deployment` directory
3. Tweak the `conf/cameradar.conf.json` as you need (see [the onfiguration guide here](#configuration) for more information)
4. Run `docker-compose build cameradar` to build the cameradar container
5. Run `docker-compose up cameradar` to launch Cameradar

If you want to deploy your custom version of Cameradar using the same method, you should check the [advanced docker deployment](#advanced-docker-deployment) tutorial here.

## Manual installation

The manual installation is recommended if you want to tweak Cameradar and quickly test them using CMake and running Cameradar in command-line. If you just want to use Cameradar, it is recommended to use the [quick install](#quick-install) instead.

### Dependencies

Expand All @@ -37,6 +65,9 @@ To install Cameradar you will need these packages
* cmake (`cmake`)
* gstreamer1.x (`libgstreamer1.0-dev`)
* ffmpeg (`ffmpeg`)
* libcurl (`libcurl4-openssl-dev`)

### Steps

The simplest way would be to follow these steps :

Expand All @@ -48,6 +79,22 @@ The simplest way would be to follow these steps :
6. You can now customize the `conf/cameradar.conf.json` file to set the subnetworks and specific ports you want to scan, as well as the thumbnail generation path. More information will be given about the configuration file in another part of this document.
7. You are now ready to launch Cameradar by launching `./cameradar` in the cameradar_standalone directory.

## Advanced Docker deployment

### Dependencies

The only dependencies are `docker` and `docker-compose`.

### Deploy a custom version of Cameradar

2. Go into the Cameradar repository, create a directory named `build` and go in it
3. In the build directory, run `cmake .. -DCMAKE_BUILD_TYPE=Release` This will generate the Makefiles you need to build Cameradar
4. Run the command `make package` to compile it into a package
5. Copy your package into the `deployment` directory
6. Run `docker-compose build cameradar` to build the cameradar container using your custom package
5. Run `docker-compose up cameradar` to launch Cameradar


### Configuration

Here is the basic content of the configuration file with simple placeholders :
Expand Down
4 changes: 2 additions & 2 deletions cache_managers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ cmake_minimum_required (VERSION 2.8.1)
cmake_policy(SET CMP0042 NEW)

# set temporarly the ouput path for all server plugins
set (LIBRARY_OUTPUT_PATH ${CCTV_CAMERA_MANAGER_OUTPUT_PATH})
set (LIBRARY_OUTPUT_PATH ${CAMERADAR_CACHE_MANAGER_OUTPUT_PATH})

add_subdirectory(dumb_cache_manager)

set (CCTV_CACHE_MANAGERS ${CCTV_CACHE_MANAGERS} PARENT_SCOPE)
set (CAMERADAR_CACHE_MANAGERS ${CAMERADAR_CACHE_MANAGERS} PARENT_SCOPE)
2 changes: 1 addition & 1 deletion cache_managers/dumb_cache_manager/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ add_library (dumb_cache_manager SHARED ${SOURCES})
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined")
target_link_libraries (dumb_cache_manager)

set (CACHE_MANAGER_NAME ${CAMERADAR_CACHE_MANAGER_OUTPUT_PATH}/${CMAKE_SHARED_LIBRARY_PREFIX}dumb_cache_manager{CMAKE_SHARED_LIBRARY_SUFFIX})
set (CACHE_MANAGER_NAME ${CAMERADAR_CACHE_MANAGER_OUTPUT_PATH}/${CMAKE_SHARED_LIBRARY_PREFIX}dumb_cache_manager${CMAKE_SHARED_LIBRARY_SUFFIX})
list (APPEND CAMERADAR_CACHE_MANAGERS ${CACHE_MANAGER_NAME})
set (CAMERADAR_CACHE_MANAGERS ${CAMERADAR_CACHE_MANAGERS} PARENT_SCOPE)
13 changes: 9 additions & 4 deletions cameradar_standalone/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
## limitations under the License.

cmake_minimum_required (VERSION 2.8.1)
cmake_policy(SET CMP0042 NEW)
cmake_policy(SET CMP0048 OLD)

project(cameradar CXX)

Expand All @@ -23,11 +23,15 @@ include(FindPkgConfig)
pkg_search_module(GSTREAMER REQUIRED gstreamer-1.0)
find_library(LIB_GSTREAMER NAMES ${GSTREAMER_LIBRARIES} HINTS ${GSTREAMER_LIBRARY_DIRS})

include_directories (${GSTREAMER_INCLUDE_DIRS})
include_directories (
${GSTREAMER_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/include
${VERSION_INCLUDE_DIR}
)

link_directories (
${GSTREAMER_LIBRARY_DIRS}
"../../cctv_server2/deps/jsoncpp/src/deps.jsoncpp/src/lib_json"
"../deps/jsoncpp/src/deps.jsoncpp/src/lib_json"
)

if ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
Expand All @@ -52,4 +56,5 @@ add_custom_command(TARGET cameradar PRE_BUILD
${CMAKE_SOURCE_DIR}/cameradar_standalone/conf $<TARGET_FILE_DIR:cameradar>/conf/)

set (BINARIES_NAME ${PROJECT_BINARY_DIR}/cameradar)
list (APPEND CCTV_BINARIES ${BINARIES_NAME})
list (APPEND CAMERADAR_BINARIES ${BINARIES_NAME})
set (CAMERADAR_BINARIES ${CAMERADAR_BINARIES} PARENT_SCOPE)
12 changes: 11 additions & 1 deletion cameradar_standalone/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,18 @@
#include <fs.h> // fs::home
#include <opt_parse.h> // parsing opt
#include <dispatcher.h> // program loop
#include <iostream> // iostream
#include "version.h" // versionning

namespace cmrdr = etix::cameradar;

void
print_version() {
std::cout << "Cameradar version " << CAMERADAR_VERSION << std::endl;
std::cout << "Build " << CAMERADAR_VERSION_BUILD << std::endl;
std::cout << "Git commit " << CAMERADAR_VERSION_GIT_SHA1 << std::endl;
}

// Command line parsing
std::pair<bool, etix::tool::opt_parse>
parse_cmdline(int argc, char* argv[]) {
Expand All @@ -37,7 +46,7 @@ parse_cmdline(int argc, char* argv[]) {
opt_parse.print_help();
return std::make_pair(false, opt_parse);
} else if (opt_parse.exist("-v")) {
std::cout << "Cameradar 0.1" << std::endl;
print_version();
return std::make_pair(false, opt_parse);
} else if (opt_parse.has_error()) {
std::cout << "Usage: ./cameradar [option]\n\toptions:\n" << std::endl;
Expand Down Expand Up @@ -76,6 +85,7 @@ main(int argc, char* argv[]) {
auto args = parse_cmdline(argc, argv);
if (not args.first) return EXIT_FAILURE;

print_version();
// configure file configuration path
auto conf_path = std::string{};
if (not args.second.exist("-c")) {
Expand Down
6 changes: 3 additions & 3 deletions cmake/boost.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ set(BOOST_LIBRARY_DIR ${BOOST_LIBRARY_DIR} PARENT_SCOPE)

# list all the boost libraries .dylib/.so
file(GLOB BOOST_INSTALL_DEPENDENCIES "${BOOST_LIBRARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}boost_*${CMAKE_SHARED_LIBRARY_SUFFIX}")
list (APPEND CCTV_INSTALL_DEPENDENCIES ${BOOST_INSTALL_DEPENDENCIES})
list (APPEND CAMERADAR_INSTALL_DEPENDENCIES ${BOOST_INSTALL_DEPENDENCIES})
# on linux
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
file(GLOB BOOST_INSTALL_DEPENDENCIES "${BOOST_LIBRARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}boost_*${CMAKE_SHARED_LIBRARY_SUFFIX}.${BOOST_VERSION}")
list (APPEND CCTV_INSTALL_DEPENDENCIES ${BOOST_INSTALL_DEPENDENCIES})
list (APPEND CAMERADAR_INSTALL_DEPENDENCIES ${BOOST_INSTALL_DEPENDENCIES})
endif()

set(CCTV_INSTALL_DEPENDENCIES ${CCTV_INSTALL_DEPENDENCIES} PARENT_SCOPE)
set(CAMERADAR_INSTALL_DEPENDENCIES ${CAMERADAR_INSTALL_DEPENDENCIES} PARENT_SCOPE)
4 changes: 2 additions & 2 deletions cmake/jsoncpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ set (JSONCPP_LIBRARY_DIR "${SOURCE_DIR}/src/lib_json")
set (JSONCPP_LIBRARY_DIR ${JSONCPP_LIBRARY_DIR} PARENT_SCOPE)

file(GLOB JSONCPP_INSTALL_DEPENDENCIES "${JSONCPP_LIBRARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}jsoncpp*${CMAKE_SHARED_LIBRARY_SUFFIX}*")
list (APPEND CCTV_INSTALL_DEPENDENCIES ${JSONCPP_INSTALL_DEPENDENCIES})
list (APPEND CAMERADAR_INSTALL_DEPENDENCIES ${JSONCPP_INSTALL_DEPENDENCIES})

set(CCTV_INSTALL_DEPENDENCIES ${CCTV_INSTALL_DEPENDENCIES} PARENT_SCOPE)
set(CAMERADAR_INSTALL_DEPENDENCIES ${CAMERADAR_INSTALL_DEPENDENCIES} PARENT_SCOPE)
21 changes: 21 additions & 0 deletions deployment/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM ubuntu:15.10

MAINTAINER [email protected]

ENV LD_LIBRARY_PATH="/cameradar/libraries"

RUN apt-get update && apt-get install -y \
nmap \
ffmpeg \
libgstreamer1.0-dev \
gstreamer1.0-plugins-base \
gstreamer1.0-plugins-good \
libcurl4-openssl-dev

ADD cameradar_*_Release_Linux.tar.gz /
RUN mv cameradar_*_Release_Linux cameradar

RUN mkdir /conf
ADD run.sh /run.sh

CMD ["/run.sh"]
Binary file not shown.
14 changes: 14 additions & 0 deletions deployment/conf/cameradar.conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"subnets" : "172.16.100.13,localhost",

// If not specified, will scan all ports (1-65535)
"ports" : "554,8554",
"rtsp_url_file" : "conf/url.json",
"rtsp_ids_file" : "conf/ids.json",

// You must give an accessible path to an already existing directory
"thumbnail_storage_path" : "/tmp",

"cache_manager_path" : "/cameradar/cache_managers",
"cache_manager_name" : "dumb"
}
31 changes: 31 additions & 0 deletions deployment/conf/ids.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"username": [
"",
"admin",
"Admin",
"root",
"supervisor",
"ubnt"
],
"password" : [
"",
"admin",
"9999",
"123456",
"pass",
"camera",
"1234",
"12345",
"fliradmin",
"system",
"jvc",
"meinsm",
"root",
"4321",
"1111111",
"password",
"ikwd",
"supervisor",
"ubnt"
]
}
Loading

0 comments on commit fdb146f

Please sign in to comment.