Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command Driver Infrastructure #226

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
{
"cSpell.words": [
"Ductus",
"Exploaded",
"Ipam",
"LOCALAPPDATA",
"Miscellanious",
"NOPASSWD",
"Npgsql",
"Toffia",
"appconfig",
"archve",
"behaviour",
"compsed",
"dockercli",
"dont",
"Ductus",
"editorconfig",
"Exploaded",
"flaviours",
"fluentdockerdl",
"fluentdockertest",
"Ipam",
"kiasaki",
"LOCALAPPDATA",
"lxss",
"mariotoffia",
"martoffi",
"Miscellanious",
"mkdir",
"myimg",
"mysecretpassword",
"mytag",
"nodetest",
"NOPASSWD",
"Npgsql",
"nuget",
"particulary",
"postgres",
Expand All @@ -34,6 +34,7 @@
"proto",
"somewordpress",
"sudoer",
"Toffia",
"typeof",
"wdlp"
],
Expand Down
46 changes: 46 additions & 0 deletions Ductus.FluentDocker/Execution/CommandCategory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
namespace Ductus.FluentDocker.Execution
{
public enum CommandCategory
{
/// <summary>
/// Unknown commnad category.
/// </summary>
Unknown = 0,
/// <summary>
/// Container is manageing a single container approach such as create container.
/// </summary>
/// <remarks>
/// Even though it is possible to create multiple containers, when the command is in this
/// category, it is assumed that the command is for a single container.
/// </remarks>
Container = 1,
/// <summary>
/// Composite is when e.g. using docker compose to allow for multiple container, network etc. operation.
/// </summary>
/// <remarks>
/// Since e.g. docker compose may handle volumes, network etc. it is not a strict container command
/// that is the yielded result.
Composite = 2,
/// <summary>
/// Network is manageing docker networking.
/// </summary>
Network = 3,
/// <summary>
/// Volume is managing docker volumes.
/// </summary>
Volume = 4,
/// <summary>
/// Information command request.
/// </summary>
Info = 5,
/// <summary>
/// Machine is the legacy docker-machine command.
/// </summary>
Machine = 6,
/// <summary>
/// Stack manages docker stack operations.
/// </summary>
Stack = 7
}

}
20 changes: 20 additions & 0 deletions Ductus.FluentDocker/Execution/CommandType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace Ductus.FluentDocker.Execution
{
public enum CommandType
{
/// <summary>
/// Unknown command type.
/// </summary>
Unknown = 0,
/// <summary>
/// Shell is a command that will use the host environment shell to
/// execute the command.
/// </summary>
Shell = 1,
/// <summary>
/// DockerREST will use the Docker REST API to execute the command.
/// </summary>
DockerREST = 2
}

}
17 changes: 17 additions & 0 deletions Ductus.FluentDocker/Execution/ICommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Ductus.FluentDocker.Execution
{

public interface ICommand
{
/// <summary>
/// CommandType exposes the type of command.
/// </summary>
CommandType Type { get; }
/// <summary>
/// CommandCategory exposes the category of command.
/// </summary>
/// <value></value>
CommandCategory Category { get; }
}
}

1 change: 1 addition & 0 deletions Examples/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"cSpell.words": [
"Ductus",
"INITDB",
"mysecretpassword"
]
}
28 changes: 28 additions & 0 deletions Examples/Simple/Compose/Sample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.IO;
using Ductus.FluentDocker.Model.Common;
using Ductus.FluentDocker;

namespace Simple.Compose
{
public class Sample
{
public static void Runner()
{

var file = Path.Combine(Directory.GetCurrentDirectory(), (TemplateString)"Resources", "docker-compose.yml");

using (var svc = Fd.UseContainer()
.UseCompose()
.ForceRecreate()
.ServiceName("test-services")
.FromFile(file)
.RemoveOrphans()
.ForceRecreate()
.Build()
.Start())
{

}
}
}
}
43 changes: 43 additions & 0 deletions Examples/Simple/Compose/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
version: '3.4'

services:

zookeeper:
image: confluentinc/cp-zookeeper:5.5.6
container_name: "zookeeper"
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
ports:
- 22181:2181

kafka:
image: confluentinc/cp-kafka:5.5.6
container_name: "kafka"
depends_on:
- zookeeper
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092,PLAINTEXT_HOST://localhost:29092
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
ports:
- 29092:29092

mongodb:
image: mongo:5.0
container_name: "mongodb"
environment:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: MyPassw0rd_123
MONGO_INITDB_DATABASE: broker-messages
volumes:
- mongodata:/data/db
- ./init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
ports:
- "27017:27017"

volumes:
mongodata:
42 changes: 42 additions & 0 deletions Examples/Simple/ExecuteCommandInRunningContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using Ductus.FluentDocker.Commands;
using Ductus.FluentDocker.Builders;

namespace Simple
{
internal class ExecuteCommandInRunningContainer
{
internal static void Runner()
{
using (
var container =
new Builder().UseContainer()
.UseImage("postgres:9.6-alpine")
.ExposePort(5432)
.WithEnvironment("POSTGRES_PASSWORD=mysecretpassword")
.WaitForPort("5432/tcp", 30000)
.Build()
.Start())
{

var config = container.GetConfiguration(true);

// Run the *echo* command inside the running container
var output = container.DockerHost.Execute(
config.Id,
"echo \"I'm inside the container\"",
container.Certificates);

if (output.Data.Contains("I'm inside the container"))
{
Console.WriteLine("The command was executed successfully");
}
else
{
Console.WriteLine("The command was not executed successfully");
}

}
}
}
}
2 changes: 2 additions & 0 deletions Examples/Simple/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ static void Main(string[] args)
//RunSingleContainerFluentAPI();
//PerformanceSingleContainer();
//PerformanceSingleContainerFluentAPI();
//ExecuteCommandInRunningContainer.Runner();
Compose.Sample.Runner();
}
}
}
3 changes: 2 additions & 1 deletion Examples/Simple/Simple.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Ductus.FluentDocker" Version="2.*"/>
<PackageReference Include="Ductus.FluentDocker" Version="2.*" />
<PackageReference Include="MongoDB.Driver" Version="2.13.2" />
</ItemGroup>

</Project>