Skip to content

Commit

Permalink
aklite-apps: Remove the register command
Browse files Browse the repository at this point in the history
Since the docker engine has been patched with functionality that
registers images at the end of image loading process the
dedicated/separate `register` command becomes redundant.

Signed-off-by: Mike Sul <[email protected]>
  • Loading branch information
mike-sul committed Dec 6, 2023
1 parent f1cd0e5 commit 9cdeb4c
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 81 deletions.
48 changes: 0 additions & 48 deletions apps/aklite-apps/cmds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,54 +106,6 @@ int ListCmd::listApps(const std::string& store_root, bool wide) {
return EXIT_SUCCESS;
}

int RegisterCmd::hackDockerStore(const std::vector<std::string>& shortlist, const std::string& store_root,
const std::string& docker_root) {
LOG_INFO << "Registering the preloaded Apps at the docker store repository;"
<< "\n\tshortlist: " << boost::algorithm::join(shortlist, ",") << "\n\tstore-root: " << store_root
<< "\n\tdocker-root: " << docker_root;

const auto apps{getStoreApps(store_root, shortlist)};
if (apps.size() == 0) {
LOG_INFO << "No Apps found in the store; path: " << store_root;
exit(EXIT_SUCCESS);
}

const fs::path repositories_file{docker_root + "/image/overlay2/repositories.json"};
Json::Value repositories;
if (fs::exists(repositories_file)) {
repositories = Utils::parseJSONFile(repositories_file.string());
} else {
repositories = Utils::parseJSON("{\"Repositories\":{}}");
}

for (const auto& app : apps) {
const fs::path app_compose_file{app.path / Docker::RestorableAppEngine::ComposeFile};
const Docker::ComposeInfo app_compose{app_compose_file.string()};
for (const Json::Value& service : app_compose.getServices()) {
const auto image_uri_str{app_compose.getImage(service)};
const auto image_uri{Docker::Uri::parseUri(image_uri_str, false)};

const auto image_index_path{app.path / "images" / image_uri.registryHostname / image_uri.repo /
image_uri.digest.hash() / "index.json"};
const auto image_index{Utils::parseJSONFile(image_index_path.string())};

// parse an image index to find a path to an image manifest
const Docker::HashedDigest manifest_digest(image_index["manifests"][0]["digest"].asString());
const auto image_manifest_path{store_root + "/blobs/sha256/" + manifest_digest.hash()};
const auto image_manifest{Utils::parseJSONFile(image_manifest_path)};
// parse an image manifest to get a digest of an image config
const Docker::HashedDigest config_digest(image_manifest["config"]["digest"].asString());
const auto image_repo{image_uri.registryHostname + "/" + image_uri.repo};

LOG_INFO << "Registering image: " << image_uri_str << " -> " << config_digest();
repositories["Repositories"][image_repo][image_uri_str] = config_digest();
}
}

Utils::writeFile(repositories_file.string(), repositories);
return EXIT_SUCCESS;
}

int RunCmd::runApps(const std::vector<std::string>& shortlist, const std::string& docker_host,
const std::string& store_root, const std::string& compose_root, const std::string& docker_root,
const std::string& client, const std::string& compose_client) {
Expand Down
32 changes: 0 additions & 32 deletions apps/aklite-apps/cmds.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,38 +53,6 @@ class ListCmd : public Cmd {
po::options_description _options;
};

class RegisterCmd : public Cmd {
public:
RegisterCmd() : Cmd("register", _options) {
_options.add_options()("help,h", "print usage")("log-level", po::value<int>()->default_value(2),
"set log level 0-5 (trace, debug, info, warning, error, fatal)")(
"apps", po::value<std::string>()->default_value(""),
"Comma separated list of Apps to register, by default all Apps are registered")(
"store-root", po::value<std::string>()->default_value("/var/sota/reset-apps"), "Image store root folder")(
"docker-root", po::value<std::string>()->default_value("/var/lib/docker"), "Docker data root folder");
}

int operator()(const po::variables_map& vm) const override {
try {
std::vector<std::string> apps;
if (!vm["apps"].as<std::string>().empty()) {
boost::split(apps, vm["apps"].as<std::string>(), boost::is_any_of(", "), boost::token_compress_on);
}

return hackDockerStore(apps, vm["store-root"].as<std::string>(), vm["docker-root"].as<std::string>());
} catch (const std::exception& exc) {
LOG_ERROR << "Failed to register preloaded Apps's images: " << exc.what();
return EXIT_FAILURE;
}
}

private:
static int hackDockerStore(const std::vector<std::string>& shortlist, const std::string& store_root,
const std::string& docker_root);

po::options_description _options;
};

class RunCmd : public Cmd {
public:
RunCmd() : Cmd("run", _options) {
Expand Down
1 change: 0 additions & 1 deletion apps/aklite-apps/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ namespace po = boost::program_options;
static std::vector<apps::aklite_apps::Cmd::Ptr> cmds{
std::make_shared<apps::aklite_apps::ListCmd>(),
std::make_shared<apps::aklite_apps::RunCmd>(),
std::make_shared<apps::aklite_apps::RegisterCmd>(),
};

static void print_usage() {
Expand Down

0 comments on commit 9cdeb4c

Please sign in to comment.