Skip to content

Commit

Permalink
fix and simplify docker detection
Browse files Browse the repository at this point in the history
Signed-off-by: Vitalii Koshura <[email protected]>
  • Loading branch information
AenBleidd committed Aug 14, 2024
1 parent 6c3d4eb commit ecc6d78
Show file tree
Hide file tree
Showing 18 changed files with 422 additions and 376 deletions.
21 changes: 6 additions & 15 deletions client/client_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,24 +280,15 @@ void CLIENT_STATE::show_host_info() {
}
#endif
}
if (host_info.docker_use){
if (host_info.docker_available) {
msg_printf(NULL, MSG_INFO, "Docker is installed and available");
}
else{
} else {
msg_printf(NULL, MSG_INFO, "Docker is not installed or is not available for running task");
}

if (strlen(host_info.docker_compose_version)){
if ((strstr(host_info.docker_compose_version, "v1")) && (strstr(host_info.docker_compose_version, "v2"))){
msg_printf(NULL, MSG_INFO, "Docker compose (new and old versions: docker-compose and docker compose) is installed and available for running task");
}else if (strstr(host_info.docker_compose_version, "v1")) {
msg_printf(NULL, MSG_INFO, "Docker compose (old version: docker-compose) is installed and available for running task");
}else if (strstr(host_info.docker_compose_version, "v2")){
msg_printf(NULL, MSG_INFO, "Docker compose (new version: docker compose) is installed and available for running task");
}
else{
msg_printf(NULL, MSG_INFO, "Docker compose is not installed or is not available for running task");
}
if (host_info.docker_compose_available) {
msg_printf(NULL, MSG_INFO, "Docker compose is installed and available");
} else {
msg_printf(NULL, MSG_INFO, "Docker compose is not installed or is not available for running task");
}
}

Expand Down
11 changes: 2 additions & 9 deletions client/cs_statefile.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2022 University of California
// https://boinc.berkeley.edu
// Copyright (C) 2024 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
Expand Down Expand Up @@ -977,13 +977,6 @@ int CLIENT_STATE::parse_app_info(PROJECT* p, FILE* in) {
delete avp;
continue;
}
if (cc_config.dont_use_docker_compose && strstr(avp->plan_class, "docker")) {
msg_printf(p, MSG_INFO,
"skipping app with docker compose in app_info.xml; docker compose disabled in cc_config.xml"
);
delete avp;
continue;
}
if (strlen(avp->platform) == 0) {
safe_strcpy(avp->platform, get_primary_platform());
}
Expand Down
109 changes: 26 additions & 83 deletions client/hostinfo_unix.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2021 University of California
// https://boinc.berkeley.edu
// Copyright (C) 2024 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
Expand All @@ -20,7 +20,6 @@
// Try to keep this well-organized and not nested.

#include "version.h" // version numbers from autoconf
#include <fstream>
#include "cpp.h"
#include "config.h"

Expand Down Expand Up @@ -1237,91 +1236,38 @@ int HOST_INFO::get_virtualbox_version() {
//check if docker compose or docker-compose is installed on volunteer's host
//
int HOST_INFO::get_docker_compose_info(){
FILE* fd;
char buf[MAXPATHLEN];

std::ofstream compose_file ("docker-compose.yaml");
compose_file << "version: \"2\"\nservices: \n hello: \n image: \"hello-world\" \n" << std::endl;

char* docker_command = "docker-compose up 2>&1";
fd = popen(docker_command, "r");
if (fd){
while(!feof(fd)){
if (fgets(buf, sizeof(buf), fd)){
if (strstr(buf, "Hello from Docker!")){
safe_strcat(docker_compose_version, "v1");
break;
}
}
}
pclose(fd);
}

docker_command = "docker compose up 2>&1";
fd = popen(docker_command, "r");
if (fd){
while(!feof(fd)){
if (fgets(buf, sizeof(buf), fd)){
if (strstr(buf, "Hello from Docker!")){
safe_strcat(docker_compose_version, "v2");
break;
}
}
}
pclose(fd);
}

std::remove("docker-compose.yaml");

if (!(strstr(docker_compose_version, "v1"))){
if (!(strstr(docker_compose_version, "v2"))){
safe_strcat(docker_compose_version, "not_used");
FILE* f = popen(command_get_docker_compose_version, "r");
if (f) {
char buf[256];
fgets(buf, 256, f);
std::string version;
if (get_docker_compose_version_string(buf, version)) {
docker_compose_available = true;
safe_strcpy(docker_compose_version, version.c_str());
}
pclose(f);
return 0;
}

return 0;
return 1;
}


//check if docker is installed on volunteer's host
//
int HOST_INFO::get_docker_info(bool& docker_use){
char buf[256];
char buf_command[256];
FILE* fd;
FILE* fd_1;
char docker_cmd [256];

strcpy(docker_cmd, "which -a docker 2>&1");
fd = popen(docker_cmd, "r");
if (fd){
while(!feof(fd)){
if (fgets(buf, sizeof(buf), fd)){
strip_whitespace(buf);
if (!(access(buf, X_OK))){
strcpy(docker_cmd, buf);
strcat(docker_cmd, " run --rm hello-world 2>&1");
fd_1 = popen(docker_cmd, "r");
if (fd_1){
while(!feof(fd_1)){
if (fgets(buf_command, sizeof(buf_command), fd_1)){
if (strstr(buf_command, "Hello from Docker!")){
docker_use = true;
break;
}
}
}
pclose(fd_1);
}
}
if (docker_use){
break;
}
}
int HOST_INFO::get_docker_info(){
FILE* f = popen(command_get_docker_version, "r");
if (f) {
char buf[256];
fgets(buf, 256, f);
std::string version;
if (get_docker_version_string(buf, version)) {
docker_available = true;
safe_strcpy(docker_version, version.c_str());
}
pclose(fd);
pclose(f);
return 0;
}
return 0;
return 1;
}


Expand Down Expand Up @@ -1773,10 +1719,7 @@ int HOST_INFO::get_host_info(bool init) {
}

if(!cc_config.dont_use_docker){
get_docker_info(docker_use);
}

if(!cc_config.dont_use_docker_compose){
get_docker_info();
get_docker_compose_info();
}

Expand Down
117 changes: 3 additions & 114 deletions client/hostinfo_win.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2018 University of California
// https://boinc.berkeley.edu
// Copyright (C) 2024 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
Expand Down Expand Up @@ -29,8 +29,6 @@
#include "str_util.h"
#include "str_replace.h"
#include "util.h"
#include <fstream>


#include "client_msgs.h"
#include "client_types.h"
Expand Down Expand Up @@ -1552,98 +1550,6 @@ int get_network_usage_totals(unsigned int& total_received, unsigned int& total_s
return iRetVal;
}

//check if docker compose or docker-compose is installed on volunteer's host
//
int HOST_INFO::get_docker_compose_info(){
FILE* fd;
char buf[MAXPATHLEN];

std::ofstream compose_file ("docker-compose.yaml");
compose_file << "version: \"2\"\nservices: \n hello: \n image: \"hello-world\" \n" << std::endl;

char* docker_command = "wsl docker-compose up 2>&1";
fd = _popen(docker_command, "r");
if (fd){
while(!feof(fd)){
if (fgets(buf, sizeof(buf), fd)){
if (strstr(buf, "Hello from Docker!")){
safe_strcat(docker_compose_version, "v1");
break;
}
}
}
_pclose(fd);
}

docker_command = "wsl docker compose up 2>&1";
fd = _popen(docker_command, "r");
if (fd){
while(!feof(fd)){
if (fgets(buf, sizeof(buf), fd)){
if (strstr(buf, "Hello from Docker!")){
safe_strcat(docker_compose_version, "v2");
break;
}
}
}
_pclose(fd);
}

std::remove("docker-compose.yaml");

if (!(strstr(docker_compose_version, "v1"))){
if (!(strstr(docker_compose_version, "v2"))){
safe_strcat(docker_compose_version, "not_used");
}
}

return 0;
}


//check if docker is installed on volunteer's host
//
int HOST_INFO::get_docker_info(bool& docker_use){
char buf[256];
FILE* fd;
FILE *fd_1;

char* docker_command = "wsl which -a docker 2>&1";
fd = _popen(docker_command, "r");
if (fd) {
while (!feof(fd)){
if (fgets(buf + 4, sizeof(buf), fd)){
buf[0] = 'w';
buf[1] = 's';
buf[2] = 'l';
buf[3] = ' ';
int i, j;
for (i = 0, j = 0; buf[i]; i++) {
if (buf[i] != '\n') {
buf[j++] = buf[i];
}
}
buf[j] = '\0';
docker_command = strcat(buf, " run --rm hello-world 2>&1");
fd_1 = _popen(docker_command, "r");
if (fd_1){
while (!feof(fd_1)){
if (fgets(buf, sizeof(buf), fd_1)){
if (strstr(buf, "Hello from Docker!")){
docker_use = true;
break;
}
}
}
_pclose(fd_1);
}
}
}
_pclose(fd);
}
return 0;
}

// see if Virtualbox is installed
//
int HOST_INFO::get_virtualbox_version() {
Expand Down Expand Up @@ -1763,26 +1669,9 @@ int HOST_INFO::get_host_info(bool init) {
if (!cc_config.dont_use_wsl) {
OSVERSIONINFOEX osvi;
if (get_OSVERSIONINFO(osvi) && osvi.dwMajorVersion >= 10) {
get_wsl_information(wsl_available, wsls);
get_wsl_information(wsl_available, wsls, !cc_config.dont_use_docker, docker_available, docker_compose_available);
}
}

if ((!cc_config.dont_use_docker) && (!cc_config.dont_use_wsl)){
if (wsl_available){
for (size_t i = 0; i < wsls.wsls.size(); ++i){
const WSL& wsl = wsls.wsls[i];
if (wsl.is_default){
if (wsl.version.find("WSL2") != std::string::npos){
get_docker_info(docker_use);
if (!cc_config.dont_use_docker_compose){
get_docker_compose_info();
}
}
}
}
}
}

#endif
if (!cc_config.dont_use_vbox) {
get_virtualbox_version();
Expand Down
Loading

0 comments on commit ecc6d78

Please sign in to comment.