forked from microsoft/WSL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWSLCLocalRegistry.cpp
More file actions
90 lines (68 loc) · 2.04 KB
/
WSLCLocalRegistry.cpp
File metadata and controls
90 lines (68 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*++
Copyright (c) Microsoft. All rights reserved.
Module Name:
WSLCLocalRegistry.cpp
Abstract:
Implementation of WSLCLocalRegistry.
--*/
#include "WSLCLocalRegistry.h"
using wsl::windows::common::RunningWSLCContainer;
using wsl::windows::common::WSLCContainerLauncher;
using wsl::windows::common::WSLCLocalRegistry;
namespace {
constexpr auto c_registryImage = "wslc-registry:latest";
std::vector<std::string> BuildRegistryEnv(const std::string& username, const std::string& password)
{
std::vector<std::string> env = {
"REGISTRY_HTTP_ADDR=0.0.0.0:5000",
};
if (!username.empty())
{
env.push_back(std::format("USERNAME={}", username));
env.push_back(std::format("PASSWORD={}", password));
}
return env;
}
} // namespace
WSLCLocalRegistry::WSLCLocalRegistry(
IWSLCSession& session,
RunningWSLCContainer&& container,
std::string&& username,
std::string&& password) :
m_session(wil::com_ptr<IWSLCSession>(&session)),
m_username(std::move(username)),
m_password(std::move(password)),
m_container(std::move(container))
{
}
WSLCLocalRegistry::~WSLCLocalRegistry()
{
// Delete the container first while the session is still active.
m_container.Reset();
}
WSLCLocalRegistry WSLCLocalRegistry::Start(
IWSLCSession& session, const std::string& username, const std::string& password)
{
auto env = BuildRegistryEnv(username, password);
WSLCContainerLauncher launcher(c_registryImage, {}, {}, env);
launcher.SetEntrypoint({"/entrypoint.sh"});
launcher.AddPort(5000, 5000, AF_INET);
auto container = launcher.Launch(session, WSLCContainerStartFlagsNone);
return WSLCLocalRegistry(
session,
std::move(container),
std::string(username),
std::string(password));
}
const char* WSLCLocalRegistry::GetServerAddress() const
{
return "127.0.0.1:5000";
}
const std::string& WSLCLocalRegistry::GetUsername() const
{
return m_username;
}
const std::string& WSLCLocalRegistry::GetPassword() const
{
return m_password;
}