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

add docker machine support #481

Closed
wants to merge 1 commit into from
Closed
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
111 changes: 80 additions & 31 deletions doc/manual/global-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,64 @@ connection to the Docker host. The corresponding system properties
which can be used to set it from the outside are given in
parentheses.

* **dockerHost** (`docker.host`) Use this variable to specify the URL
to on your Docker Daemon is listening. This plugin requires the
usage of the Docker remote API so this must be enabled. If this
configuration option is not given, the environment variable
`DOCKER_HOST` is evaluated. If this is also not set the plugin will use `unix:///var/run/docker.sock`
as a default. The scheme of this URL can be either given
directly as `http` or `https` depending on whether plain HTTP
communication is enabled or SSL should be used (default since Docker
1.3.0). Alternatively the scheme could be `tcp` in which case the protocol is
determined via the IANA assigned port: 2375 for `http` and 2376 for
`https`. Finally Unix sockets are supported with when a scheme `unix` is used together with the
filesystem path to the unix socket.
* **apiVersion** (`docker.apiVersion`) Use this variable if you are using
an older version of docker not compatible with the current default
use to communicate with the server.
* **certPath** (`docker.certPath`) Since 1.3.0 Docker remote API requires
communication via SSL and authentication with certificates when used
with boot2docker or docker-machine. These
certificates are normally stored
in `~/.docker/`. With this configuration the path can be set
explicitly. If not set, the fallback is first taken from the
environment variable `DOCKER_CERT_PATH` and then as last resort
`~/.docker/`. The keys in this are expected with it standard names
The docker-maven-plugin uses the Docker remote API so the URL of your
Docker Daemon must somehow be specified. The URL can be specified by
the dockerHost or machine configuration, or by the `DOCKER_HOST`
environment variable.

Since 1.3.0, the Docker remote API supports communication via SSL and
authentication with certificates. The path to the certificates can
be specified by the certPath or machine configuration, or by the
`DOCKER_CERT_PATH` environment variable.

* **apiVersion** (`docker.apiVersion`) Use this parameter if you are
using an older version of Docker not compatible with the current
default used to communicate with the server.
* **dockerHost** (`docker.host`)
Use this parameter to directly specify the URL of the Docker Daemon.
If this configuration option is not given, then the **<machine>**
configuration section is consulted.
The scheme of the URL can be either given directly as `http` or `https`
depending on whether plain HTTP communication is enabled or SSL should
be used. Alternatively the scheme could be `tcp` in which case the
protocol is determined via the IANA assigned port: 2375 for `http`
and 2376 for `https`. Finally, Unix sockets are supported by using
the scheme `unix` together with the filesystem path to the unix socket.
The discovery sequence used by the docker-maven-plugin to determine
the URL is:
- value of **dockerHost** (`docker.host`)
- the `DOCKER_HOST` associated with the docker-machine named in **<machine>**.
- the value of the environment variable `DOCKER_HOST`.
- `unix:///var/run/docker.sock` if it a readable socket.
* **certPath** (`docker.certPath`)
Use this parameter to directly specify the directory of SSL
certificates to use when communicating with the Docker daemon.
If this configuration option is not given, then the **<machine>**
configuration section is consulted.
The keys in this directory are expected to have the standard names
`ca.pem`, `cert.pem` and `key.pem`. Please refer to the
[Docker documentation](https://docs.docker.com/articles/https/) for
more information about SSL security with Docker.
more information about SSL security with Docker.
The discovery sequence used by the docker-maven-plugin to determine
the SSL certificate directory is:
- value of **certPath** (`docker.certPath`)
- the `DOCKER_CERT_PATH` associated with the docker-machine named in **<machine>**.
- the value of the environment variable `DOCKER_CERT_PATH`.
- user directory `~/.docker/`
* **machine** Use this configuration section with sub-elements to work
with a docker-machine. The docker-machine executable must be
available in the PATH on the host running the maven build. If the
named docker-machine is not started, it will be started.
* **name** (`docker.machine.name`)
This parameter specifies the name of a docker-machine. The
docker-machine will be queried for the Docker Daemon URL and
certificate path. If **name** is not set, the docker-machine named
'default' will be queried.
* **autoCreate** (`docker.machine.autoCreate`)
Setting this parameter true will create the docker-machine if it
does not exist. If not provided, this parameter will be false.
* **createOptions**
This is the map of name to value pairs used when creating a docker-machine.
* **image** (`docker.image`) In order to temporarily restrict the
operation of plugin goals this configuration option can be
used. Typically this will be set via the system property
Expand All @@ -48,7 +80,7 @@ parentheses.
With this parameter the execution of this plugin can be skipped
completely.
* **skipTags** (`docker.skipTags`)
If set to `true` the plugin won't add any tags to images that have been built.
If set to `true` the docker-maven-plugin won't add any tags to images that have been built.
* **registry** (`docker.registry`)
Specify globally a registry to use for pulling and pushing
images. See [Registry handling](registry-handling.md) for details.
Expand All @@ -62,28 +94,30 @@ parentheses.
during run which has no `<build>` section. Valid values are `on|off|always`.
* **authConfig** holds the authentication information when pulling from
or pushing to Docker registry. There is a dedicated section
[Authentication](#authentication) for how doing security.
[Authentication](authentication.md) for security.
* **logDate** (`docker.logDate`) specifies the date format which is used for printing out
container logs. This configuration can be overwritten by individual
run configurations and described below. The format is described in
[Log configuration](#log-configuration) below.
[Log configuration](docker-start.html#log-configuration).
* **logStdout** (`docker.logStdout`) if set, do all container logging to standard output,
regardless whether a `file` for log output is specified. See also [Log configuration](#log-configuration)
regardless whether a `file` for log output is specified. See also
[Log configuration](docker-start.html#log-configuration)
* **portPropertyFile** if given, specifies a global file into which the
mapped properties should be written to. The format of this file and
its purpose are also described in [Port Mapping](#port-mapping).
its purpose are also described in [Port Mapping](docker-start.html#port-mapping).
* **sourceDirectory** (`docker.source.dir`) specifies the default directory that contains
the assembly descriptor(s) used by the plugin. The default value is `src/main/docker`. This
option is only relevant for the `docker:build` goal.
* **outputDirectory** (`docker.target.dir`) specifies the default output directory to be
used by the plugin. The default value is `target/docker` and is only used for the goal `docker:build`.
used by docker-maven-plugin. The default value is `target/docker` and is only used for the goal `docker:build`.
* **maxConnections** (`docker.maxConnections`) specifies how many parallel connections are allowed to be opened
to the Docker Host. For parsing log output, a connection needs to be kept open (as well for the wait features),
so don't put that number to low. Default is 100 which should be suitable for most of the cases.

Example:
Examples:

````xml
<!-- directly configure communication with daemon -->
<configuration>
<dockerHost>https://localhost:2376</dockerHost>
<certPath>src/main/dockerCerts</certPath>
Expand All @@ -92,3 +126,18 @@ Example:
</configuration>
````


````xml
<!-- work with a docker-machine -->
<configuration>
<machine>
<autoCreate>true</autoCreate>
<createOptions>
<driver>virtualbox</driver>
<virtualbox-cpu-count>2</virtualbox-cpu-count>
</createOptions>
</machine>
.....
</configuration>
````

10 changes: 8 additions & 2 deletions samples/cargo-jolokia-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@
<parent>
<groupId>io.fabric8</groupId>
<artifactId>dmp-sample-parent</artifactId>
<version>0.15-SNAPSHOT</version>
<version>0.15.7</version>
<relativePath>../pom.xml</relativePath>
</parent>

<groupId>io.fabric8</groupId>
<artifactId>cargo-jolokia-demo</artifactId>
<version>0.15-SNAPSHOT</version>

<url>http://www.jolokia.org</url>

Expand Down Expand Up @@ -78,6 +77,13 @@
<version>${project.version}</version>
<extensions>true</extensions>
<configuration>
<machine>
<autoCreate>true</autoCreate>
<createOptions>
<virtualbox-memory>10000</virtualbox-memory>
<virtualbox-no-share></virtualbox-no-share>
</createOptions>
</machine>
<images>
<image>
<name>${image}</name>
Expand Down
8 changes: 6 additions & 2 deletions samples/data-jolokia-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

<groupId>io.fabric8</groupId>
<artifactId>docker-jolokia-demo</artifactId>
<version>0.15.7</version>
<!-- add custom lifecycle -->
<packaging>docker</packaging>

Expand Down Expand Up @@ -83,9 +82,14 @@
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>${project.version}</version>
<extensions>true</extensions> <!-- enables using 'docker' packaging above -->
<configuration>
<machine>
<createOptions>
<driver>virtualbox</driver>
</createOptions>
</machine>

<watchInterval>500</watchInterval>
<logDate>default</logDate>
<verbose>true</verbose>
Expand Down
2 changes: 1 addition & 1 deletion samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<url>http://www.jolokia.org</url>

<properties>
<docker.maven.plugin.version>${project.version}</docker.maven.plugin.version>
<docker.maven.plugin.version>0.15-SNAPSHOT</docker.maven.plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import io.fabric8.maven.docker.service.ServiceHub;
import io.fabric8.maven.docker.util.*;
import org.apache.maven.archiver.MavenArchiveConfiguration;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
Expand All @@ -36,9 +35,6 @@ abstract public class AbstractBuildSupportMojo extends AbstractDockerMojo {
@Parameter
private MavenArchiveConfiguration archive;

@Parameter(defaultValue = "${session}", readonly = true)
protected MavenSession session;

@Component
private MavenFileFilter mavenFileFilter;

Expand Down
30 changes: 27 additions & 3 deletions src/main/java/io/fabric8/maven/docker/AbstractDockerMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.codehaus.plexus.context.ContextException;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
import io.fabric8.maven.docker.config.ImageConfiguration;
import io.fabric8.maven.docker.config.MachineConfiguration;
import io.fabric8.maven.docker.config.handler.ImageConfigResolver;
import io.fabric8.maven.docker.log.LogDispatcher;
import io.fabric8.maven.docker.log.LogOutputSpecFactory;
Expand Down Expand Up @@ -67,9 +68,13 @@ public abstract class AbstractDockerMojo extends AbstractMojo implements Context
protected Settings settings;

// Current maven project
@Parameter(defaultValue= "${session}", readonly = true)
@Parameter(property= "session")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this change important ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not an important change. Aligned with latest recommended practice.

Chas

On Jun 26, 2016, at 6:29 PM, Roland Huß notifications@github.com wrote:

In src/main/java/io/fabric8/maven/docker/AbstractDockerMojo.java:

@@ -67,9 +68,13 @@
protected Settings settings;

 // Current maven project
  • @parameter(defaultValue= "${session}", readonly = true)
  • @parameter(property= "session")
    Why is this change important ?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, looks cleaner. will probably align the other usages, too.

protected MavenSession session;

// Current mojo execution
@Parameter(property= "mojoExecution")
protected MojoExecution execution;

// Handler for external configurations
@Component
protected ImageConfigResolver imageConfigResolver;
Expand Down Expand Up @@ -150,6 +155,10 @@ public abstract class AbstractDockerMojo extends AbstractMojo implements Context
@Parameter
private List<ImageConfiguration> images;

// Docker-machine configuration
@Parameter
private MachineConfiguration machine;

// Images resolved with external image resolvers and hooks for subclass to
// mangle the image configurations.
private List<ImageConfiguration> resolvedImages;
Expand Down Expand Up @@ -240,11 +249,26 @@ private void storeInPluginContext(List<ImageConfiguration> resolvedImages, Strin
private DockerAccess createDockerAccess(String minimalVersion) throws MojoExecutionException, MojoFailureException {
DockerAccess access = null;
if (isDockerAccessRequired()) {
String dockerUrl = EnvUtil.extractUrl(dockerHost);
boolean isDefaults = machine == null;
if (isDefaults) {
// create instance to resolve system defines
// docker.machine.name and docker.machine.autoCreate
machine = new MachineConfiguration();
}
isDefaults &= machine.resolveDefines(new PluginParameterExpressionEvaluator(session, execution), getLog());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is is needed to do an extras property resolve step here ?

For all other configurations we simply rely on Maven to have the properties resolved before injecting it into the Plugin via @Parameter. Using the same scheme here would make things much simpler.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was unable to get injection framework to provide default values for embedded instances. I'd love to be shown how to do this correctly.

Chas

On Jun 26, 2016, at 6:31 PM, Roland Huß notifications@github.com wrote:

In src/main/java/io/fabric8/maven/docker/AbstractDockerMojo.java:

@@ -240,11 +249,26 @@ private void storeInPluginContext(List resolvedImages, Strin
private DockerAccess createDockerAccess(String minimalVersion) throws MojoExecutionException, MojoFailureException {
DockerAccess access = null;
if (isDockerAccessRequired()) {

  •        String dockerUrl = EnvUtil.extractUrl(dockerHost);
    
  •        boolean isDefaults = machine == null;
    
  •        if (isDefaults) {
    
  •            // create instance to resolve system defines
    
  •            // docker.machine.name and docker.machine.autoCreate
    
  •            machine = new MachineConfiguration();
    
  •        }
    
  •        isDefaults &= machine.resolveDefines(new PluginParameterExpressionEvaluator(session, execution), getLog());
    
    Why is is needed to do an extras property resolve step here ?

For all other configurations we simply rely on Maven to have the properties resolved before injecting it into the Plugin via @parameter. Using the same scheme here would make things much simpler.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats true, for deeper configuration objects @parameter is ignored. I used therefor plain field initializers and a constructor to feed the two properties from the outside when the configuration is created because of setting the property. Please look into AbstractDockerMojo how this is resolved.

log.debug(machine.toString());
if (isDefaults) {
// if no <machine> configuration and no system defines, do not
// use docker-machine
machine = null;
}

DockerMachine dockerMachine = new DockerMachine(log, machine);
String dockerUrl = dockerMachine.extractUrl(dockerHost);
try {
String version = minimalVersion != null ? minimalVersion : API_VERSION;
access = new DockerAccessWithHcClient("v" + version, dockerUrl,
EnvUtil.getCertPath(certPath), maxConnections, log);
dockerMachine.getCertPath(certPath), maxConnections, log);
access.start();
setDockerHostAddressProperty(dockerUrl);
}
Expand Down
Loading