Skip to content

Commit

Permalink
apps: App fetch and install using CLI utility
Browse files Browse the repository at this point in the history
Add implementation of the app fetching and installation methods that
make use of the `composectl` utility to perform their action.

Signed-off-by: Mike Sul <[email protected]>
  • Loading branch information
mike-sul committed Dec 5, 2023
1 parent a305c35 commit 2d5613a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/composeappmanager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ ComposeAppManager::ComposeAppManager(const PackageConfig& pconfig, const Bootloa
app_engine_ = std::make_shared<ctr::AppEngine>(
cfg_.reset_apps_root, cfg_.apps_root, cfg_.images_data_root, registry_client,
std::make_shared<Docker::DockerClient>(), skopeo_cmd, docker_host, compose_cmd, composectl_cmd,
Docker::RestorableAppEngine::GetDefStorageSpaceFunc(cfg_.storage_watermark));
cfg_.storage_watermark, Docker::RestorableAppEngine::GetDefStorageSpaceFunc(cfg_.storage_watermark));
#else
app_engine_ = std::make_shared<Docker::RestorableAppEngine>(
cfg_.reset_apps_root, cfg_.apps_root, cfg_.images_data_root, registry_client,
Expand Down
9 changes: 8 additions & 1 deletion src/ctr/appengine.cc
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
#include "appengine.h"

#include <boost/format.hpp>
#include <boost/process.hpp>

#include "exec.h"

namespace ctr {
AppEngine::Result AppEngine::fetch(const App& app) {
// TODO
exec(boost::format{"%s --store %s pull %s --storage-usage-watermark %d"} % composectl_cmd_ % storeRoot() % app.uri % storage_watermark_, "failed to pull compose app");
return true;
}
void AppEngine::installAppAndImages(const App& app) {
exec(boost::format{"%s --store %s install --compose-dir %s --docker-host %s %s"} % composectl_cmd_ % storeRoot() % installRoot() % dockerHost() % app.uri, "failed to installl compose app");
}

} // namespace ctr
7 changes: 5 additions & 2 deletions src/ctr/appengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,21 @@ class AppEngine : public Docker::RestorableAppEngine {
boost::filesystem::path store_root, boost::filesystem::path install_root, boost::filesystem::path docker_root,
Docker::RegistryClient::Ptr registry_client, Docker::DockerClient::Ptr docker_client,
std::string client = "/sbin/skopeo", std::string docker_host = "unix:///var/run/docker.sock",
std::string compose_cmd = "/usr/bin/docker-compose", std::string composectl_cmd = "/usr/bin/composectl",
std::string compose_cmd = "/usr/bin/docker-compose", std::string composectl_cmd = "/usr/bin/composectl", int storage_watermark = 80,
StorageSpaceFunc storage_space_func = RestorableAppEngine::GetDefStorageSpaceFunc(),
ClientImageSrcFunc client_image_src_func = [](const Docker::Uri& /* app_uri */,
const std::string& image_uri) { return "docker://" + image_uri; },
bool create_containers_if_install = true, bool offline = false):
Docker::RestorableAppEngine(store_root, install_root, docker_root, registry_client, docker_client, client, docker_host, compose_cmd, storage_space_func, client_image_src_func), composectl_cmd_{composectl_cmd} {}
Docker::RestorableAppEngine(store_root, install_root, docker_root, registry_client, docker_client, client, docker_host, compose_cmd, storage_space_func, client_image_src_func), composectl_cmd_{composectl_cmd}, storage_watermark_{storage_watermark} {}


Result fetch(const App& app) override;
private:
void installAppAndImages(const App& app) override;

private:
const std::string composectl_cmd_;
const int storage_watermark_;
};

} // namespace ctr
Expand Down
8 changes: 7 additions & 1 deletion src/docker/restorableappengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ class RestorableAppEngine : public AppEngine {
static bool areDockerAndSkopeoOnTheSameVolume(const boost::filesystem::path& skopeo_path,
const boost::filesystem::path& docker_path);

protected:
const boost::filesystem::path& storeRoot() const { return store_root_; }
const boost::filesystem::path& installRoot() const { return install_root_; }
const std::string& dockerHost() const { return docker_host_; }

virtual void installAppAndImages(const App& app);

private:
class LoadImageException : public std::runtime_error {
public:
Expand All @@ -124,7 +131,6 @@ class RestorableAppEngine : public AppEngine {
// install App&Images
Result installAndCreateOrRunContainers(const App& app, bool run = false);
Result installContainerless(const App& app);
void installAppAndImages(const App& app);
static void installApp(const boost::filesystem::path& app_dir, const boost::filesystem::path& dst_dir);
void installAppImages(const boost::filesystem::path& app_dir);

Expand Down

0 comments on commit 2d5613a

Please sign in to comment.