Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions libs/linglong/src/linglong/cli/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,13 +669,14 @@ int Cli::run(const RunOptions &options)
LogD("RunContext Config:\n{}", nlohmann::json(runContextCfg).dump());

auto containerID = runContext.getContainerId();
LogD("run app: {} container id: {}", curAppRef->toString(), containerID);
LogD("run {} with container id: {}", curAppRef->toString(), containerID);

const auto &appLayerItem = runContext.getCachedAppItem();
if (!appLayerItem) {
auto targetItem = runContext.getCachedTargetItem();
if (!targetItem) {
this->printer.printErr(LINGLONG_ERRV("failed to get cached target item", targetItem));
return -1;
}
Comment thread
reddevillg marked this conversation as resolved.
const auto &info = appLayerItem->info;
const auto &info = targetItem->info;

auto commands = options.commands;
if (options.commands.empty()) {
Expand Down Expand Up @@ -831,20 +832,20 @@ int Cli::runResolvedContext(runtime::RunContext &runContext,
{
LINGLONG_TRACE("run resolved context");

auto appLayerItem = runContext.getCachedAppItem();
if (!appLayerItem) {
this->printer.printErr(LINGLONG_ERRV("failed to get cached app item"));
auto targetItem = runContext.getCachedTargetItem();
if (!targetItem) {
this->printer.printErr(LINGLONG_ERRV("failed to get cached target item", targetItem));
return -1;
}
Comment thread
reddevillg marked this conversation as resolved.

auto commands = options.commands;
if (options.commands.empty()) {
commands = appLayerItem->info.command.value_or(std::vector<std::string>{ "bash" });
commands = targetItem->info.command.value_or(std::vector<std::string>{ "bash" });
}
commands = filePathMapping(commands, options);

auto appCache =
common::dir::getContainerCacheDir(appLayerItem->commit, runContext.getContainerId());
common::dir::getContainerCacheDir(targetItem->commit, runContext.getContainerId());

runtime::RunContainerOptions runOptions;
runOptions.enableSecurityContext(runtime::getDefaultSecurityContexts());
Expand Down Expand Up @@ -991,7 +992,9 @@ Cli::getCurrentContainers() const noexcept

myContainers.emplace_back(api::types::v1::CliContainer{
.id = std::move(info->containerID),
.package = std::move(info->app),
.package = !info->app.empty()
? info->app
: (info->runtime && !info->runtime->empty() ? *info->runtime : info->base),
.pid = container->pid,
});
}
Expand Down Expand Up @@ -2089,12 +2092,12 @@ utils::error::Result<std::filesystem::path> Cli::ensureCache(runtime::RunContext
LINGLONG_TRACE("ensure cache via PM");

const auto &containerID = context.getContainerId();
auto appLayerItem = context.getCachedAppItem();
if (!appLayerItem) {
return LINGLONG_ERR("failed to get cached app item");
auto targetItem = context.getCachedTargetItem();
if (!targetItem) {
return LINGLONG_ERR("failed to get cached target item", targetItem);
}
Comment thread
reddevillg marked this conversation as resolved.

auto appCache = common::dir::getContainerCacheDir(appLayerItem->commit, containerID);
auto appCache = common::dir::getContainerCacheDir(targetItem->commit, containerID);
auto runContextConfigFile = appCache / ".config";
std::error_code ec;
if (std::filesystem::exists(runContextConfigFile, ec)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1937,12 +1937,12 @@ utils::error::Result<void> PackageManager::initRunContext(const std::string &run
return LINGLONG_ERR("container id mismatch");
}

auto appLayerItem = ctx.getCachedAppItem();
if (!appLayerItem) {
return LINGLONG_ERR("failed to get cached app item");
auto targetItem = ctx.getCachedTargetItem();
if (!targetItem) {
return LINGLONG_ERR("failed to get cached target item", targetItem);
}
Comment thread
reddevillg marked this conversation as resolved.

auto appCache = common::dir::getContainerCacheDir(appLayerItem->commit, containerID);
auto appCache = common::dir::getContainerCacheDir(targetItem->commit, containerID);
auto runContextConfigFile = appCache / ".config";
std::error_code ec;
if (std::filesystem::exists(runContextConfigFile, ec)) {
Expand Down
8 changes: 4 additions & 4 deletions libs/linglong/src/linglong/runtime/container_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,12 @@ auto ContainerBuilder::finalizeContainer(PreparedContainer &prepared) noexcept
bool useOverlayMode = true;
bool needGenLdConf = false;
if (prepared.mode == ContainerMode::Init) {
const auto &appLayer = prepared.runContext->getAppLayer();
if (!appLayer) {
return LINGLONG_ERR("app layer not found");
auto targetLayer = prepared.runContext->getTargetLayer();
if (!targetLayer) {
return LINGLONG_ERR("target layer not found", targetLayer);
}
Comment thread
reddevillg marked this conversation as resolved.

triplet = appLayer->getReference().arch.getTriplet();
triplet = targetLayer->get().getReference().arch.getTriplet();
needGenLdConf = true;
} else if (prepared.mode == ContainerMode::Build) {
triplet = package::Architecture::currentCPUArchitecture().getTriplet();
Expand Down
37 changes: 31 additions & 6 deletions libs/linglong/src/linglong/runtime/run_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,10 @@ utils::error::Result<void> RunContext::resolve(const api::types::v1::RunContextC

return std::move(layer).value();
};
auto findTargetLayer = [this, &_linglong_trace_message](const std::string &targetRefStr)
auto findTargetLayer = [this](const std::string &targetRefStr)
-> utils::error::Result<std::reference_wrapper<RuntimeLayer>> {
LINGLONG_TRACE("find target layer");

auto fuzzyRef = package::FuzzyReference::parse(targetRefStr);
if (!fuzzyRef) {
return LINGLONG_ERR("failed to parse target layer reference", fuzzyRef);
Expand Down Expand Up @@ -1021,15 +1023,38 @@ utils::error::Result<std::filesystem::path> RunContext::getRuntimeLayerPath() co
return runtimeLayer->getLayerDir()->path();
}

utils::error::Result<api::types::v1::RepositoryCacheLayersItem> RunContext::getCachedAppItem()
utils::error::Result<std::reference_wrapper<RuntimeLayer>> RunContext::getTargetLayer()
{
LINGLONG_TRACE("get cached app item");
LINGLONG_TRACE("get target layer");

if (!appLayer) {
return LINGLONG_ERR("no app layer exist");
if (appLayer) {
return std::ref(*appLayer);
}
if (runtimeLayer) {
return std::ref(*runtimeLayer);
}
if (baseLayer) {
return std::ref(*baseLayer);
}

return LINGLONG_ERR("no layer resolved");
}

utils::error::Result<api::types::v1::RepositoryCacheLayersItem> RunContext::getCachedTargetItem()
{
LINGLONG_TRACE("get cached target item");

if (appLayer) {
return appLayer->getCachedItem();
}
if (runtimeLayer) {
return runtimeLayer->getCachedItem();
}
if (baseLayer) {
return baseLayer->getCachedItem();
}

return appLayer->getCachedItem();
return LINGLONG_ERR("no layer resolved");
}

} // namespace linglong::runtime
6 changes: 5 additions & 1 deletion libs/linglong/src/linglong/runtime/run_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "ocppi/runtime/config/types/Generators.hpp"

#include <filesystem>
#include <functional>

namespace linglong::generator {
class ContainerCfgBuilder;
Expand Down Expand Up @@ -85,7 +86,10 @@ class RunContext
[[nodiscard]] utils::error::Result<std::filesystem::path> getBaseLayerPath() const;
[[nodiscard]] utils::error::Result<std::filesystem::path> getRuntimeLayerPath() const;

utils::error::Result<api::types::v1::RepositoryCacheLayersItem> getCachedAppItem();
[[nodiscard]] utils::error::Result<std::reference_wrapper<RuntimeLayer>> getTargetLayer();

[[nodiscard]] utils::error::Result<api::types::v1::RepositoryCacheLayersItem>
getCachedTargetItem();

[[nodiscard]] bool hasRuntime() const noexcept { return !!runtimeLayer; }

Expand Down
Loading