forked from microsoft/WSL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker_schema.h
More file actions
483 lines (387 loc) · 11.9 KB
/
docker_schema.h
File metadata and controls
483 lines (387 loc) · 11.9 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
/*++
Copyright (c) Microsoft. All rights reserved.
Module Name:
docker_schema.h
Abstract:
JSON schema for the docker API.
The documentation for the API can be found at: https://docs.docker.com/reference/api/engine/version/v1.52/#tag/Container
--*/
#pragma once
#include "JsonUtils.h"
namespace wsl::windows::common::docker_schema {
struct CreatedContainer
{
std::string Id;
std::string Name;
std::vector<std::string> Warnings;
NLOHMANN_DEFINE_TYPE_INTRUSIVE(CreatedContainer, Id, Warnings);
};
struct ErrorResponse
{
std::string message;
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(ErrorResponse, message);
};
struct ImageLoadResult
{
std::optional<std::string> stream;
std::optional<ErrorResponse> errorDetail;
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(ImageLoadResult, stream, errorDetail);
};
struct EmptyRequest
{
using TResponse = void;
};
struct AuthRequest
{
using TResponse = struct AuthResponse;
std::string username;
std::string password;
std::string serveraddress;
NLOHMANN_DEFINE_TYPE_INTRUSIVE(AuthRequest, username, password, serveraddress);
};
struct AuthResponse
{
std::string Status;
std::optional<std::string> IdentityToken;
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(AuthResponse, Status, IdentityToken);
};
struct CreateVolume
{
using TResponse = void;
std::string Name;
std::string Driver;
std::map<std::string, std::string> DriverOpts;
std::map<std::string, std::string> Labels;
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(CreateVolume, Name, Driver, DriverOpts, Labels);
};
struct Volume
{
std::string Name;
std::string Driver;
std::string Mountpoint;
std::optional<std::map<std::string, std::string>> Options;
std::map<std::string, std::string> Labels;
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Volume, Name, Driver, Mountpoint, Options, Labels);
};
struct ListVolumesResponse
{
std::vector<Volume> Volumes;
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(ListVolumesResponse, Volumes);
};
struct EmptyObject
{
};
inline void to_json(nlohmann::json& j, const EmptyObject& memory)
{
UNREFERENCED_PARAMETER(memory);
j = nlohmann::json::object();
}
inline void from_json(const nlohmann::json& j, EmptyObject& obj)
{
// EmptyObject has no fields, so nothing to deserialize
UNREFERENCED_PARAMETER(j);
UNREFERENCED_PARAMETER(obj);
}
struct Mount
{
std::string Name;
std::string Source;
std::string Target;
std::string Type;
bool ReadOnly{};
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Mount, Name, Target, Source, Type, ReadOnly);
};
struct PortMapping
{
std::string HostIp;
std::string HostPort;
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(PortMapping, HostIp, HostPort);
};
struct HostConfig
{
std::vector<Mount> Mounts;
std::map<std::string, std::vector<PortMapping>> PortBindings;
std::string NetworkMode;
bool Init{};
std::optional<std::vector<std::string>> Dns;
std::optional<std::vector<std::string>> DnsSearch;
std::optional<std::vector<std::string>> DnsOptions;
std::optional<std::vector<std::string>> Binds;
std::map<std::string, std::string> Tmpfs;
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(HostConfig, Mounts, PortBindings, NetworkMode, Init, Dns, DnsSearch, DnsOptions, Binds, Tmpfs);
};
struct CreateContainer
{
using TResponse = CreatedContainer;
std::string Image;
bool Tty{};
bool OpenStdin{};
bool StdinOnce{};
bool AttachStdin{};
bool AttachStdout{};
bool AttachStderr{};
std::optional<std::string> User;
std::string Hostname;
std::string Domainname;
std::optional<std::string> StopSignal;
std::optional<std::string> WorkingDir;
std::optional<std::vector<std::string>> Cmd;
std::optional<std::vector<std::string>> Entrypoint;
std::vector<std::string> Env;
std::map<std::string, EmptyObject> ExposedPorts;
std::map<std::string, std::string> Labels;
HostConfig HostConfig;
NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE(
CreateContainer, Image, Cmd, Tty, OpenStdin, StdinOnce, Entrypoint, Env, ExposedPorts, HostConfig, StopSignal, WorkingDir, User, Hostname, Domainname, Labels);
};
struct ContainerInspectState
{
std::string Status;
bool Running{};
int ExitCode{};
std::string StartedAt;
std::string FinishedAt;
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(ContainerInspectState, Status, Running, ExitCode, StartedAt, FinishedAt);
};
struct ContainerConfig
{
std::string Image;
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(ContainerConfig, Image);
};
struct InspectMount
{
std::string Type;
std::string Source;
std::string Destination;
bool RW{};
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(InspectMount, Type, Source, Destination, RW);
};
struct InspectContainer
{
std::string Id;
std::string Name;
std::string Created;
std::string Image;
ContainerInspectState State;
ContainerConfig Config;
HostConfig HostConfig;
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(InspectContainer, Id, Name, Created, Image, State, Config, HostConfig);
};
struct InspectExec
{
std::optional<int> Pid{};
std::optional<int> ExitCode{};
bool Running{};
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(InspectExec, Pid, ExitCode, Running);
};
struct PruneContainerLabelFilter
{
std::map<std::string, bool> presentLabels;
std::map<std::string, bool> absentLabels;
std::optional<std::uint64_t> until;
};
inline void to_json(nlohmann::json& j, const PruneContainerLabelFilter& object)
{
j = nlohmann::json{};
if (!object.presentLabels.empty())
{
j["label"] = object.presentLabels;
}
if (!object.absentLabels.empty())
{
j["label!"] = object.absentLabels;
}
// This is required because docker crashes if 'until' is null.
// TODO: Open a PR to fix this directly in moby.
if (object.until.has_value())
{
j["until"] = nlohmann::json{{std::to_string(object.until.value()), true}};
}
}
struct PruneContainerResult
{
std::optional<std::vector<std::string>> ContainersDeleted; // Null if no containers were deleted.
uint64_t SpaceReclaimed{};
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(PruneContainerResult, ContainersDeleted, SpaceReclaimed);
};
struct Image
{
std::string Id;
std::vector<std::string> RepoTags;
std::vector<std::string> RepoDigests;
uint64_t Size{};
int64_t Created{};
std::string ParentId;
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Image, Id, RepoTags, RepoDigests, Size, Created, ParentId);
};
struct DeletedImage
{
std::string Untagged;
std::string Deleted;
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(DeletedImage, Untagged, Deleted);
};
struct ImportStatus
{
std::string status;
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(ImportStatus, status);
};
struct ImageConfig
{
std::string User;
std::optional<std::map<std::string, EmptyObject>> ExposedPorts;
std::optional<std::vector<std::string>> Env;
std::optional<std::vector<std::string>> Cmd;
std::optional<std::vector<std::string>> Entrypoint;
std::optional<std::map<std::string, EmptyObject>> Volumes;
std::string WorkingDir;
std::optional<std::map<std::string, std::string>> Labels;
std::string StopSignal;
std::optional<std::vector<std::string>> Shell;
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(ImageConfig, User, ExposedPorts, Env, Cmd, Entrypoint, Volumes, WorkingDir, Labels, StopSignal, Shell);
};
struct RootFS
{
std::string Type;
std::optional<std::vector<std::string>> Layers;
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(RootFS, Type, Layers);
};
struct GraphDriverData
{
std::string Name;
std::optional<std::map<std::string, std::string>> Data;
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(GraphDriverData, Name, Data);
};
struct InspectImage
{
std::string Id;
std::optional<std::vector<std::string>> RepoTags;
std::optional<std::vector<std::string>> RepoDigests;
std::string Parent;
std::string Comment;
std::string Created;
std::optional<ImageConfig> Config;
std::string Author;
std::string Architecture;
std::string Variant;
std::string Os;
std::string OsVersion;
uint64_t Size{};
std::optional<GraphDriverData> GraphDriver;
std::optional<RootFS> RootFS;
std::optional<std::map<std::string, std::string>> Metadata;
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(
InspectImage, Id, RepoTags, RepoDigests, Parent, Comment, Created, Config, Author, Architecture, Variant, Os, OsVersion, Size, GraphDriver, RootFS, Metadata);
};
struct CreateExecResponse
{
std::string Id;
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(CreateExecResponse, Id);
};
struct CreateExec
{
using TResponse = CreateExecResponse;
bool AttachStdin{};
bool AttachStdout{};
bool AttachStderr{};
bool Tty{};
std::vector<ULONG> ConsoleSize;
std::vector<std::string> Cmd;
std::vector<std::string> Env;
std::optional<std::string> User;
std::string WorkingDir;
std::optional<std::string> DetachKeys;
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(CreateExec, AttachStdin, AttachStdout, AttachStderr, Tty, ConsoleSize, Cmd, Env, WorkingDir, User, DetachKeys);
};
struct StartExec
{
using TResponse = void;
bool Tty{};
bool Detach{};
std::vector<ULONG> ConsoleSize;
NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE(StartExec, Tty, Detach, ConsoleSize);
};
enum class ContainerState
{
Created,
Running,
Paused,
Restarting,
Exited,
Removing,
Dead,
Unknown
};
NLOHMANN_JSON_SERIALIZE_ENUM(
ContainerState,
{
{ContainerState::Created, "created"},
{ContainerState::Running, "running"},
{ContainerState::Paused, "paused"},
{ContainerState::Restarting, "restarting"},
{ContainerState::Exited, "exited"},
{ContainerState::Removing, "removing"},
{ContainerState::Dead, "dead"},
});
struct Port
{
uint16_t PrivatePort{};
uint16_t PublicPort{};
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Port, PrivatePort, PublicPort);
};
struct ContainerInfo
{
std::string Id;
std::vector<std::string> Names;
std::string Image;
std::map<std::string, std::string> Labels;
std::vector<Port> Ports;
std::vector<Mount> Mounts;
ContainerState State{ContainerState::Unknown};
int64_t Created{};
HostConfig HostConfig;
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(ContainerInfo, Id, Names, Image, Labels, Ports, Mounts, State, Created, HostConfig);
};
struct BuildKitVertex
{
std::string digest;
std::string name;
std::string started;
std::string error;
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(BuildKitVertex, digest, name, started, error);
};
struct BuildKitStatus
{
std::string id;
std::string vertex;
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(BuildKitStatus, id, vertex);
};
struct BuildKitLog
{
std::string vertex;
std::string data; // base64-encoded output
int stream{}; // 1 = stdout, 2 = stderr
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(BuildKitLog, vertex, data, stream);
};
struct BuildKitSolveStatus
{
std::vector<BuildKitVertex> vertexes;
std::vector<BuildKitStatus> statuses;
std::vector<BuildKitLog> logs;
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(BuildKitSolveStatus, vertexes, statuses, logs);
};
struct CreateImageProgressDetails
{
uint64_t current{};
uint64_t total{};
std::string unit;
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(CreateImageProgressDetails, current, total, unit);
};
struct CreateImageProgress
{
std::string status;
std::string id;
std::optional<ErrorResponse> errorDetail;
CreateImageProgressDetails progressDetail;
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(CreateImageProgress, status, id, progressDetail, errorDetail);
};
} // namespace wsl::windows::common::docker_schema