Skip to content

Commit

Permalink
Fixed Issue #85 and set version to 2.6.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Mario Toffia committed May 17, 2019
1 parent 8946d91 commit 4fe5c72
Show file tree
Hide file tree
Showing 10 changed files with 420 additions and 101 deletions.
4 changes: 2 additions & 2 deletions Ductus.FluentDocker.MsTest/Ductus.FluentDocker.MsTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFrameworks>netcoreapp1.1;netcoreapp2.0;net452</TargetFrameworks>
<VersionPrefix>2.6.6</VersionPrefix>
<VersionPrefix>2.6.7</VersionPrefix>
<AssemblyTitle>Ductus.FluentDocker.MsTest</AssemblyTitle>
<Authors>Mario Toffia</Authors>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
Expand All @@ -19,7 +19,7 @@ Documentation: https://github.com/mariotoffia/FluentDocker
<Copyright>© 2016 - 2019 Mario Toffia</Copyright>
<DefineConstants Condition=" '$(TargetFramework)' == 'netcoreapp1.1' ">$(DefineConstants);COREFX</DefineConstants>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>2.6.6</Version>
<Version>2.6.7</Version>
<AssemblyOriginatorKeyFile>..\keypair.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
Expand Down
3 changes: 3 additions & 0 deletions Ductus.FluentDocker.Tests/Ductus.FluentDocker.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
</ItemGroup>

<ItemGroup>
<None Update="Resources\ComposeTests\MongoDbAndNetwork\docker-compose.yml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Resources\ComposeTests\WordPress\docker-compose.yml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
207 changes: 115 additions & 92 deletions Ductus.FluentDocker.Tests/FluentApiTests/FluentDockerComposeTests.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Ductus.FluentDocker.Builders;
using Ductus.FluentDocker.Common;
using Ductus.FluentDocker.Model.Common;
using Ductus.FluentDocker.Services;
using Ductus.FluentDocker.Tests.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using HttpExtensions = Ductus.FluentDocker.Extensions.HttpExtensions;
Expand All @@ -13,14 +15,14 @@

namespace Ductus.FluentDocker.Tests.FluentApiTests
{
[TestClass]
public class FluentDockerComposeTests : FluentDockerTestBase
[TestClass]
public class FluentDockerComposeTests : FluentDockerTestBase
{
[TestMethod]
public async Task WordPressDockerComposeServiceShallShowInstallScreen()
{
[TestMethod]
public async Task WordPressDockerComposeServiceShallShowInstallScreen()
{
var file = Path.Combine(Directory.GetCurrentDirectory(),
(TemplateString) "Resources/ComposeTests/WordPress/docker-compose.yml");
var file = Path.Combine(Directory.GetCurrentDirectory(),
(TemplateString) "Resources/ComposeTests/WordPress/docker-compose.yml");

// @formatter:off
using (var svc = Fd
Expand All @@ -30,24 +32,24 @@ public async Task WordPressDockerComposeServiceShallShowInstallScreen()
.RemoveOrphans()
.WaitForHttp("wordpress", "http://localhost:8000/wp-admin/install.php")
.Build().Start())
// @formatter:on
{
// We now have a running WordPress with a MySql database
var installPage = await "http://localhost:8000/wp-admin/install.php".Wget();

Assert.IsTrue(installPage.IndexOf("https://wordpress.org/", StringComparison.Ordinal) != -1);
Assert.AreEqual(1, svc.Hosts.Count);
Assert.AreEqual(2, svc.Containers.Count);
Assert.AreEqual(2, svc.Images.Count);
Assert.AreEqual(5, svc.Services.Count);
}
}
// @formatter:on
{
// We now have a running WordPress with a MySql database
var installPage = await "http://localhost:8000/wp-admin/install.php".Wget();

[TestMethod]
public async Task ComposeWaitForHttpShallWork()
{
var file = Path.Combine(Directory.GetCurrentDirectory(),
(TemplateString) "Resources/ComposeTests/WordPress/docker-compose.yml");
Assert.IsTrue(installPage.IndexOf("https://wordpress.org/", StringComparison.Ordinal) != -1);
Assert.AreEqual(1, svc.Hosts.Count);
Assert.AreEqual(2, svc.Containers.Count);
Assert.AreEqual(2, svc.Images.Count);
Assert.AreEqual(5, svc.Services.Count);
}
}

[TestMethod]
public async Task ComposeWaitForHttpShallWork()
{
var file = Path.Combine(Directory.GetCurrentDirectory(),
(TemplateString) "Resources/ComposeTests/WordPress/docker-compose.yml");

// @formatter:off
using (Fd
Expand All @@ -58,23 +60,23 @@ public async Task ComposeWaitForHttpShallWork()
.WaitForHttp("wordpress", "http://localhost:8000/wp-admin/install.php", continuation: (resp, cnt) =>
resp.Body.IndexOf("https://wordpress.org/", StringComparison.Ordinal) != -1 ? 0 : 500)
.Build().Start())
// @formatter:on
{
// Since we have waited - this shall now always work.
var installPage = await "http://localhost:8000/wp-admin/install.php".Wget();
Assert.IsTrue(installPage.IndexOf("https://wordpress.org/", StringComparison.Ordinal) != -1);
}
}
// @formatter:on
{
// Since we have waited - this shall now always work.
var installPage = await "http://localhost:8000/wp-admin/install.php".Wget();
Assert.IsTrue(installPage.IndexOf("https://wordpress.org/", StringComparison.Ordinal) != -1);
}
}

[TestMethod]
[ExpectedException(typeof(FluentDockerException))]
public void ComposeWaitForHttpThatFailShallBeAborted()
{
var file = Path.Combine(Directory.GetCurrentDirectory(),
(TemplateString) "Resources/ComposeTests/WordPress/docker-compose.yml");
[TestMethod]
[ExpectedException(typeof(FluentDockerException))]
public void ComposeWaitForHttpThatFailShallBeAborted()
{
var file = Path.Combine(Directory.GetCurrentDirectory(),
(TemplateString) "Resources/ComposeTests/WordPress/docker-compose.yml");

try
{
try
{
// @formatter:off
using (Fd
.UseContainer()
Expand All @@ -89,28 +91,28 @@ public void ComposeWaitForHttpThatFailShallBeAborted()
return resp.Body.IndexOf("ALIBABA", StringComparison.Ordinal) != -1 ? 0 : 500;
})
.Build().Start())
// @formatter:on

{
Assert.Fail("It should have thrown a FluentDockerException!");
}
}
catch
{
// Manually remove containers since they are not cleaned up due to the error...
foreach (var container in Fd.Native().GetContainers())
if (container.Name.StartsWith("wordpress"))
container.Dispose();

throw;
}
}
// @formatter:on

[TestMethod]
public async Task ComposeWaitForCustomLambdaShallWork()
{
var file = Path.Combine(Directory.GetCurrentDirectory(),
(TemplateString) "Resources/ComposeTests/WordPress/docker-compose.yml");
Assert.Fail("It should have thrown a FluentDockerException!");
}
}
catch
{
// Manually remove containers since they are not cleaned up due to the error...
foreach (var container in Fd.Native().GetContainers())
if (container.Name.StartsWith("wordpress"))
container.Dispose();

throw;
}
}

[TestMethod]
public async Task ComposeWaitForCustomLambdaShallWork()
{
var file = Path.Combine(Directory.GetCurrentDirectory(),
(TemplateString) "Resources/ComposeTests/WordPress/docker-compose.yml");

// @formatter:off
using (Fd
Expand All @@ -126,39 +128,60 @@ public async Task ComposeWaitForCustomLambdaShallWork()
res.Body.IndexOf("https://wordpress.org/", StringComparison.Ordinal) != -1 ? 0 : 500;
})
.Build().Start())
// @formatter:on
{
// Since we have waited - this shall now always work.
var installPage = await "http://localhost:8000/wp-admin/install.php".Wget();
Assert.IsTrue(installPage.IndexOf("https://wordpress.org/", StringComparison.Ordinal) != -1);
}
}
// @formatter:on
{
// Since we have waited - this shall now always work.
var installPage = await "http://localhost:8000/wp-admin/install.php".Wget();
Assert.IsTrue(installPage.IndexOf("https://wordpress.org/", StringComparison.Ordinal) != -1);
}
}

[TestMethod]
public void ComposeRunOnRemoteMachineShallWork()
{
var file = Path.Combine(Directory.GetCurrentDirectory(),
(TemplateString) "Resources/ComposeTests/WordPress/docker-compose.yml");

using (
var svc =
new Builder().UseHost()
.UseSsh("192.168.1.27").WithName("remote-daemon")
.WithSshUser("solo").WithSshKeyPath("${E_LOCALAPPDATA}/lxss/home/martoffi/.ssh/id_rsa")
.UseContainer()
.UseCompose()
.FromFile(file)
.RemoveOrphans()
.WaitForHttp("wordpress", "http://localhost:8000/wp-admin/install.php",
continuation: (resp, cnt) =>
resp.Body.IndexOf("https://wordpress.org/", StringComparison.Ordinal) != -1 ? 0 : 500)
.Build().Start())
{
Assert.AreEqual(1, svc.Hosts.Count);
Assert.AreEqual(2, svc.Containers.Count);
Assert.AreEqual(2, svc.Images.Count);
Assert.AreEqual(5, svc.Services.Count);
}
}
[TestMethod]
public void ComposeRunOnRemoteMachineShallWork()
{
var file = Path.Combine(Directory.GetCurrentDirectory(),
(TemplateString) "Resources/ComposeTests/WordPress/docker-compose.yml");

using (
var svc =
new Builder().UseHost()
.UseSsh("192.168.1.27").WithName("remote-daemon")
.WithSshUser("solo").WithSshKeyPath("${E_LOCALAPPDATA}/lxss/home/martoffi/.ssh/id_rsa")
.UseContainer()
.UseCompose()
.FromFile(file)
.RemoveOrphans()
.WaitForHttp("wordpress", "http://localhost:8000/wp-admin/install.php",
continuation: (resp, cnt) =>
resp.Body.IndexOf("https://wordpress.org/", StringComparison.Ordinal) != -1 ? 0 : 500)
.Build().Start())
{
Assert.AreEqual(1, svc.Hosts.Count);
Assert.AreEqual(2, svc.Containers.Count);
Assert.AreEqual(2, svc.Images.Count);
Assert.AreEqual(5, svc.Services.Count);
}
}

[TestMethod]
public void Issue85()
{
var file = Path.Combine(Directory.GetCurrentDirectory(),
(TemplateString) "Resources/ComposeTests/MongoDbAndNetwork/docker-compose.yml");

using (var svc = Fd.UseContainer()
.UseCompose()
.FromFile(file)
.Build()
.Start())
{
var c = (IContainerService) svc.Services.Single(s => s is IContainerService);
var nw = c.GetNetworks().Single();
var ncfg = nw.GetConfiguration(true);

Assert.AreEqual("mongodbandnetwork_mongodb-network", nw.Name);
Assert.AreEqual(ncfg.Id, nw.Id);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: '3.3'

services:
mongodb:
image: mongo:latest
volumes:
- mongodb-data:/data
command: mongod --smallfiles --bind_ip=0.0.0.0 --logpath=/dev/null
expose:
- 27017
networks:
- mongodb-network

volumes:
mongodb-data:

networks:
mongodb-network:
36 changes: 36 additions & 0 deletions Ductus.FluentDocker/Commands/Service.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using Ductus.FluentDocker.Executors;
using Ductus.FluentDocker.Executors.Parsers;
using Ductus.FluentDocker.Extensions;
using Ductus.FluentDocker.Model.Common;
using Ductus.FluentDocker.Model.Containers;
using Ductus.FluentDocker.Model.Stacks;

namespace Ductus.FluentDocker.Commands
{
/// <summary>
/// Docker service commands
/// </summary>
/// <remarks>
/// API 1.24+
/// docker service create [OPTIONS] IMAGE [COMMAND] [ARG...]
/// </remarks>
public static class Service
{
// TODO: Implement me!
public static CommandResponse<IList<string>> ServiceCreate(this DockerUri host,
Orchestrator orchestrator = Orchestrator.All,
string kubeConfigFile = null,
ICertificatePaths certificates = null, params string []stacks)
{
var args = $"{host.RenderBaseArgs(certificates)}";
var opts = $"--orchestrator={orchestrator}"; // TODO:

return // TODO:
new ProcessExecutor<StringListResponseParser, IList<string>>(
"docker".ResolveBinary(),
$"{args} stack rm {opts} {string.Join(" ", stacks)}").Execute();
}
}
}
1 change: 0 additions & 1 deletion Ductus.FluentDocker/Commands/Stack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ namespace Ductus.FluentDocker.Commands
/// </remarks>
public static class Stack
{
// TODO: https://docs.docker.com/engine/reference/commandline/stack_ps/
public static CommandResponse<IList<StackLsResponse>> StackLs(this DockerUri host,
Orchestrator orchestrator = Orchestrator.All,
bool kubeAllNamespaces = true,
Expand Down
8 changes: 4 additions & 4 deletions Ductus.FluentDocker/Ductus.FluentDocker.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard1.6;netstandard2.0;net452</TargetFrameworks>
<VersionPrefix>2.6.6</VersionPrefix>
<VersionPrefix>2.6.7</VersionPrefix>
<AssemblyTitle>Ductus.FluentDocker</AssemblyTitle>
<Authors>Mario Toffia</Authors>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
Expand All @@ -16,9 +16,9 @@
<DefineConstants Condition=" '$(TargetFramework)' == 'netstandard1.6' ">$(DefineConstants);COREFX</DefineConstants>
<DefineConstants Condition=" '$(TargetFramework)' == 'netstandard2.0' ">$(DefineConstants);COREFX</DefineConstants>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<AssemblyVersion>2.6.6.0</AssemblyVersion>
<FileVersion>2.6.6.0</FileVersion>
<Version>2.6.6</Version>
<AssemblyVersion>2.6.7.0</AssemblyVersion>
<FileVersion>2.6.7.0</FileVersion>
<Version>2.6.7</Version>
<AssemblyOriginatorKeyFile>..\keypair.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
Expand Down
Loading

0 comments on commit 4fe5c72

Please sign in to comment.