FluentDocker

Use docker, docker-compose local and remote in tests and your .NET core/full framework apps via a FluentAPI

APACHE-2.0 License

Stars
1.3K
Committers
33

Bot releases are hidden (Show)

FluentDocker - WaitFor custom Lambda Support

Published by mariotoffia about 6 years ago

This release adds a possibility to have one or more custom lambdas to do the wait and thus it is possible to e.g. do a db connection and wait until it succeeds.

For example, it is possible to do this custom action:

      // @formatter:off
      using (new Builder()
                .UseContainer()
                .UseCompose()
                .FromFile(file)
                .RemoveOrphans()
                .Wait("wordpress", (service, cnt) => {
                    if (cnt > 60) throw new FluentDockerException("Failed to wait for wordpress service");
            
                    var res = HttpExtensions.DoRequest("http://localhost:8000/wp-admin/install.php").Result;            
                    return (res.Code == HttpStatusCode.OK && 
                            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);
      }

(this is basically a more cumbersome version of WaitForHttp but it illustrates the point).

Also the container builder now also have the WaitForHttp and Wait (and not only compose).

Cheers,
Mario

FluentDocker - Sudo support

Published by mariotoffia about 6 years ago

This is a experimental release to allow for sudo support on Linux and Mac.

For Linux and Mac users there are several options how to authenticate towards the socket. FluentDocker supports no sudo, sudo without any password (user added as NOPASSWD in /etc/sudoer), or
sudo with password. The default is that FluentDocker expects to be able to talk without any sudo. The options ar global but can be changed in runtime.

     SudoMechanism.None.SetSudo(); // This is the default
     SudoMechanism.Password.SetSudo("<my-sudo-password>");
     SudoMechanism.NoPassword.SetSudo();

This is still experimental and will probably change to e.g SecureString or other in the future.

FluentDocker - New Features on Docker Compose Fluent API

Published by mariotoffia about 6 years ago

This release adds a new Wait method called WaitForHttp. It uses one of HTTP POST, GET, PUT, DELETE with or without body to perform it's wait. In addition it is possible to add a lambda to determine if e.g. responses are OK or if it should abandon wait.

In addition compose fluent API now supports:

  • ExportOnDispose
  • ExportExploadedOnDispose
  • CopyOnStart
  • CopyOnDispose
  • WaitForPort
  • WaitForProcess
  • ExecuteOnRunning
  • ExecuteOnDisposing

In order to use those functions, you have to name the container name and therefore it is possible to address several containers in same compose project. For example it is possible to do e.g. this:

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

      // @formatter:off
      using (new Builder()
                .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())
        // @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);
      }

This example waits until it gets a specific response from the wordpress container. There are a few more in the unit test section.

FluentDocker - Align Ssh API with fluent Machine API

Published by mariotoffia about 6 years ago

Now you can define container or new image directly under the ssh in order to allow for multiple external daemons in same fluent definition.

Also Updated documentation.

FluentDocker - Remote Docker Connection Definition Support

Published by mariotoffia about 6 years ago

It is now possible to define a remote SSH connection to a docker daemon. For example:

using (
        var container =
          new Builder().UseHost()
            .UseSsh("192.168.1.27").WithName("remote-daemon")
            .WithSshUser("solo").WithSshKeyPath("${E_LOCALAPPDATA}/lxss/home/martoffi/.ssh/id_rsa").Host()
            .UseContainer()
            .UseImage("postgres:9.6-alpine")
            .WithEnvironment("POSTGRES_PASSWORD=mysecretpassword")
            .Build())
      {
        Assert.AreEqual(ServiceRunningState.Stopped, container.State);
      }

Creates a remote connection called remote-daemon. It uses WSL on windows, therefore the ssh keypath is in lxx but on Linux and Mac it should be along the lines of ~/.ssh/id_rsa. Please Check the section arount Connecting to Remote Docker Daemons (https://github.com/mariotoffia/FluentDocker#connecting-to-remote-docker-daemons) for more information.

This do address the task #60 as well.

Cheers,
Mario

FluentDocker - Compose Port Bugfix

Published by mariotoffia about 6 years ago

Small bugfix to fix issue #60.

FluentDocker - Bugfix & Small Feature Release

Published by mariotoffia about 6 years ago

This release fixes a few bugs and adds small fetures such as the ability to handle

  • Container Memory Management Options
  • Container Identification Options
  • Block I/O Constraints, Privileged Options
  • Networks settings Options

Added a property on the IContainerService called Image. It reflects the image of the current runtime container.

It also fixes spaces in paths in many places such as docker-compose, mount, working directory etc. It also handles / as neutral path and thus is translated to __ in windows.

Untested docker-compose service where a service is handling docker-compose docker container life-cycle. It also has a fluent API to model up such service. However, it is in alpha and things may change when 3.0.0 is released.

Cheers,
Mario

FluentDocker - Spaces in compose path bug fix

Published by mariotoffia about 6 years ago

This release fixes so it is possible to have spaces in the path to compose files. It also gives the ability to use --memory in docker run commands.

FluentDocker - Logging & Restart Policy

Published by mariotoffia over 6 years ago

This minor release adds the ability hard control if it shall log or not. In addition it supports RestartPolicy when doing a Docker run. The supported policies are

  1. OnFailure
  2. UnlessStopped
  3. Always

Thus it is possible to e.g. do a restart always policy when running:

var cmd = _docker.Run("postgres:9.6-alpine", new ContainerCreateParams
        {
          PortMappings = new[] {"40001:5432"},
          RestartPolicy = RestartPolicy.Always,
          Environment = new[] {"POSTGRES_PASSWORD=mysecretpassword"}
        }, _certificates);

This release is associated with task #49 and #50

FluentDocker - Bugfix and small performance fix

Published by mariotoffia over 6 years ago

This release fixes a bug when discovering already running containers. If such is the case, the handling around disposal is never configured and could result in containers being deleted. It also alters the behavior on Host.Discover where docker machine may be omitted completely by settingpreferNativeDocker = true.

Cheers,
Mario

FluentDocker - Docker exec command support

Published by mariotoffia over 6 years ago

Just a small addition to command to do docker exec.

FluentDocker - Support network in docker run command

Published by mariotoffia over 6 years ago

Minor update to support docker networking (--network) in dock run command.

FluentDocker - GetContainers bug fix

Published by mariotoffia over 6 years ago

This release bugfixes GetContainers where it could possibly do a NPE when a container Id was discovered during the docker ps phase and the docker inspect phase

FluentDocker - Check for errors in docker inspec

Published by mariotoffia over 6 years ago

This is just simple fix where error code is checked in a docker inspect.

FluentDocker - No Color in compose stream

Published by mariotoffia over 6 years ago

The compose stream log can now pass the --no-color option in order to capture pure ASCII without color information.

FluentDocker - Fix of docker compose down

Published by mariotoffia over 6 years ago

This is a simple bugfix release where docker-compose down would on a ImageRemovalOption.All do a --rmi type all but now does --rmi all. This fix was provided by @kroshner.

FluentDocker - Networking & Volumes

Published by mariotoffia over 6 years ago

This release brings docker networking and volumes into the commands and fluent API.

It is now possible to create networks and use those in the containers such as:

    using(var nw = new Builder().UseNetwork("test-network")) 
    {
      using (
        var container =
          new DockerBuilder()
            .WithImage("kiasaki/alpine-postgres")
            .WithEnvironment("POSTGRES_PASSWORD=mysecretpassword")
            .ExposePorts("5432")
            .UseNetwork(nw)
            .WaitForPort("5432/tcp", 30000 /*30s*/)
            .Build())
      {
        container.Create().Start();
      }
    }

The above code snippet creates a new network called test-network and then creates a container that is attached to the test-network. When the Dispose() is called on nw it will remove the network.

In addition volume fluent API can be used such:

      using (var vol = new Builder().UseVolume("test-volume").RemoveOnDispose().Build())
      {
        using (
          var container =
            new Builder().UseContainer()
              .UseImage("postgres:9.6-alpine")
              .WithEnvironment("POSTGRES_PASSWORD=mysecretpassword")
              .MountVolume(vol, "/var/lib/postgresql/data", MountType.ReadWrite)
              .Build()
              .Start())
        {
          var config = container.GetConfiguration();

          Assert.AreEqual(1, config.Mounts.Length);
          Assert.AreEqual("test-volume", config.Mounts[0].Name);
        }
      }

The above sample creates a new volume called test-volume and it is scheduled to be delete when Dispose() is invoked on the IVolumeService. The container is created and mounts the newly created volume to /var/lib/postgresql/data as read/write access mode.
Since the container is within the scope of the using statement of the volume it's lifetime spans the whole container lifetime and then get's deleted.

Happy networking & volumeing ;)

FluentDocker - Docker Networking Support

Published by mariotoffia over 6 years ago

Commands for docker networking is now available. You can create, delete, inspect, discover, attach container, and detatch containers via the commands. The create also support all advanced parameters to e.g. set IPam options etc.

This aloso comes with an enhancement form @megafinz that allows you to wait for a container to properly shut down.

Networking services and fluent API will come in a later release, but the foundation is laid for docker networking using the commands.

FluentDocker - Bugfix in reuse container

Published by mariotoffia over 6 years ago

@megafinz Fixed a bug that caused ReuseIfExist not to work. He also added a better matching using regexp.

FluentDocker - Strong Signed Assemblies

Published by mariotoffia over 6 years ago

The fluent docker assemblies are now signed by default.
Many thanks to @skarllot for this PR.

Badges
Extracted from project README
Quality Gate Status Build status NuGet NuGet NuGet