diff --git a/GPP/cpp/GPP.cpp b/GPP/cpp/GPP.cpp index afc5d7329..f1b3769fb 100644 --- a/GPP/cpp/GPP.cpp +++ b/GPP/cpp/GPP.cpp @@ -1428,6 +1428,60 @@ CF::ExecutableDevice::ProcessID_Type GPP_i::execute (const char* name, const CF: prepend_args.push_back(waveform_name+"."+name_binding); } } + bool useDocker = false; + if (tmp_params.find("__DOCKER_IMAGE__") != tmp_params.end()) { + std::string image_name = tmp_params["__DOCKER_IMAGE__"].toString(); + LOG_DEBUG(GPP_i, __FUNCTION__ << "Component specified a Docker image: " << image_name); + std::string target = GPP_i::find_exec("docker"); + if(!target.empty()) { + char buffer[128]; + std::string result = ""; + std::string docker_query = target + " image -q " + image_name; + FILE* pipe = popen(docker_query.c_str(), "r"); + if (!pipe) + throw CF::ExecutableDevice::ExecuteFail(CF::CF_EINVAL, "Could not run popen"); + try { + while (!feof(pipe)) { + if (fgets(buffer, 128, pipe) != NULL) { + result += buffer; + } + } + } catch (...) { + pclose(pipe); + throw; + } + pclose(pipe); + if (result.empty()) { + CF::Properties invalidParameters; + invalidParameters.length(invalidaParameters.length() + 1); + invalidParameters[invalidParameters.length() -1].id = "__DOCKER_IMAGE__"; + invalidParameters[invalidParameters.length() -1].value <<= image_name.c_str(); + throw CF::ExecutableDevice::InvalidParameters(invalidParameters); + } + std::string container_name(component_id); + std::replace(container_name.begin(), container_name.end(), ':', '-'); + prepend_args.push_back(target); + prepend_args.push_back("run"); + prepend_args.push_back("--sig-proxy=true"); + prepend_args.push_back("--rm"); + prepend_args.push_back("--name"); + prepend_args.push_back(container_name); + prepend_args.push_back("--net=host"); + prepend_args.push_back("-v"); + prepend_args.push_back(docker_omniorb_cfg+":/etc/omniORB.cfg"); + if ( tmp_params.find("__DOCKER_ARGS__") != tmp_params.end()) { + std::string docker_args_raw = tmp_params["__DOCKER_ARGS__"].toString(); + std::vector docker_args; + boost::split(docker_args, docker_args_raw, boost::is_any_of(" ")); + BOOST_FOREACH( const std::string& arg, docker_args) { + prepend_args.push_back(arg); + } + } + prepend_args.push_back(image_name); + LOG_DEBUG(GPP_i, __FUNCTION__ << "Component will launch within a Docker container using this image: " << image_name); + useDocker = true; + } + } CF::ExecutableDevice::ProcessID_Type ret_pid; try { ret_pid = do_execute(name, options, tmp_params, prepend_args); diff --git a/GPP/cpp/GPP.h b/GPP/cpp/GPP.h index fac8492ed..6f0d609bf 100644 --- a/GPP/cpp/GPP.h +++ b/GPP/cpp/GPP.h @@ -94,7 +94,8 @@ class GPP_i : public GPP_base CF::ExecutableDevice::ProcessID_Type do_execute (const char* name, const CF::Properties& options, const CF::Properties& parameters, - const std::vector prepend_args) + const std::vector prepend_args, + const bool use_docker) throw (CF::ExecutableDevice::ExecuteFail, CF::InvalidFileName, CF::ExecutableDevice::InvalidOptions, CF::ExecutableDevice::InvalidParameters, diff --git a/GPP/cpp/GPP_base.cpp b/GPP/cpp/GPP_base.cpp index ec367414a..0545c2a84 100644 --- a/GPP/cpp/GPP_base.cpp +++ b/GPP/cpp/GPP_base.cpp @@ -187,7 +187,15 @@ void GPP_base::loadProperties() "", "external", "property"); - + + addProperty(docker_omniorb_cfg, + "docker_omniorb_cfg", + "docker_omniorb_cfg", + "readonly", + "/etc/omniORB.cfg", + "external", + "property"); + addProperty(mcastnicInterface, "", "DCE:4e416acc-3144-47eb-9e38-97f1d24f7700", diff --git a/GPP/cpp/GPP_base.h b/GPP/cpp/GPP_base.h index ea7a46eba..e46488a65 100644 --- a/GPP/cpp/GPP_base.h +++ b/GPP/cpp/GPP_base.h @@ -59,8 +59,10 @@ class GPP_base : public ExecutableDevice_impl, protected ThreadedComponent std::string os_version; /// Property: hostName std::string hostName; + // Property: docker_omniorb_cfg + std::string docker_omniorb_cfg; /// Property: useScreen - bool useScreen; + bool useScreen; /// Property: componentOutputLog std::string componentOutputLog; /// Property: mcastnicInterface diff --git a/GPP/tests/.md5sums b/GPP/tests/.md5sums new file mode 100644 index 000000000..6ac7101fd --- /dev/null +++ b/GPP/tests/.md5sums @@ -0,0 +1 @@ +dbaf096c6b94ee57160c4c2e3f5abc26 test_GPP.py