forked from microsoft/WSL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWSLCContainerLauncher.h
More file actions
111 lines (92 loc) · 4 KB
/
WSLCContainerLauncher.h
File metadata and controls
111 lines (92 loc) · 4 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*++
Copyright (c) Microsoft. All rights reserved.
Module Name:
WSLCContainerLauncher.h
Abstract:
This file contains the definition for WSLCContainerLauncher.
--*/
#pragma once
#include "WSLCProcessLauncher.h"
#include "docker_schema.h"
#include "wslc_schema.h"
namespace wsl::windows::common {
class RunningWSLCContainer
{
public:
NON_COPYABLE(RunningWSLCContainer);
DEFAULT_MOVABLE(RunningWSLCContainer);
RunningWSLCContainer(wil::com_ptr<IWSLCContainer>&& Container, WSLCProcessFlags Flags);
~RunningWSLCContainer();
IWSLCContainer& Get();
WSLCContainerState State();
ClientRunningWSLCProcess GetInitProcess();
void SetDeleteOnClose(bool deleteOnClose);
void Reset();
wslc_schema::InspectContainer Inspect();
std::string Id();
std::string Name();
std::map<std::string, std::string> Labels();
private:
wil::com_ptr<IWSLCContainer> m_container;
WSLCProcessFlags m_flags;
bool m_deleteOnClose = true;
};
class WSLCContainerLauncher : private WSLCProcessLauncher
{
public:
NON_COPYABLE(WSLCContainerLauncher);
NON_MOVABLE(WSLCContainerLauncher);
WSLCContainerLauncher(
const std::string& Image,
const std::string& Name = "",
const std::vector<std::string>& Arguments = {},
const std::vector<std::string>& Environment = {},
WSLCContainerNetworkType containerNetworkType = WSLCContainerNetworkTypeHost,
WSLCProcessFlags Flags = WSLCProcessFlagsNone);
void AddVolume(const std::wstring& HostPath, const std::string& ContainerPath, bool ReadOnly);
void AddNamedVolume(const std::string& Name, const std::string& ContainerPath, bool ReadOnly);
void AddPort(uint16_t WindowsPort, uint16_t ContainerPort, int Family, int Protocol = IPPROTO_TCP, const std::optional<std::string>& BindingAddress = {});
void AddLabel(const std::string& Key, const std::string& Value);
void AddTmpfs(const std::string& ContainerPath, const std::string& Options);
std::pair<HRESULT, std::optional<RunningWSLCContainer>> CreateNoThrow(IWSLCSession& Session);
RunningWSLCContainer Create(IWSLCSession& Session);
RunningWSLCContainer Launch(IWSLCSession& Session, WSLCContainerStartFlags Flags = WSLCContainerStartFlagsAttach);
std::pair<HRESULT, std::optional<RunningWSLCContainer>> LaunchNoThrow(IWSLCSession& Session, WSLCContainerStartFlags Flags = WSLCContainerStartFlagsAttach);
void SetName(std::string&& Name);
void SetEntrypoint(std::vector<std::string>&& entrypoint);
void SetDefaultStopSignal(WSLCSignal Signal);
void SetContainerFlags(WSLCContainerFlags Flags);
void SetHostname(std::string&& Hostname);
void SetDomainname(std::string&& Domainame);
void SetDnsServers(std::vector<std::string>&& DnsServers);
void SetDnsSearchDomains(std::vector<std::string>&& DnsSearchDomains);
void SetDnsOptions(std::vector<std::string>&& DnsOptions);
using WSLCProcessLauncher::FormatResult;
using WSLCProcessLauncher::SetUser;
using WSLCProcessLauncher::SetWorkingDirectory;
private:
std::string m_image;
std::string m_name;
std::vector<WSLCPortMapping> m_ports;
std::vector<WSLCVolume> m_volumes;
std::vector<WSLCNamedVolume> m_namedVolumes;
std::deque<std::wstring> m_hostPaths;
std::deque<std::string> m_volumeNames;
std::deque<std::string> m_containerPaths;
WSLCContainerNetworkType m_containerNetworkType;
std::vector<std::string> m_entrypoint;
WSLCSignal m_stopSignal = WSLCSignalNone;
WSLCContainerFlags m_containerFlags = WSLCContainerFlagsNone;
std::string m_hostname;
std::string m_domainname;
std::vector<std::string> m_dnsServers;
std::vector<std::string> m_dnsSearchDomains;
std::vector<std::string> m_dnsOptions;
std::vector<WSLCLabel> m_labels;
std::deque<std::string> m_labelKeys;
std::deque<std::string> m_labelValues;
std::vector<WSLCTmpfsMount> m_tmpfsMounts;
std::deque<std::string> m_tmpfsContainerPaths;
std::deque<std::string> m_tmpfsOptions;
};
} // namespace wsl::windows::common