-
-
Notifications
You must be signed in to change notification settings - Fork 309
/
Copy pathIContainerBuilder`2.cs
457 lines (410 loc) · 21.2 KB
/
IContainerBuilder`2.cs
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
namespace DotNet.Testcontainers.Builders
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Docker.DotNet.Models;
using DotNet.Testcontainers.Configurations;
using DotNet.Testcontainers.Containers;
using DotNet.Testcontainers.Images;
using DotNet.Testcontainers.Networks;
using DotNet.Testcontainers.Volumes;
using JetBrains.Annotations;
/// <summary>
/// A fluent Docker container builder.
/// </summary>
/// <typeparam name="TBuilderEntity">The builder entity.</typeparam>
/// <typeparam name="TContainerEntity">The resource entity.</typeparam>
[PublicAPI]
public interface IContainerBuilder<out TBuilderEntity, out TContainerEntity> : IAbstractBuilder<TBuilderEntity, TContainerEntity, CreateContainerParameters>
{
/// <summary>
/// Sets the dependent container to resolve and start before starting this container configuration.
/// </summary>
/// <param name="container">The dependent container.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity DependsOn(IContainer container);
/// <summary>
/// Sets the dependent network to resolve and create before starting this container configuration.
/// </summary>
/// <param name="network">The dependent network.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity DependsOn(INetwork network);
/// <summary>
/// Sets the dependent volume to resolve and create before starting this container configuration.
/// </summary>
/// <param name="volume">The dependent volume.</param>
/// <param name="destination">An absolute path as destination in the container.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity DependsOn(IVolume volume, string destination);
/// <summary>
/// Sets the dependent volume to resolve and create before starting this container configuration.
/// </summary>
/// <param name="volume">The dependent volume.</param>
/// <param name="destination">An absolute path as destination in the container.</param>
/// <param name="accessMode">The volume access mode.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity DependsOn(IVolume volume, string destination, AccessMode accessMode);
/// <summary>
/// Sets an image for which to create the container.
/// </summary>
/// <param name="image">The image.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithImage(string image);
/// <summary>
/// Sets an image for which to create the container.
/// </summary>
/// <param name="image">The image.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithImage(IImage image);
/// <summary>
/// Sets the image pull policy.
/// </summary>
/// <param name="imagePullPolicy">The image pull policy.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithImagePullPolicy(Func<ImageInspectResponse, bool> imagePullPolicy);
/// <summary>
/// Sets the name.
/// </summary>
/// <param name="name">The name.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithName(string name);
/// <summary>
/// Sets the hostname.
/// </summary>
/// <param name="hostname">The hostname.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithHostname(string hostname);
/// <summary>
/// Sets the MAC address.
/// </summary>
/// <param name="macAddress">The MAC address.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithMacAddress(string macAddress);
/// <summary>
/// Sets the working directory.
/// </summary>
/// <param name="workingDirectory">The working directory.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithWorkingDirectory(string workingDirectory);
/// <summary>
/// Overrides the container's entrypoint executable.
/// </summary>
/// <param name="entrypoint">The entrypoint executable.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithEntrypoint(params string[] entrypoint);
/// <summary>
/// Overrides the container's command arguments.
/// </summary>
/// <param name="command">A list of commands, "executable", "param1", "param2" or "param1", "param2".</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithCommand(params string[] command);
/// <summary>
/// Sets the environment variable.
/// </summary>
/// <param name="name">The environment variable name.</param>
/// <param name="value">The environment variable value.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithEnvironment(string name, string value);
/// <summary>
/// Sets the environment variable.
/// </summary>
/// <param name="environments">A dictionary of environment variables.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithEnvironment(IReadOnlyDictionary<string, string> environments);
/// <summary>
/// Exposes the port without publishing it to the host system's interfaces.
/// </summary>
/// <param name="port">The port.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithExposedPort(int port);
/// <summary>
/// Exposes the port without publishing it to the host system's interfaces.
/// </summary>
/// <param name="port">The port.</param>
/// <remarks>Append /tcp|udp|sctp to <paramref name="port" /> to change the protocol e.g. "53/udp".</remarks>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithExposedPort(string port);
/// <summary>
/// Binds the container port to a random host port.
/// </summary>
/// <param name="port">The container port.</param>
/// <param name="assignRandomHostPort">Determines whether Testcontainers assigns a random host port or not.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithPortBinding(int port, bool assignRandomHostPort = false);
/// <summary>
/// Binds the container port to a specific host port.
/// </summary>
/// <param name="hostPort">The host port.</param>
/// <param name="containerPort">The container port.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithPortBinding(int hostPort, int containerPort);
/// <summary>
/// Binds the container port to a random host port.
/// </summary>
/// <param name="port">The container port.</param>
/// <param name="assignRandomHostPort">Determines whether Testcontainers assigns a random host port or not.</param>
/// <remarks>Append /tcp|udp|sctp to <paramref name="port" /> to change the protocol e.g. "53/udp".</remarks>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithPortBinding(string port, bool assignRandomHostPort = false);
/// <summary>
/// Binds the container port to a specific host port.
/// </summary>
/// <param name="hostPort">The host port.</param>
/// <param name="containerPort">The container port.</param>
/// <remarks>Append /tcp|udp|sctp to <paramref name="containerPort" /> to change the protocol e.g. "53/udp".</remarks>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithPortBinding(string hostPort, string containerPort);
/// <summary>
/// Copies the byte array content of the resource mapping to the created container before it starts.
/// </summary>
/// <param name="resourceMapping">The resource mapping.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithResourceMapping(IResourceMapping resourceMapping);
/// <summary>
/// Copies the byte array content to the created container before it starts.
/// </summary>
/// <param name="resourceContent">The byte array content of the resource mapping.</param>
/// <param name="filePath">The target file path to copy the file to.</param>
/// <param name="fileMode">The POSIX file mode permission.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithResourceMapping(byte[] resourceContent, string filePath, UnixFileModes fileMode = Unix.FileMode644);
/// <summary>
/// Copies the contents of a URL, a test host directory or file to the container before it starts.
/// </summary>
/// <remarks>
/// If the source corresponds to a file or the Uri scheme corresponds to a file,
/// the content is copied to the target directory path. If the Uri scheme
/// corresponds to HTTP or HTTPS, the content is copied to the target file path.
///
/// If you prefer to copy a file to a specific target file path instead of a
/// directory, use: <see cref="WithResourceMapping(FileInfo, FileInfo, UnixFileModes)" />.
/// </remarks>
/// <param name="source">The source URL, directory or file to be copied.</param>
/// <param name="target">The target directory or file path to copy the file to.</param>
/// <param name="fileMode">The POSIX file mode permission.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithResourceMapping(string source, string target, UnixFileModes fileMode = Unix.FileMode644);
/// <summary>
/// Copies a test host directory or file to the container before it starts.
/// </summary>
/// <param name="source">The source directory to be copied.</param>
/// <param name="target">The target directory path to copy the files to.</param>
/// <param name="fileMode">The POSIX file mode permission.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithResourceMapping(DirectoryInfo source, string target, UnixFileModes fileMode = Unix.FileMode644);
/// <summary>
/// Copies a test host directory or file to the container before it starts.
/// </summary>
/// <param name="source">The source file to be copied.</param>
/// <param name="target">The target directory path to copy the file to.</param>
/// <param name="fileMode">The POSIX file mode permission.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithResourceMapping(FileInfo source, string target, UnixFileModes fileMode = Unix.FileMode644);
/// <summary>
/// Copies a test host file to the container before it starts.
/// </summary>
/// <param name="source">The source file to be copied.</param>
/// <param name="target">The target file path to copy the file to.</param>
/// <param name="fileMode">The POSIX file mode permission.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithResourceMapping(FileInfo source, FileInfo target, UnixFileModes fileMode = Unix.FileMode644);
/// <summary>
/// Copies a file from a URL to the container before it starts.
/// </summary>
/// <remarks>
/// If the Uri scheme corresponds to a file, the content is copied to the target
/// directory path. If the Uri scheme corresponds to HTTP or HTTPS, the content is
/// copied to the target file path.
///
/// The Uri scheme must be either <c>http</c>, <c>https</c> or <c>file</c>.
///
/// If you prefer to copy a file to a specific target file path instead of a
/// directory, use: <see cref="WithResourceMapping(FileInfo, FileInfo, UnixFileModes)" />.
/// </remarks>
/// <param name="source">The source URL of the file to be copied.</param>
/// <param name="target">The target directory or file path to copy the file to.</param>
/// <param name="fileMode">The POSIX file mode permission.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
TBuilderEntity WithResourceMapping(Uri source, string target, UnixFileModes fileMode = Unix.FileMode644);
/// <summary>
/// Assigns the mount configuration to manage data in the container.
/// </summary>
/// <param name="mount">The mount configuration.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithMount(IMount mount);
/// <summary>
/// Binds and mounts the specified host machine volume into the container.
/// </summary>
/// <param name="source">An absolute path or a name value within the host machine.</param>
/// <param name="destination">An absolute path as destination in the container.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithBindMount(string source, string destination);
/// <summary>
/// Binds and mounts the specified host machine volume into the container.
/// </summary>
/// <param name="source">An absolute path or a name value within the host machine.</param>
/// <param name="destination">An absolute path as destination in the container.</param>
/// <param name="accessMode">The volume access mode.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithBindMount(string source, string destination, AccessMode accessMode);
/// <summary>
/// Mounts the specified managed volume into the container.
/// </summary>
/// <param name="source">The name of the managed volume.</param>
/// <param name="destination">An absolute path as destination in the container.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithVolumeMount(string source, string destination);
/// <summary>
/// Mounts the specified managed volume into the container.
/// </summary>
/// <param name="source">The name of the managed volume.</param>
/// <param name="destination">An absolute path as destination in the container.</param>
/// <param name="accessMode">The volume access mode.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithVolumeMount(string source, string destination, AccessMode accessMode);
/// <summary>
/// Mounts the specified managed volume into the container.
/// </summary>
/// <param name="volume">The managed volume.</param>
/// <param name="destination">An absolute path as destination in the container.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithVolumeMount(IVolume volume, string destination);
/// <summary>
/// Mounts the specified managed volume into the container.
/// </summary>
/// <param name="volume">The managed volume.</param>
/// <param name="destination">An absolute path as destination in the container.</param>
/// <param name="accessMode">The volume access mode.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithVolumeMount(IVolume volume, string destination, AccessMode accessMode);
/// <summary>
/// Mounts the specified tmpfs (temporary file system) volume into the container.
/// </summary>
/// <param name="destination">An absolute path as destination in the container.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithTmpfsMount(string destination);
/// <summary>
/// Mounts the specified tmpfs (temporary file system) volume into the container.
/// </summary>
/// <param name="destination">An absolute path as destination in the container.</param>
/// <param name="accessMode">The volume access mode.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithTmpfsMount(string destination, AccessMode accessMode);
/// <summary>
/// Assigns the specified network to the container.
/// </summary>
/// <param name="name">The network's name to connect to.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithNetwork(string name);
/// <summary>
/// Assigns the specified network to the container.
/// </summary>
/// <param name="network">The network to connect container to.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithNetwork(INetwork network);
/// <summary>
/// Assigns the specified network-scoped aliases to the container.
/// </summary>
/// <param name="networkAliases">The network-scoped aliases.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithNetworkAliases(params string[] networkAliases);
/// <summary>
/// Assigns the specified network-scoped aliases to the container.
/// </summary>
/// <param name="networkAliases">A list of network-scoped aliases.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithNetworkAliases(IEnumerable<string> networkAliases);
/// <summary>
/// Adds the extra host to "/etc/hosts" respectively "%WINDIR%\\system32\\drivers\\etc\\hosts".
/// </summary>
/// <param name="hostname">The hostname.</param>
/// <param name="ipAddress">The IP address.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithExtraHost(string hostname, string ipAddress);
/// <summary>
/// Cleans up the container after it exits.
/// </summary>
/// <remarks>
/// It is recommended to rely on the Resource Reaper to clean up resources: https://dotnet.testcontainers.org/api/resource-reaper/.
/// </remarks>
/// <param name="autoRemove">Determines whether Docker removes the container after it exits or not.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithAutoRemove(bool autoRemove);
/// <summary>
/// Sets the privileged flag.
/// </summary>
/// <param name="privileged">Determines whether the privileged flag is set or not.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithPrivileged(bool privileged);
/// <summary>
/// Sets the output consumer to capture the container's stdout and stderr messages.
/// </summary>
/// <param name="outputConsumer">The output consumer.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithOutputConsumer(IOutputConsumer outputConsumer);
/// <summary>
/// Sets the wait strategies to indicate readiness of the container.
/// </summary>
/// <param name="waitStrategy">The wait strategy.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithWaitStrategy(IWaitForContainerOS waitStrategy);
/// <summary>
/// Sets a startup callback to invoke after the container start.
/// </summary>
/// <remarks>
/// The callback method is invoked after the container start, but before the wait strategies.
/// </remarks>
/// <param name="startupCallback">The callback method to invoke.</param>
/// <returns>A configured instance of <typeparamref name="TBuilderEntity" />.</returns>
[PublicAPI]
TBuilderEntity WithStartupCallback(Func<TContainerEntity, CancellationToken, Task> startupCallback);
}
}