mirror of
https://github.com/microsoft/WSL.git
synced 2026-06-01 01:49:36 -05:00
wslc: add Config (env, cmd, entrypoint, user, workdir) to container inspect output (#40403)
This commit is contained in:
@@ -260,8 +260,13 @@ struct ContainerInspectState
|
||||
struct ContainerConfig
|
||||
{
|
||||
std::string Image;
|
||||
std::string User;
|
||||
std::string WorkingDir;
|
||||
std::optional<std::vector<std::string>> Env;
|
||||
std::optional<std::vector<std::string>> Cmd;
|
||||
std::optional<std::vector<std::string>> Entrypoint;
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(ContainerConfig, Image);
|
||||
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(ContainerConfig, Image, User, WorkingDir, Env, Cmd, Entrypoint);
|
||||
};
|
||||
|
||||
struct InspectMount
|
||||
|
||||
@@ -56,6 +56,17 @@ struct InspectHostConfig
|
||||
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(InspectHostConfig, NetworkMode);
|
||||
};
|
||||
|
||||
struct InspectContainerConfig
|
||||
{
|
||||
std::optional<std::vector<std::string>> Env;
|
||||
std::optional<std::vector<std::string>> Cmd;
|
||||
std::optional<std::vector<std::string>> Entrypoint;
|
||||
std::string User;
|
||||
std::string WorkingDir;
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(InspectContainerConfig, Env, Cmd, Entrypoint, User, WorkingDir);
|
||||
};
|
||||
|
||||
struct InspectContainer
|
||||
{
|
||||
std::string Id;
|
||||
@@ -64,11 +75,12 @@ struct InspectContainer
|
||||
std::string Image;
|
||||
InspectState State;
|
||||
InspectHostConfig HostConfig;
|
||||
InspectContainerConfig Config;
|
||||
std::map<std::string, std::vector<InspectPortBinding>> Ports;
|
||||
std::vector<InspectMount> Mounts;
|
||||
std::map<std::string, std::string> Labels;
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(InspectContainer, Id, Name, Created, Image, State, HostConfig, Ports, Mounts, Labels);
|
||||
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(InspectContainer, Id, Name, Created, Image, State, HostConfig, Config, Ports, Mounts, Labels);
|
||||
};
|
||||
|
||||
struct ImageConfig
|
||||
|
||||
@@ -1139,6 +1139,12 @@ WslcInspectContainer WSLCContainerImpl::BuildInspectContainer(const DockerInspec
|
||||
|
||||
wslcInspect.HostConfig.NetworkMode = dockerInspect.HostConfig.NetworkMode;
|
||||
|
||||
wslcInspect.Config.Env = dockerInspect.Config.Env;
|
||||
wslcInspect.Config.Cmd = dockerInspect.Config.Cmd;
|
||||
wslcInspect.Config.Entrypoint = dockerInspect.Config.Entrypoint;
|
||||
wslcInspect.Config.User = dockerInspect.Config.User;
|
||||
wslcInspect.Config.WorkingDir = dockerInspect.Config.WorkingDir;
|
||||
|
||||
// Map WSLC port mappings (Windows host ports only). HostIp is not set here and will use
|
||||
// the default value ("127.0.0.1") defined in the InspectPortBinding schema.
|
||||
for (const auto& e : m_mappedPorts)
|
||||
|
||||
@@ -5766,6 +5766,37 @@ class WSLCTests
|
||||
|
||||
VERIFY_SUCCEEDED(container.Get().Delete(WSLCDeleteFlagsNone));
|
||||
}
|
||||
|
||||
// Test that Config fields are populated in inspect output.
|
||||
{
|
||||
const std::string envVar = "WSLC_TEST_VAR=hello";
|
||||
const std::string workDir = "/tmp";
|
||||
|
||||
WSLCContainerLauncher launcher("debian:latest", "test-container-inspect-config", {"99999"}, {envVar});
|
||||
launcher.SetEntrypoint({"sleep"});
|
||||
launcher.SetWorkingDirectory(std::string{workDir});
|
||||
launcher.SetUser("nobody");
|
||||
|
||||
auto container = launcher.Launch(*m_defaultSession);
|
||||
auto details = container.Inspect();
|
||||
|
||||
const auto& config = details.Config;
|
||||
|
||||
VERIFY_IS_TRUE(config.Env.has_value());
|
||||
VERIFY_IS_TRUE(std::ranges::find(*config.Env, envVar) != config.Env->end());
|
||||
|
||||
VERIFY_ARE_EQUAL(config.WorkingDir, workDir);
|
||||
|
||||
VERIFY_IS_TRUE(config.Cmd.has_value());
|
||||
VERIFY_ARE_EQUAL(1u, config.Cmd->size());
|
||||
VERIFY_ARE_EQUAL(config.Cmd->at(0), std::string{"99999"});
|
||||
|
||||
VERIFY_IS_TRUE(config.Entrypoint.has_value());
|
||||
VERIFY_ARE_EQUAL(1u, config.Entrypoint->size());
|
||||
VERIFY_ARE_EQUAL(config.Entrypoint->at(0), std::string{"sleep"});
|
||||
|
||||
VERIFY_ARE_EQUAL(config.User, std::string{"nobody"});
|
||||
}
|
||||
}
|
||||
|
||||
WSLC_TEST_METHOD(Exec)
|
||||
|
||||
Reference in New Issue
Block a user