Skip to content

Commit

Permalink
Fixed bug (Issue #90) and added ulimit feature (Issue #88).
Browse files Browse the repository at this point in the history
The bug is when docker-machine was created using --generic-ip-address=docker where it will have docker as the ipaddress.

Now it is possible to set ulimit on ContainerCreateParams and on
the fluent API.
  • Loading branch information
Mario Toffia committed Jul 24, 2019
1 parent 8ba0869 commit a1f821b
Show file tree
Hide file tree
Showing 7 changed files with 518 additions and 271 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -477,5 +477,21 @@ public void ContainerHealthCheckShallWork()
AreEqual(HealthState.Starting, config.State.Health.Status);
}
}
[TestMethod]
public void ContainerWithUlimitsShallWork()
{
using (
var container =
Fd.UseContainer()
.UseImage("postgres:latest", force: true)
.UseUlimit(Ulimit.NoFile,2048, 2048)
.WithEnvironment("POSTGRES_PASSWORD=mysecretpassword")
.Build()
.Start())
{
var config = container.GetConfiguration(true);
AreEqual(HealthState.Starting, config.State.Health.Status);
}
}
}
}
35 changes: 35 additions & 0 deletions Ductus.FluentDocker/Builders/ContainerBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Ductus.FluentDocker.Model.Builders;
using Ductus.FluentDocker.Model.Common;
using Ductus.FluentDocker.Model.Compose;
using Ductus.FluentDocker.Model.Containers;
using Ductus.FluentDocker.Services;
using Ductus.FluentDocker.Services.Extensions;

Expand Down Expand Up @@ -378,6 +379,40 @@ public ContainerBuilder UseIpV6(string ipv6)
return this;
}

/// <summary>
/// Adds a new <see cref="Ulimit"/> onto a container.
/// </summary>
/// <param name="ulimit">The ulimit to impose.</param>
/// <param name="soft">The soft value.</param>
/// <param name="hard">The optional hard value.</param>
/// <returns>Itself for fluent access.</returns>
/// <remarks>
/// For example restricting the number of open files to 10 use <see cref="Ulimit.NoFile"/> and set soft / hard
/// to 10.
/// </remarks>
public ContainerBuilder UseUlimit(Ulimit ulimit, string soft, string hard = null)
{
_config.CreateParams.Ulimit.Add(new ULimitItem(ulimit, soft, hard));
return this;
}

/// <summary>
/// Adds a new <see cref="Ulimit"/> onto a container.
/// </summary>
/// <param name="ulimit">The ulimit to impose.</param>
/// <param name="soft">The soft value.</param>
/// <param name="hard">The optional hard value.</param>
/// <returns>Itself for fluent access.</returns>
/// <remarks>
/// For example restricting the number of open files to 10 use <see cref="Ulimit.NoFile"/> and set soft / hard
/// to 10.
/// </remarks>
public ContainerBuilder UseUlimit(Ulimit ulimit, long soft, long ?hard = null)
{
_config.CreateParams.Ulimit.Add(new ULimitItem(ulimit, soft.ToString(), hard.HasValue ? hard.ToString() : null));
return this;
}

public ContainerBuilder ExportOnDispose(string hostPath, Func<IContainerService, bool> condition = null)
{
_config.ExportOnDispose =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@ public IProcessResponse<MachineConfiguration> Process(ProcessExecutionResult res
memsize = j["Driver"]["MemSize"].Value<int>();
}

string hostname = null;
if (!IPAddress.TryParse(ip, out var ipaddr))
hostname = ip;


var config = new MachineConfiguration
{
AuthConfig = authConfig,
IpAddress = string.IsNullOrEmpty(ip) ? IPAddress.None : IPAddress.Parse(ip),
IpAddress = ipaddr,
Hostname = hostname,
DriverName = null != j["DriverName"] ? j["DriverName"].Value<string>() : "unknown",
MemorySizeMb = memsize,
Name = null != j["Name"] ? j["Name"].Value<string>() : string.Empty,
Expand Down
Loading

0 comments on commit a1f821b

Please sign in to comment.