-
-
Notifications
You must be signed in to change notification settings - Fork 345
Expand file tree
/
Copy pathContainerConfiguration.cs
More file actions
238 lines (210 loc) · 10 KB
/
ContainerConfiguration.cs
File metadata and controls
238 lines (210 loc) · 10 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
using Docker.DotNet.Models;
using DotNet.Testcontainers.Builders;
using DotNet.Testcontainers.Configurations.Containers;
using DotNet.Testcontainers.Containers;
using DotNet.Testcontainers.Images;
using DotNet.Testcontainers.Networks;
using JetBrains.Annotations;
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using System.Threading;
using System.Threading.Tasks;
namespace DotNet.Testcontainers.Configurations
{
/// <inheritdoc cref="IContainerConfiguration" />
[PublicAPI]
public class ContainerConfiguration : ResourceConfiguration<CreateContainerParameters>, IContainerConfiguration
{
/// <summary>
/// Initializes a new instance of the <see cref="ContainerConfiguration" /> class.
/// </summary>
/// <param name="image">The image.</param>
/// <param name="imagePullPolicy">The image pull policy.</param>
/// <param name="name">The name.</param>
/// <param name="hostname">The hostname.</param>
/// <param name="macAddress">The MAC address.</param>
/// <param name="workingDirectory">The working directory.</param>
/// <param name="entrypoint">The entrypoint.</param>
/// <param name="command">The command.</param>
/// <param name="environments">A dictionary of environment variables.</param>
/// <param name="exposedPorts">A dictionary of exposed ports.</param>
/// <param name="portBindings">A dictionary of port bindings.</param>
/// <param name="resourceMappings">A list of resource mappings.</param>
/// <param name="containers">A list of containers.</param>
/// <param name="mounts">A list of mounts.</param>
/// <param name="networks">A list of networks.</param>
/// <param name="networkAliases">A list of network-scoped aliases.</param>
/// <param name="extraHosts">A list of extra hosts.</param>
/// <param name="outputConsumer">The output consumer.</param>
/// <param name="waitStrategies">The wait strategies.</param>
/// <param name="startupCallback">The startup callback.</param>
/// <param name="connectionStringProvider">The connection string provider.</param>
/// <param name="autoRemove">A value indicating whether Docker removes the container after it exits or not.</param>
/// <param name="privileged">A value indicating whether the privileged flag is set or not.</param>
/// <param name="tarArchiveMappings">A list of tar archive mappings.</param>
public ContainerConfiguration(
IImage image = null,
Func<ImageInspectResponse, bool> imagePullPolicy = null,
string name = null,
string hostname = null,
string macAddress = null,
string workingDirectory = null,
IEnumerable<string> entrypoint = null,
ComposableEnumerable<string> command = null,
IReadOnlyDictionary<string, string> environments = null,
IReadOnlyDictionary<string, string> exposedPorts = null,
IReadOnlyDictionary<string, string> portBindings = null,
IEnumerable<IResourceMapping> resourceMappings = null,
IEnumerable<IContainer> containers = null,
IEnumerable<IMount> mounts = null,
IEnumerable<INetwork> networks = null,
IEnumerable<string> networkAliases = null,
IEnumerable<string> extraHosts = null,
IOutputConsumer outputConsumer = null,
IEnumerable<WaitStrategy> waitStrategies = null,
Func<IContainer, IContainerConfiguration, CancellationToken, Task> startupCallback = null,
IConnectionStringProvider<IContainer, IContainerConfiguration> connectionStringProvider = null,
bool? autoRemove = null,
bool? privileged = null,
IEnumerable<TarArchiveMapping> tarArchiveMappings = null)
{
AutoRemove = autoRemove;
Privileged = privileged;
Image = image;
ImagePullPolicy = imagePullPolicy;
Name = name;
Hostname = hostname;
MacAddress = macAddress;
WorkingDirectory = workingDirectory;
Entrypoint = entrypoint;
Command = command;
Environments = environments;
ExposedPorts = exposedPorts;
PortBindings = portBindings;
ResourceMappings = resourceMappings;
Containers = containers;
Mounts = mounts;
Networks = networks;
NetworkAliases = networkAliases;
ExtraHosts = extraHosts;
OutputConsumer = outputConsumer;
WaitStrategies = waitStrategies;
StartupCallback = startupCallback;
ConnectionStringProvider = connectionStringProvider;
TarArchiveMappings = tarArchiveMappings;
}
/// <summary>
/// Initializes a new instance of the <see cref="ContainerConfiguration" /> class.
/// </summary>
/// <param name="resourceConfiguration">The Docker resource configuration.</param>
public ContainerConfiguration(IResourceConfiguration<CreateContainerParameters> resourceConfiguration)
: base(resourceConfiguration)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ContainerConfiguration" /> class.
/// </summary>
/// <param name="resourceConfiguration">The Docker resource configuration.</param>
public ContainerConfiguration(IContainerConfiguration resourceConfiguration)
: this(new ContainerConfiguration(), resourceConfiguration)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ContainerConfiguration" /> class.
/// </summary>
/// <param name="oldValue">The old Docker resource configuration.</param>
/// <param name="newValue">The new Docker resource configuration.</param>
public ContainerConfiguration(IContainerConfiguration oldValue, IContainerConfiguration newValue)
: base(oldValue, newValue)
{
Image = BuildConfiguration.Combine(oldValue.Image, newValue.Image);
ImagePullPolicy = BuildConfiguration.Combine(oldValue.ImagePullPolicy, newValue.ImagePullPolicy);
Name = BuildConfiguration.Combine(oldValue.Name, newValue.Name);
Hostname = BuildConfiguration.Combine(oldValue.Hostname, newValue.Hostname);
MacAddress = BuildConfiguration.Combine(oldValue.MacAddress, newValue.MacAddress);
WorkingDirectory = BuildConfiguration.Combine(oldValue.WorkingDirectory, newValue.WorkingDirectory);
Entrypoint = BuildConfiguration.Combine<IEnumerable<string>>(oldValue.Entrypoint, newValue.Entrypoint);
Command = BuildConfiguration.Combine(oldValue.Command, newValue.Command);
Environments = BuildConfiguration.Combine(oldValue.Environments, newValue.Environments);
ExposedPorts = BuildConfiguration.Combine(oldValue.ExposedPorts, newValue.ExposedPorts);
PortBindings = BuildConfiguration.Combine(oldValue.PortBindings, newValue.PortBindings);
ResourceMappings = BuildConfiguration.Combine(oldValue.ResourceMappings, newValue.ResourceMappings);
TarArchiveMappings = BuildConfiguration.Combine(oldValue.TarArchiveMappings, newValue.TarArchiveMappings);
Containers = BuildConfiguration.Combine(oldValue.Containers, newValue.Containers);
Mounts = BuildConfiguration.Combine(oldValue.Mounts, newValue.Mounts);
Networks = BuildConfiguration.Combine(oldValue.Networks, newValue.Networks);
NetworkAliases = BuildConfiguration.Combine(oldValue.NetworkAliases, newValue.NetworkAliases);
ExtraHosts = BuildConfiguration.Combine(oldValue.ExtraHosts, newValue.ExtraHosts);
OutputConsumer = BuildConfiguration.Combine(oldValue.OutputConsumer, newValue.OutputConsumer);
WaitStrategies = BuildConfiguration.Combine<IEnumerable<WaitStrategy>>(oldValue.WaitStrategies, newValue.WaitStrategies);
StartupCallback = BuildConfiguration.Combine(oldValue.StartupCallback, newValue.StartupCallback);
ConnectionStringProvider = BuildConfiguration.Combine(oldValue.ConnectionStringProvider, newValue.ConnectionStringProvider);
AutoRemove = (oldValue.AutoRemove.HasValue && oldValue.AutoRemove.Value) || (newValue.AutoRemove.HasValue && newValue.AutoRemove.Value);
Privileged = (oldValue.Privileged.HasValue && oldValue.Privileged.Value) || (newValue.Privileged.HasValue && newValue.Privileged.Value);
}
/// <inheritdoc />
[JsonIgnore]
public bool? AutoRemove { get; }
/// <inheritdoc />
[JsonIgnore]
public bool? Privileged { get; }
/// <inheritdoc />
public IImage Image { get; }
/// <inheritdoc />
[JsonIgnore]
public Func<ImageInspectResponse, bool> ImagePullPolicy { get; }
/// <inheritdoc />
public string Name { get; }
/// <inheritdoc />
[JsonIgnore]
public string Hostname { get; }
/// <inheritdoc />
[JsonIgnore]
public string MacAddress { get; }
/// <inheritdoc />
[JsonIgnore]
public string WorkingDirectory { get; }
/// <inheritdoc />
public IEnumerable<string> Entrypoint { get; }
/// <inheritdoc />
public ComposableEnumerable<string> Command { get; }
/// <inheritdoc />
public IReadOnlyDictionary<string, string> Environments { get; }
/// <inheritdoc />
public IReadOnlyDictionary<string, string> ExposedPorts { get; }
/// <inheritdoc />
public IReadOnlyDictionary<string, string> PortBindings { get; }
/// <inheritdoc />
[JsonIgnore]
public IEnumerable<IResourceMapping> ResourceMappings { get; }
/// <inheritdoc />
[JsonIgnore]
public IEnumerable<TarArchiveMapping> TarArchiveMappings { get; }
/// <inheritdoc />
[JsonIgnore]
public IEnumerable<IContainer> Containers { get; }
/// <inheritdoc />
[JsonIgnore]
public IEnumerable<IMount> Mounts { get; }
/// <inheritdoc />
[JsonIgnore]
public IEnumerable<INetwork> Networks { get; }
/// <inheritdoc />
public IEnumerable<string> NetworkAliases { get; }
/// <inheritdoc />
public IEnumerable<string> ExtraHosts { get; }
/// <inheritdoc />
[JsonIgnore]
public IOutputConsumer OutputConsumer { get; }
/// <inheritdoc />
[JsonIgnore]
public IEnumerable<WaitStrategy> WaitStrategies { get; }
/// <inheritdoc />
[JsonIgnore]
public Func<IContainer, IContainerConfiguration, CancellationToken, Task> StartupCallback { get; }
/// <inheritdoc />
[JsonIgnore]
public IConnectionStringProvider<IContainer, IContainerConfiguration> ConnectionStringProvider { get; }
}
}