ComposeBuilderDotNet 1.0.4

The goal of this project is to generate docker-compose literate YAML in C# using the builder design pattern

Install-Package ComposeBuilderDotNet -Version 1.0.4
dotnet add package ComposeBuilderDotNet --version 1.0.4
<PackageReference Include="ComposeBuilderDotNet" Version="1.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ComposeBuilderDotNet --version 1.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ComposeBuilderDotNet, 1.0.4"
For F# scripts that support #r syntax, copy this into the source code to reference the package.

ComposeBuilderDotNet

The Goal

The goal of this project is to generate docker-compose literate YAML in C# using the builder design pattern

About ComposeBuilderDotNet

This project was inspired by The need to create dynamically generated docker-compose files the right way,
without using templates and replacement techniques; as well as providing a wide range of developer friendly
methods and enums for quick access without the need to constantly check documentation.

Example Code

var dbUser = "root";
var dbPass = "pass";
var dbName = "wordpress"; 

var network1 = Builder.MakeNetwork("my-net")
    .SetExternal(true)                       
    .Build();

var network2 = Builder.MakeNetwork("my-net2") 
    .Build();

var mysql = Builder.MakeService("db")
    .WithImage("mysql:5.7")
    .WithNetworks(network1)
    .WithExposed("3306") 
    .WithEnvironment(mb => mb
        .WithProperty("MYSQL_ROOT_PASSWORD", dbPass)
        .WithProperty("MYSQL_DATABASE", dbName)
        .WithProperty("MYSQL_USER", dbUser)
        .WithProperty("MYSQL_PASSWORD", dbPass)
    )
    .WithRestartPolicy(ERestartMode.Always) 
    .WithSwarm()
    .WithDeploy(d => d
        .WithMode(EReplicationMode.Replicated)
        .WithReplicas(3))
    .Build();

var wordpress = Builder.MakeService("wordpress")
    .WithImage("wordpress:latest")
    .WithNetworks(network1, network2)
    .WithPortMapping("8000:80") 
    .WithEnvironment(mb => mb
        .WithProperty("WORDPRESS_DB_HOST", $"{mysql.Name}:3306")
        .WithProperty("WORDPRESS_DB_USER", dbUser)
        .WithProperty("WORDPRESS_DB_PASSWORD", dbPass)
        .WithProperty("WORDPRESS_DB_NAME", dbName)
    )
    .WithDependencies(mysql) 
    .WithRestartPolicy(ERestartMode.UnlessStopped) 
    .WithSwarm()
    .WithDeploy(d => d
        .WithMode(EReplicationMode.Global) 
    )
    .Build();

var compose = Builder.MakeCompose()
    .WithServices(mysql, wordpress)
    .WithNetworks(network1, network2)
    .Build();

// serialize our object graph to yaml for writing to a docker-compose file
var result = compose.Serialize();

ComposeBuilderDotNet

The Goal

The goal of this project is to generate docker-compose literate YAML in C# using the builder design pattern

About ComposeBuilderDotNet

This project was inspired by The need to create dynamically generated docker-compose files the right way,
without using templates and replacement techniques; as well as providing a wide range of developer friendly
methods and enums for quick access without the need to constantly check documentation.

Example Code

var dbUser = "root";
var dbPass = "pass";
var dbName = "wordpress"; 

var network1 = Builder.MakeNetwork("my-net")
    .SetExternal(true)                       
    .Build();

var network2 = Builder.MakeNetwork("my-net2") 
    .Build();

var mysql = Builder.MakeService("db")
    .WithImage("mysql:5.7")
    .WithNetworks(network1)
    .WithExposed("3306") 
    .WithEnvironment(mb => mb
        .WithProperty("MYSQL_ROOT_PASSWORD", dbPass)
        .WithProperty("MYSQL_DATABASE", dbName)
        .WithProperty("MYSQL_USER", dbUser)
        .WithProperty("MYSQL_PASSWORD", dbPass)
    )
    .WithRestartPolicy(ERestartMode.Always) 
    .WithSwarm()
    .WithDeploy(d => d
        .WithMode(EReplicationMode.Replicated)
        .WithReplicas(3))
    .Build();

var wordpress = Builder.MakeService("wordpress")
    .WithImage("wordpress:latest")
    .WithNetworks(network1, network2)
    .WithPortMapping("8000:80") 
    .WithEnvironment(mb => mb
        .WithProperty("WORDPRESS_DB_HOST", $"{mysql.Name}:3306")
        .WithProperty("WORDPRESS_DB_USER", dbUser)
        .WithProperty("WORDPRESS_DB_PASSWORD", dbPass)
        .WithProperty("WORDPRESS_DB_NAME", dbName)
    )
    .WithDependencies(mysql) 
    .WithRestartPolicy(ERestartMode.UnlessStopped) 
    .WithSwarm()
    .WithDeploy(d => d
        .WithMode(EReplicationMode.Global) 
    )
    .Build();

var compose = Builder.MakeCompose()
    .WithServices(mysql, wordpress)
    .WithNetworks(network1, network2)
    .Build();

// serialize our object graph to yaml for writing to a docker-compose file
var result = compose.Serialize();

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.4 401 12/5/2019
1.0.3 173 12/5/2019
1.0.2 946 12/3/2019