diff --git a/lib/hostinfo.cpp b/lib/hostinfo.cpp index 289ab42382d7e98270625a074bf98373acdb9c8b..fa159fd277a2977325233ab48bd8b6ede93ccb47 100644 --- a/lib/hostinfo.cpp +++ b/lib/hostinfo.cpp @@ -89,7 +89,6 @@ void HOST_INFO::clear_host_info() { } int HOST_INFO::parse(XML_PARSER& xp, bool static_items_only) { - int i; clear_host_info(); while (!xp.get_tag()) { if (xp.match_tag("/host_info")) return 0; @@ -144,6 +143,7 @@ int HOST_INFO::parse(XML_PARSER& xp, bool static_items_only) { continue; } #else + int i; if (xp.parse_str("docker_version", docker_version, sizeof(docker_version))) continue; if (xp.parse_int("docker_type", i)) { docker_type = (DOCKER_TYPE)i; diff --git a/lib/util.cpp b/lib/util.cpp index b3207604eb4e8772b7db1f1d7bb6f7cb6f3ee424..fe78754d1e13cc2d88fb55db34f1bcb13bdbe0b8 100644 --- a/lib/util.cpp +++ b/lib/util.cpp @@ -701,8 +701,13 @@ string parse_ldd_libc(const char* input) { return s; } +// Set up to issue Docker commands. +// On Win this requires connecting to a shell in the WSL distro +// #ifdef _WIN32 -int DOCKER_CONN::init(DOCKER_TYPE docker_type, string distro_name, bool _verbose) { +int DOCKER_CONN::init( + DOCKER_TYPE docker_type, string distro_name, bool _verbose +) { string err_msg; cli_prog = docker_cli_prog(docker_type); if (docker_type == DOCKER) { @@ -727,6 +732,8 @@ int DOCKER_CONN::init(DOCKER_TYPE docker_type, bool _verbose) { } #endif +// issue a Docker command and return its output in out +// int DOCKER_CONN::command(const char* cmd, vector<string> &out) { char buf[1024]; int retval; @@ -765,9 +772,12 @@ int DOCKER_CONN::command(const char* cmd, vector<string> &out) { return 0; } +// parse the output of 'docker images' +// from the following, return 'boinc__app_test__test_wu' +// // REPOSITORY TAG IMAGE ID CREATED SIZE // localhost/boinc__app_test__test_wu latest cbc1498dfc49 43 hours ago 121 MB - +// int DOCKER_CONN::parse_image_name(string line, string &name) { char buf[1024]; strcpy(buf, line.c_str()); @@ -781,9 +791,12 @@ int DOCKER_CONN::parse_image_name(string line, string &name) { return 0; } +// parse the output of 'docker ps -all'. +// from the following, return boinc__app_test__test_result +// // CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES // 6d4877e0d071 localhost/boinc__app_test__test_wu:latest /bin/sh -c ./work... 43 hours ago Exited (0) 21 hours ago boinc__app_test__test_result - +// int DOCKER_CONN::parse_container_name(string line, string &name) { char buf[1024]; strcpy(buf, line.c_str()); @@ -794,13 +807,16 @@ int DOCKER_CONN::parse_container_name(string line, string &name) { return 0; } +// we name Docker images so that they're +// - distinguishable from non-BOINC images (hence boinc__) +// - unique per WU (hence projurl__wuname) +// - lowercase (required by Docker) +// string docker_image_name( const char* proj_url_esc, const char* wu_name ) { - char buf[1024], url_buf[1024], wu_buf[1024];; + char buf[1024], url_buf[1024], wu_buf[1024]; - // Docker image names can't have upper case chars - // safe_strcpy(url_buf, proj_url_esc); downcase_string(url_buf); safe_strcpy(wu_buf, wu_name); @@ -810,13 +826,14 @@ string docker_image_name( return string(buf); } +// similar for Docker container names, +// but they're unique per result rather than per WU +// string docker_container_name( const char* proj_url_esc, const char* result_name ){ - char buf[1024], url_buf[1024], result_buf[1024];; + char buf[1024], url_buf[1024], result_buf[1024]; - // Docker image names can't have upper case chars - // safe_strcpy(url_buf, proj_url_esc); downcase_string(url_buf); safe_strcpy(result_buf, result_name);