diff --git a/Ductus.FluentDocker.MsTest/Ductus.FluentDocker.MsTest.csproj b/Ductus.FluentDocker.MsTest/Ductus.FluentDocker.MsTest.csproj index b25a4d2..21415f7 100644 --- a/Ductus.FluentDocker.MsTest/Ductus.FluentDocker.MsTest.csproj +++ b/Ductus.FluentDocker.MsTest/Ductus.FluentDocker.MsTest.csproj @@ -2,7 +2,7 @@ netcoreapp1.1;net452 - 2.2.19 + 2.3.0 Ductus.FluentDocker.MsTest Mario Toffia https://github.com/mariotoffia/FluentDocker/blob/master/LICENSE @@ -19,7 +19,7 @@ Documentation: https://github.com/mariotoffia/FluentDocker © 2016, 2017, 2018 Mario Toffia $(DefineConstants);COREFX True - 2.2.19 + 2.3.0 ..\keypair.snk true true diff --git a/Ductus.FluentDocker/Builders/ContainerBuilder.cs b/Ductus.FluentDocker/Builders/ContainerBuilder.cs index e6ff8d5..e2238dd 100644 --- a/Ductus.FluentDocker/Builders/ContainerBuilder.cs +++ b/Ductus.FluentDocker/Builders/ContainerBuilder.cs @@ -36,7 +36,12 @@ public override IContainerService Build() .FirstOrDefault(x => IsNameMatch(x.Name, _config.CreateParams.Name)); if (null != existing) + { + existing.RemoveOnDispose = _config.DeleteOnDispose; + existing.StopOnDispose = _config.StopOnDispose; + return existing; + } } var container = host.Value.Create(_config.Image, _config.CreateParams, _config.StopOnDispose, @@ -168,7 +173,7 @@ public ContainerBuilder ExposePort(int containerPort) public ContainerBuilder Mount(string fqHostPath, string fqContainerPath, MountType access) { - var hp = OperatingSystem.IsWindows() && CommandExtensions.IsToolbox() + var hp = Ductus.FluentDocker.Common.OperatingSystem.IsWindows() && CommandExtensions.IsToolbox() ? ((TemplateString) fqHostPath).Rendered.ToMsysPath() : ((TemplateString) fqHostPath).Rendered; @@ -407,7 +412,7 @@ private void AddHooks(IService container) // docker execute when disposing if (null != _config.ExecuteOnDisposingArguments && _config.ExecuteOnDisposingArguments.Count > 0) - container.AddHook(ServiceRunningState.Running, service => + container.AddHook(ServiceRunningState.Removing, service => { var svc = (IContainerService) service; foreach (var binaryAndArguments in _config.ExecuteOnDisposingArguments) diff --git a/Ductus.FluentDocker/Builders/HostBuilder.cs b/Ductus.FluentDocker/Builders/HostBuilder.cs index b007ab6..9c99562 100644 --- a/Ductus.FluentDocker/Builders/HostBuilder.cs +++ b/Ductus.FluentDocker/Builders/HostBuilder.cs @@ -13,7 +13,7 @@ internal HostBuilder(IBuilder builder) : base(builder) public override IHostService Build() { - return _useNative ? new Hosts().Discover().First(x => x.IsNative) : null; + return _useNative ? new Hosts().Discover(_useNative).First(x => x.IsNative) : null; } protected override IBuilder InternalCreate() diff --git a/Ductus.FluentDocker/Ductus.FluentDocker.csproj b/Ductus.FluentDocker/Ductus.FluentDocker.csproj index 42a0a29..b6fa484 100644 --- a/Ductus.FluentDocker/Ductus.FluentDocker.csproj +++ b/Ductus.FluentDocker/Ductus.FluentDocker.csproj @@ -3,7 +3,7 @@ netstandard1.6;netstandard2.0;net452 - 2.2.19 + 2.3.0 Ductus.FluentDocker Mario Toffia https://github.com/mariotoffia/FluentDocker/blob/master/LICENSE @@ -18,9 +18,9 @@ $(DefineConstants);COREFX $(DefineConstants);COREFX True - 2.2.19.0 - 2.2.19.0 - 2.2.19 + 2.3.0.0 + 2.3.0.0 + 2.3.0 ..\keypair.snk true true diff --git a/Ductus.FluentDocker/Services/Hosts.cs b/Ductus.FluentDocker/Services/Hosts.cs index a3463b2..afa3a12 100644 --- a/Ductus.FluentDocker/Services/Hosts.cs +++ b/Ductus.FluentDocker/Services/Hosts.cs @@ -9,10 +9,18 @@ namespace Ductus.FluentDocker.Services { public sealed class Hosts { - public IList Discover() + public IList Discover(bool preferNative = false) { var list = new List(); + if (CommandExtensions.IsEmulatedNative() || CommandExtensions.IsNative()) + list.Add(new DockerHostService("native", true, false, + null, + Environment.GetEnvironmentVariable(DockerHostService.DockerCertPath))); + + if (list.Count > 0 && preferNative) + return list; + if (Machine.IsPresent()) { var ls = Machine.Ls(); @@ -24,11 +32,6 @@ public IList Discover() inspect.Data.AuthConfig.CertDir)); } - if (CommandExtensions.IsEmulatedNative() || CommandExtensions.IsNative()) - list.Add(new DockerHostService("native", true, false, - null, - Environment.GetEnvironmentVariable(DockerHostService.DockerCertPath))); - return list; } } diff --git a/Ductus.FluentDocker/Services/IContainerService.cs b/Ductus.FluentDocker/Services/IContainerService.cs index 4c4710d..0e89689 100644 --- a/Ductus.FluentDocker/Services/IContainerService.cs +++ b/Ductus.FluentDocker/Services/IContainerService.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Ductus.FluentDocker.Model.Common; using Ductus.FluentDocker.Model.Containers; @@ -6,11 +7,28 @@ namespace Ductus.FluentDocker.Services { public interface IContainerService : IService { + /// + /// The container id of the running container. + /// string Id { get; } + + /// + /// The to the docker daemon in control of this service. + /// DockerUri DockerHost { get; } /// - /// Dettermines if this container is based on a windows image or linux image. + /// When set to true the container is stopped automatically on . + /// + bool StopOnDispose { get; set; } + + /// + /// When set to true the container is removed automaticallyh on . + /// + bool RemoveOnDispose { get; set; } + + /// + /// Dettermines if this container is based on a windows image or linux image. /// bool IsWindowsContainer { get; } diff --git a/Ductus.FluentDocker/Services/Impl/DockerContainerService.cs b/Ductus.FluentDocker/Services/Impl/DockerContainerService.cs index 8b147a2..0c4e031 100644 --- a/Ductus.FluentDocker/Services/Impl/DockerContainerService.cs +++ b/Ductus.FluentDocker/Services/Impl/DockerContainerService.cs @@ -13,8 +13,6 @@ public sealed class DockerContainerService : IContainerService private readonly ServiceHooks _hooks = new ServiceHooks(); private readonly bool _removeMountOnDispose; private readonly bool _removeNamedMountOnDispose; - private readonly bool _removeOnDispose; - private readonly bool _stopOnDispose; private Container _containerConfigCache; private ServiceRunningState _state = ServiceRunningState.Unknown; @@ -27,8 +25,8 @@ public DockerContainerService(string name, string id, DockerUri docker, ServiceR Certificates = certificates; _removeNamedMountOnDispose = removeNamedMountOnDispose; _removeMountOnDispose = removeMountOnDispose; - _stopOnDispose = stopOnDispose; - _removeOnDispose = removeOnDispose; + StopOnDispose = stopOnDispose; + RemoveOnDispose = removeOnDispose; Name = name; Id = id; @@ -38,6 +36,11 @@ public DockerContainerService(string name, string id, DockerUri docker, ServiceR public string Id { get; } public DockerUri DockerHost { get; } + + public bool StopOnDispose { get; set; } + + public bool RemoveOnDispose { get; set; } + public bool IsWindowsContainer { get; } public Container GetConfiguration(bool fresh = false) @@ -78,10 +81,10 @@ public void Dispose() if (string.IsNullOrEmpty(Id)) return; - if (_stopOnDispose) + if (StopOnDispose) Stop(); - if (_removeOnDispose) + if (RemoveOnDispose) Remove(true, _removeMountOnDispose); } @@ -146,9 +149,7 @@ public IList GetNetworks() var list = new List(); foreach (var n in config.NetworkSettings.Networks) - { list.Add(new DockerNetworkService(n.Value.NetworkID, n.Key, DockerHost, Certificates)); - } return list; } diff --git a/appveyor.yml b/appveyor.yml index 466becd..c9d22b4 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,5 +1,5 @@ #version: 0.0.0.{build} -version: 2.2.19 +version: 2.3.0 skip_non_tags: true image: Visual Studio 2017 configuration: Release