Git Product home page Git Product logo

dockerprocessapi's Introduction

DockerProcessAPI

A Java API that makes it easy to issue local docker and docker-compose commands programatically. This assumes that the machine in which this runs can issue a 'docker ps' and a 'docker-compose version' from a normal command line (not from within a docker-machine).

If your installation requires a docker-machine (e.g. you have a mac or a windows machine without Hyper-V / Docker capabilities), then you should use the Spotify docker-client that uses the Docker Remote API.

Typical Use Cases

  • Integration testing - Use DockerProcessAPI to bring up external services and products your application needs and shut down those products after your tests are over.

Usage Notes

A full example can be found here. Note that this example utilizes @BeforeClass and @AfterClass methods to place logic to bring up an instance of RabbitMQ for integration test cases and shut them down after the tests complete.

Docker Examples

Docker-Compose Examples

Pull a Docker Image

Issues 'docker pull'.

Example usage:

import guru.breakthemonolith.docker.DockerCommandUtils;

DockerCommandUtils.dockerPull("hello-world");

List Active Docker Containers

Issues 'docker ps'.

All output will appear in the log under the logger name 'DockerProcessAPI'.

Example usage:

import guru.breakthemonolith.docker.DockerCommandUtils;

DockerCommandUtils.dockerContainerListing();

Run Docker Image

Issues 'docker run'.

Docker images can be run instream or dispatched. If the docker image is run instream, the image will be run in a blocking fashion and the image run will complete before control is returned to the caller. If the image is dispatched, control will be returned after a period of time suitable for the container to have completed it's start-up sequence and be ready for use.

You specify run attributes by using class DockerRunSpecification. You specify the image name any port mappings, volume mappings, or environment mappings and whether the run is instread or dispatched. If the run is dispatched (run asynchronously), then you can specify how long the container is given to complete its start sequence (default is 3 seconds).

Example usage for dispatched execution:

import guru.breakthemonolith.docker.DockerCommandUtils;
import guru.breakthemonolith.docker.DockerRunSpecification;

DockerRunSpecification runSpec = new DockerRunSpecification("rabbitmq:latest");
runSpec.getPortMap().put(address.getHostAddress() + ":6000", "5672");
runSpec.setDetachedWaitTimeMillis(5000);

rabbitMQContainerName = DockerCommandUtils.dockerRun(runSpec);

... // testing happens here

DockerCommandUtils.dockerKillContainer(rabbitMQContainerName);

Kill Docker Container

Issues 'docker kill'.

Example usage:

import guru.breakthemonolith.docker.DockerCommandUtils;

DockerCommandUtils.dockerKillContainer(rabbitMQContainerName);

Obtain log output from a running Docker Container

Issues 'docker logs --details'.

Example usage:

import guru.breakthemonolith.docker.DockerCommandUtils;

DockerCommandUtils.dockerLogContainer(rabbitMQContainerName);

Bring up docker compose environment

Issues 'docker-compose up -d'.

Example usage:

import guru.breakthemonolith.docker.ComposeCommandUtils;
import guru.breakthemonolith.docker.DockerComposeConfiguration;

ComposeCommandUtils.composeUp(new DockerComposeConfiguration("myEnvironment.yml"));

Shutdown docker compose environment

Issues 'docker-compose down'.

Example usage:

import guru.breakthemonolith.docker.ComposeCommandUtils;
import guru.breakthemonolith.docker.DockerComposeConfiguration;

ComposeCommandUtils.composeDown(new DockerComposeConfiguration("myEnvironment.yml"));

Log running docker compose environments

Issues 'docker-compose ps'.

Example usage:

import guru.breakthemonolith.docker.ComposeCommandUtils;
import guru.breakthemonolith.docker.DockerComposeConfiguration;

ComposeCommandUtils.composeListing(new DockerComposeConfiguration("myEnvironment.yml"));

Log a specific docker compose configuration

Issues 'docker-compose config'.

Example usage:

import guru.breakthemonolith.docker.ComposeCommandUtils;
import guru.breakthemonolith.docker.DockerComposeConfiguration;

ComposeCommandUtils.composeConfig(new DockerComposeConfiguration("myEnvironment.yml"));

Log output from docker-compose logs

Issues 'docker-compose logs'.

Example usage:

import guru.breakthemonolith.docker.ComposeCommandUtils;
import guru.breakthemonolith.docker.DockerComposeConfiguration;

ComposeCommandUtils.composeLogs(new DockerComposeConfiguration("myEnvironment.yml"));

Reporting Issues

Please report any problems and issues here

System Requirements

  • Java JDK 1.7 or later
  • Linux operating system or Windows 10 Pro or Enterprise with Hyper-V functioning with Docker
  • Docker and docker-compose should be installed and functioning.

Installation

Maven users can find dependency information here.

To install, you need to include the following dependent libraries in your classpath:

  • org.force66 / ValueObjectBase
  • org.apache.commons / commons-lang3
  • commons-io / commons-io
  • org.slf4j / slf4j-api

dockerprocessapi's People

Contributors

derek-ashmore avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.