Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an opportunity to check if docker/docker compose is installed on … #5618

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions client/client_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,25 @@ void CLIENT_STATE::show_host_info() {
}
#endif
}
if (host_info.docker_use){
msg_printf(NULL, MSG_INFO, "Docker is installed and available");
}
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");
}
}
}

int rsc_index(const char* name) {
Expand Down
14 changes: 14 additions & 0 deletions client/cs_statefile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,20 @@ int CLIENT_STATE::parse_app_info(PROJECT* p, FILE* in) {
delete avp;
continue;
}
if (cc_config.dont_use_docker && strstr(avp->plan_class, "docker")) {
msg_printf(p, MSG_INFO,
"skipping docker app in app_info.xml; docker disabled in cc_config.xml"
);
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
100 changes: 99 additions & 1 deletion client/hostinfo_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// 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 @@ -1231,10 +1231,100 @@ int HOST_INFO::get_virtualbox_version() {
pclose(fd);
}
}
return 0;
}

//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");
}
}

return 0;
}


//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;
}
}
}
pclose(fd);
}
return 0;
}


// get p_vendor, p_model, p_features
//
int HOST_INFO::get_cpu_info() {
Expand Down Expand Up @@ -1682,6 +1772,14 @@ int HOST_INFO::get_host_info(bool init) {
get_virtualbox_version();
}

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

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

get_cpu_info();
get_cpu_count();
get_memory_info();
Expand Down
110 changes: 110 additions & 0 deletions client/hostinfo_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#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 @@ -1542,6 +1544,97 @@ 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
//
Expand Down Expand Up @@ -1665,6 +1758,23 @@ int HOST_INFO::get_host_info(bool init) {
get_wsl_information(wsl_available, wsls);
}
}

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
3 changes: 3 additions & 0 deletions client/hostinfo_wsl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ int get_wsl_information(bool& wsl_available, WSLS& wsls) {
char wsl_dist_version[256];

const std::string& distro = distros[i];
if (distro == "docker-desktop-data"){
continue;
}
WSL wsl;
wsl.distro_name = distro;
if (distro == default_distro) {
Expand Down
8 changes: 8 additions & 0 deletions client/log_flags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ void CC_CONFIG::show() {
if (dont_use_wsl) {
msg_printf(NULL, MSG_INFO, "Config: don't use the Windows Subsystem for Linux");
}
if (dont_use_docker){
msg_printf(NULL, MSG_INFO, "Config: don't use the Docker");
}
if (dont_use_docker_compose){
msg_printf(NULL, MSG_INFO, "Config: don't use the Docker compose");
}
for (i=0; i<alt_platforms.size(); i++) {
msg_printf(NULL, MSG_INFO,
"Config: alternate platform: %s", alt_platforms[i].c_str()
Expand Down Expand Up @@ -367,6 +373,8 @@ int CC_CONFIG::parse_options_client(XML_PARSER& xp) {
if (xp.parse_bool("dont_suspend_nci", dont_suspend_nci)) continue;
if (xp.parse_bool("dont_use_vbox", dont_use_vbox)) continue;
if (xp.parse_bool("dont_use_wsl", dont_use_wsl)) continue;
if (xp.parse_bool("dont_use_docker", dont_use_docker)) continue;
if (xp.parse_bool("dont_use_docker_compose", dont_use_docker_compose)) continue;
if (xp.match_tag("exclude_gpu")) {
EXCLUDE_GPU eg;
retval = eg.parse(xp);
Expand Down
4 changes: 4 additions & 0 deletions db/boinc_db_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,10 @@ struct HOST {
bool wsl_available;
WSLS wsls;

//Docker available
bool docker_use;
char docker_compose_version[256];

// stuff from time_stats
double cpu_and_network_available_frac;
double client_start_time;
Expand Down
12 changes: 10 additions & 2 deletions lib/cc_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@
dont_suspend_nci = false;
dont_use_vbox = false;
dont_use_wsl = false;
dont_use_docker = false;
dont_use_docker_compose = false;

Check warning on line 219 in lib/cc_config.cpp

View check run for this annotation

Codecov / codecov/patch

lib/cc_config.cpp#L218-L219

Added lines #L218 - L219 were not covered by tests
exclude_gpus.clear();
exclusive_apps.clear();
exclusive_gpu_apps.clear();
Expand Down Expand Up @@ -346,6 +348,8 @@
if (xp.parse_bool("lower_client_priority", lower_client_priority)) continue;
if (xp.parse_bool("dont_suspend_nci", dont_suspend_nci)) continue;
if (xp.parse_bool("dont_use_vbox", dont_use_vbox)) continue;
if (xp.parse_bool("dont_use_docker", dont_use_docker)) continue;
if (xp.parse_bool("dont_use_docker_compose", dont_use_docker_compose)) continue;
if (xp.parse_bool("dont_use_wsl", dont_use_wsl)) continue;
if (xp.match_tag("exclude_gpu")) {
EXCLUDE_GPU eg;
Expand Down Expand Up @@ -559,14 +563,18 @@
" <lower_client_priority>%d</lower_client_priority>\n"
" <dont_suspend_nci>%d</dont_suspend_nci>\n"
" <dont_use_vbox>%d</dont_use_vbox>\n"
" <dont_use_wsl>%d</dont_use_wsl>\n",
" <dont_use_wsl>%d</dont_use_wsl>\n"
" <dont_use_docker>%d</dont_use_docker>\n"
" <dont_use_docker_compose>%d</dont_use_docker_compose>\n",
disallow_attach,
dont_check_file_sizes,
dont_contact_ref_site,
lower_client_priority,
dont_suspend_nci,
dont_use_vbox,
dont_use_wsl
dont_use_wsl,
dont_use_docker,
dont_use_docker_compose

Check warning on line 577 in lib/cc_config.cpp

View check run for this annotation

Codecov / codecov/patch

lib/cc_config.cpp#L575-L577

Added lines #L575 - L577 were not covered by tests
);

for (i=0; i<exclude_gpus.size(); i++) {
Expand Down
2 changes: 2 additions & 0 deletions lib/cc_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ struct CC_CONFIG {
bool dont_suspend_nci;
bool dont_use_vbox;
bool dont_use_wsl;
bool dont_use_docker;
bool dont_use_docker_compose;
std::vector<EXCLUDE_GPU> exclude_gpus;
std::vector<std::string> exclusive_apps;
std::vector<std::string> exclusive_gpu_apps;
Expand Down