spotify/docker-maven-plugin — pull request #41 by dflemstr (2014-11-20 13:12:01+00:00)
Title: Packaging docker

The `docker-maven-plugin` is not a Maven plugin; it is a plugin that changes the way an application is packaged. The artifact of a project that uses the plugin should thus not be a `jar`, but rather a Docker image. This pull request implements that functionality.

The idea is that your `pom.xml` should look like this:

```xml

docker

com.spotify
docker-maven-plugin
...
true

```

Note that the packaging is not `jar`, but `docker`. The `true` is what lets the `docker-maven-plugin` register a new packaging type.

What this does is that it changes the lifecycle of the project somewhat. The `jar:jar` goal is no longer run in the `package` phase; instead it is in `prepare-package`. The `docker:build` goal is run in `package` instead. In the `deploy` phase, in addition to `deploy:deploy`, the `docker:push` goal is also run.

This means that:

- `mvn prepare-package` just creates the JAR
- `mvn package` creates a Docker image and puts the JAR in it
- `mvn deploy` pushes the Docker image to the registry

Of course, you can't deploy a Docker image to a Maven repository like Artifactory or Nexus. Instead, the plugin now generates a JAR `foobar-1.0.0-docker.jar` that contains the file `META-INF/docker///image-info.json`. This is the main artifact of the project and will be deployed to the Maven repository.

The advantage of this is that you can now (in a separate project for example) depend on this artifact like so:

```xml

com.spotify
foobar
...
docker

```

Support can then be added in `helios-testing` for looking up Docker images by group and artifact ID. The library can simply look in `/META-INF/docker/...` on the classpath.

---

I also added integration tests for the new behavior and the old. Look at `src/it/`; each sub-folder is a Maven project with sample configuration. It would be nice to extend this test suite with more projects!

@rculbertson @danielnorberg