-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial stab at adding image list functionality
- Loading branch information
1 parent
be64521
commit 83fc2b2
Showing
16 changed files
with
225 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#pragma once | ||
|
||
#include <boost/process/child.hpp> | ||
#include <boost/process/async_pipe.hpp> | ||
#include <boost/process/group.hpp> | ||
#include <boost/process/io.hpp> | ||
#include <boost/asio/io_context.hpp> | ||
#include <boost/asio/read.hpp> | ||
#include <boost/asio/streambuf.hpp> | ||
#include "Logger.h" | ||
|
||
namespace asio = boost::asio; | ||
namespace bp = boost::process; | ||
|
||
class Docker : public std::enable_shared_from_this<Docker> { | ||
public: | ||
explicit Docker(asio::io_context &io_context) : io_context(io_context), output_pipe(io_context) {} | ||
|
||
// Request to get a list of docker builders | ||
// The handler must have the form void(std::error_code error, std::string image_list) | ||
template<typename ListHandler> | ||
void request_image_list(ListHandler handler) { | ||
std::string list_command("/usr/local/bin/list-images.sh"); | ||
|
||
Logger::info("Launching command: " + list_command); | ||
|
||
std::error_code list_error; | ||
process = bp::child(list_command, bp::std_in.close(), (bp::std_out & bp::std_err) > output_pipe, group, | ||
list_error); | ||
if (list_error) { | ||
auto error = std::error_code(list_error.value(), std::generic_category()); | ||
Logger::error("Error requesting image list: " + list_error.message()); | ||
io_context.post(std::bind(handler, error, std::string("image list error"))); | ||
} | ||
|
||
// Read the list-images command output until we reach EOF, which is returned as an error | ||
auto self(shared_from_this()); | ||
asio::async_read(output_pipe, output_buffer, | ||
[this, self, handler](boost::system::error_code error, std::size_t) { | ||
if (error != asio::error::eof) { | ||
auto read_error = std::error_code(error.value(), std::generic_category()); | ||
Logger::error("Error reading image list output: " + read_error.message()); | ||
std::string no_list("Error reading image list output"); | ||
io_context.post(std::bind(handler, read_error, no_list)); | ||
} else { | ||
// Complete the handler | ||
std::string image_list((std::istreambuf_iterator<char>(&output_buffer)), std::istreambuf_iterator<char>()); | ||
io_context.post(std::bind(handler, std::error_code(), image_list)); | ||
Logger::info("image list posted"); | ||
} | ||
}); | ||
} | ||
|
||
private: | ||
asio::io_context &io_context; | ||
bp::child process; | ||
bp::group group; | ||
bp::async_pipe output_pipe; | ||
asio::streambuf output_buffer; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
|
||
/usr/local/bin/docker-ls tags --progress-indicator=false --user ${DOCKERHUB_READONLY_USERNAME} --password ${DOCKERHUB_READONLY_TOKEN} olcf/titan | ||
|
||
/usr/local/bin/docker-ls tags --progress-indicator=false --user ${DOCKERHUB_READONLY_USERNAME} --password ${DOCKERHUB_READONLY_TOKEN} olcf/summitdev | ||
|
||
/usr/local/bin/docker-ls tags --progress-indicator=false --user ${DOCKERHUB_READONLY_USERNAME} --password ${DOCKERHUB_READONLY_TOKEN} olcf/summit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#include <fstream> | ||
#include <boost/asio/io_context.hpp> | ||
#include <boost/asio/ip/tcp.hpp> | ||
#include <boost/asio/connect.hpp> | ||
#include <boost/filesystem.hpp> | ||
#include <boost/beast/core/error.hpp> | ||
#include <boost/beast/websocket.hpp> | ||
#include <boost/exception/all.hpp> | ||
#include <boost/program_options.hpp> | ||
#include <regex> | ||
#include <csignal> | ||
#include "ClientData.h" | ||
#include "WaitingAnimation.h" | ||
#include "pwd.h" | ||
|
||
namespace asio = boost::asio; | ||
using asio::ip::tcp; | ||
namespace beast = boost::beast; | ||
namespace websocket = beast::websocket; | ||
|
||
void parse_environment(ClientData &client_data) { | ||
Logger::debug("Parsing environment variables"); | ||
|
||
struct passwd *pws; | ||
pws = getpwuid(getuid()); | ||
if (pws == NULL) { | ||
throw std::runtime_error("Error get login name for client data!"); | ||
} | ||
client_data.user_id = std::string(pws->pw_name); | ||
|
||
auto host = std::getenv("QUEUE_HOST"); | ||
if (!host) { | ||
throw std::runtime_error("QUEUE_HOST not set!"); | ||
} | ||
client_data.queue_host = std::string(host); | ||
} | ||
|
||
void print_images(websocket::stream<tcp::socket> &queue_stream) { | ||
Logger::debug("Writing image list request string"); | ||
std::string request_string("image_list_request"); | ||
queue_stream.write(asio::buffer(request_string)); | ||
|
||
Logger::debug("Read image list string"); | ||
std::string images_string; | ||
auto images_buffer = boost::asio::dynamic_buffer(images_string); | ||
queue_stream.read(images_buffer); | ||
|
||
std::cout << images_string; | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
asio::io_context io_context; | ||
websocket::stream<tcp::socket> queue_stream(io_context); | ||
|
||
try { | ||
ClientData client_data; | ||
|
||
parse_environment(client_data); | ||
|
||
WaitingAnimation wait_queue("Connecting to BuilderQueue"); | ||
// Open a WebSocket stream to the queue | ||
tcp::resolver queue_resolver(io_context); | ||
asio::connect(queue_stream.next_layer(), queue_resolver.resolve({client_data.queue_host, "8080"})); | ||
queue_stream.handshake(client_data.queue_host + ":8080", "/"); | ||
wait_queue.stop_success("Connected to queue: " + client_data.queue_host); | ||
|
||
// Request a build host from the queue | ||
WaitingAnimation wait_builder("Requesting image list"); | ||
print_images(queue_stream); | ||
|
||
} catch (const boost::exception &ex) { | ||
auto diagnostics = diagnostic_information(ex); | ||
Logger::error(std::string() + "Container Builder exception encountered: " + diagnostics); | ||
} catch (const std::exception &ex) { | ||
Logger::error(std::string() + "Container Builder exception encountered: " + ex.what()); | ||
} catch (...) { | ||
Logger::error("Unknown exception caught!"); | ||
} | ||
|
||
// Attempt to disconnect from builder and queue | ||
try { | ||
Logger::debug("Attempting normal close"); | ||
queue_stream.close(websocket::close_code::normal); | ||
} catch (...) { | ||
Logger::debug("Failed to cleanly close the WebSockets"); | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.