Skip to content

Commit

Permalink
Merge release branch for v1.2
Browse files Browse the repository at this point in the history
Summary of changes:
- Docker Remote API support
- addFile fixes
- Base image for Java 8 and fixes
- External Dockerfile support
- Gradle 2.0 compatibility
- Image tag version and fixes
  • Loading branch information
mattgruter committed Jul 27, 2014
2 parents cc13962 + 7f18644 commit 3da20d5
Show file tree
Hide file tree
Showing 26 changed files with 862 additions and 138 deletions.
36 changes: 36 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,45 @@
# Changelog

## Version 1.2 (2014-07-28)

#### Docker Remote API
It is now possible to use the Docker Remote API instead of the `docker` command line tool. See the [docs](README.md#docker-remote-api) for more information (PR #10). This is particularly useful for users who do not have Docker installed locally.

#### addFile
* Fixed `addFile` accepting a copySpec as an argument (issue #4).
* `addFile` now accepts the destination path as an optional second argument (default: `/`)

#### Base image
* Fixed setting of a custom base image both through the plugin extension or a task property (issue #11).
* Fixed default base image detection based on project's `targetCompatibility`.
* Added default base image for Java 8 (PR #9).

#### External Dockerfile
* Supply an external Dockerfile instead of defining it in the build script. See the [docs](README.md#building-your-dockerfile) (issue #13).
* Mix and match loading external Dockerfiles and extending in the build script.

#### Gradle 2.0
The plugin is now compatible with Gradle 2.0 (see the [docs](README.md#note-to-gradle-1.x-users) if you are using Gradle 1.x)

#### Image tagging
* Possible to set docker image tag version to something else than *:latest* (PR #5).
* Fixed setting of the image tag name and version (issue #15).

Many thanks to the contributors

* [@aglover](https://github.com/aglover)
* [@Teudimundo](https://github.com/Teudimundo)
* [@sfitts](https://github.com/sfitts)
* [@frvi](https://github.com/frvi)
* [@mattgruter](https://github.com/mattgruter)


## Version 1.1.1 (2014-06-13)
* Possible to build without specifying group.
* Failing gradle build if Docker execution fails.

Many thanks to the contributors:

* [@Teudimundo](https://github.com/Teudimundo)
* [@frvi](https://github.com/frvi)

Expand All @@ -20,6 +55,7 @@ Many thanks to the contributors:
* Fixed path seperator bug for integration testing on Windows.

Many thanks to the contributors:

* [@sfitts](https://github.com/sfitts)
* [@kernel164](https://github.com/kernel164)
* [@nicarlsson](https://github.com/nicarlsson)
Expand Down
77 changes: 65 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

This plugin for [Gradle](http://www.gradle.org/) adds the capability to build und publish [Docker](http://docker.io/) images from the build script.

See the [change log](CHANGELOG.md) for information about the latest changes.

## Extending the application plugin
The gradle-docker plugin adds a task `distDocker` if the project already has the [application plugin](http://www.gradle.org/docs/current/userguide/application_plugin.html) applied:

Expand All @@ -16,21 +18,21 @@ Executing the `distDocker` task builds a docker image containing all application

By default `distDocker` uses a base image with a Java runtime according to the project's `targetCompatibility` property. The docker image entry point is set to the start script created by the application plugin. Checkout the [example](example/) project.

*Note: Only JVM based projects are supported.*
**Note**: The creation of the convention task `distDocker` is currently only supported for JVM based application projects. If you are not using a JVM based application, use the task type `Docker` directly to create a task to build Docker images of your application.


## Stand-alone
The docker plugin introduces the task type `Docker`. A task of this type can be used to build Docker images. See the [Dockerfile documentation](http://docs.docker.com/reference/builder/) for information about how docker containers are built.
## The `Docker`task
The docker plugin introduces the task type `Docker`. A task of this type can be used to build and publish Docker images. See the [Dockerfile documentation](http://docs.docker.com/reference/builder/) for information about how Docker images are built.

The following example builds a docker image for the popular reverse proxy nginx. The image will be tagged with the name `foo/nginx`. The example is taken from the official Dockerfile [examples](http://docs.docker.com/reference/builder/#dockerfile-examples):
In the following example we build a Docker image in our Gradle build script for the popular reverse proxy nginx. The image will be tagged with the name `foo/nginx`. The example is taken from the official Dockerfile [examples](http://docs.docker.com/reference/builder/#dockerfile-examples):

```gradle
apply plugin: 'docker'
buildscript {
repositories { jcenter() }
dependencies {
classpath 'se.transmode.gradle:gradle-docker:1.1.1'
classpath 'se.transmode.gradle:gradle-docker:1.2'
}
}
Expand All @@ -49,8 +51,15 @@ task nginxDocker(type: Docker) {
}
```

## Building your Dockerfile
In the example above the instructions on how to build the nginx Docker image are configured **inline** using methods of the Docker Gradle task. During task execution the plugin first creates a [Dockerfile](https://docs.docker.com/reference/builder/) which it then passes to Docker to build the image.

However instead of defining the build instructions inline in the task it is possible to supply an **external Dockerfile**. If the task property `dockerfile` is set to the path of an existing Dockerfile the plugin will this instead of build the image.

You can even combine these two methods: Supplying an external Dockerfile and extending it by defining instructions in the task. The build instructions from the external Dockerfile are read first and the instructions defined in the task appended. If an external Dockerfile is supplied, the `baseImage` property is ignored.

## Configuring the plugin
The plugin exposes configuration options on 2 levels: globally through a plugin extension and on a per task basis. The plugin tries to always set sensible defaults for all properties. (The `maintainer` property is an exception. It is initialized with a useless default string.)
The plugin exposes configuration options on 2 levels: globally through a plugin extension and on a per task basis. The plugin tries to always set sensible defaults for all properties.

### Global configuration through plugin extension properties
Configuration properties in the plugin extension `docker` are applied to all Docker tasks. Available properties are:
Expand All @@ -59,6 +68,7 @@ Configuration properties in the plugin extension `docker` are applied to all Doc
- `baseImage` - The base docker image used when building images (i.e. the name after `FROM` in the Dockerfile).
- `maintainer` - The name and email address of the image maintainer.
- `registry` - The hostname and port of the Docker image registry unless the official Docker index is used.
- `useApi` - Use the Docker Remote API instead of a locally installed `docker` binary. See [below](https://github.com/Transmode/gradle-docker/blob/master/README.md#docker-remote-api)

Example to set the base docker image and maintainer name for all tasks:

Expand All @@ -79,9 +89,9 @@ tag = "${project.group}/${applicationName}:${tagVersion}"

Where:

- `project.group` -- This is a standard Gradle project property. If not defined, the `{project.group}/` is omitted.
- `applicationName` -- The name of the application being "dockerized".
- `tagVersion` -- Optional version name added to the image tag name.
- `project.group` - This is a standard Gradle project property. If not defined, the `{project.group}/` is omitted.
- `applicationName` - The name of the application being "dockerized".
- `tagVersion` - Optional version name added to the image tag name. Defaults to `project.version` or "latest" if `project.version` is unspecified.

The following example task will tag the docker image as `org.acme/bar:13.0`:

Expand All @@ -98,8 +108,51 @@ task fooDocker(type: Docker) {
### A note about base images ###
If no base image is configured through the extension or task property a suitable image is chosen based on the project's `targetCompatibility`. A project targeting Java 7 will for instance get a default base image with a Java 7 runtime.

## Docker Remote API
By default the plug-in will use the `docker` command line tool to execute any docker commands (such as `build` and `push`). However, it can be configured to use the [Docker Remote API](https://docs.docker.com/reference/api/docker_remote_api/) instead via the `useApi` extension property:

```gradle
docker {
useApi true
}
```

Use of the remote API requires that the Docker server be configured to listen over HTTP and that it have support for version 1.11 of the API (connecting over Unix Domain sockets is not supported yet). The following configuration options are available:

* `hostUrl` - set the URL used to contact the Docker server. Defaults to `http://localhost:2375`
* `apiUsername` - set the username used to authenticate the user with the Docker server. Defaults to `nil` which means no authentication is performed.
* `apiPassword` - set the password used to authenticate the user with the Docker server.
* `apiEmail` - set the user's email used to authenticate the user with the Docker server.

For example:

```gradle
docker {
useApi true
hostUrl 'http://myserver:4243`
apiUsername 'user'
apiPassword 'password'
apiEmail 'me@mycompany.com'
}
```


## Requirements
* Gradle 1.10
* Docker 0.6+
* Gradle 2.x
* Docker 0.11+

#### Note to Gradle 1.x users
The plugin is built with Gradle 2.x and thus needs version 2.0 or higher to work due to a newer version of Groovy version included in Gradle 2.x (2.3 vs. 1.8.6). To use the plugin with Gradle 1.x you have to add Groovy's upward compatibility patch by adding the following line to your build file:

```gradle
buildscript {
// ...
dependencies {
classpath 'se.transmode.gradle:gradle-docker:1.2'
classpath 'org.codehaus.groovy:groovy-backports-compat23:2.3.5'
}
}
```

You need to have docker installed in order to build docker images. However if the `dryRun` task property is set to `true` all calls to docker are disabled. In that case only the Dockerfile and its context directory will be created.
#### Note to native docker client users
If you are not using Docker's remote API (`useApi = false`, i.e. the default behaviour) you need to have Docker installed locally in order to build images. However if the `dryRun` task property is set to `true` all calls to Docker are disabled. In that case only the Dockerfile and its context directory will be created.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ configurations {
dependencies {
compile gradleApi()
compile localGroovy()
compile 'com.google.guava:guava:17.0'

compile 'com.google.guava:guava:17.0'
compile 'com.github.docker-java:docker-java:0.9.0'

testCompile 'junit:junit-dep:4.11'
testCompile 'org.hamcrest:hamcrest-all:1.3'
Expand Down
8 changes: 6 additions & 2 deletions examples/application/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@ apply plugin: 'application'
apply plugin: 'docker'

buildscript {
repositories { jcenter() }
repositories { mavenLocal(); jcenter() }
dependencies {
classpath 'se.transmode.gradle:gradle-docker:1.2'
}
}

task wrapper(type: Wrapper) {
gradleVersion = '2.0'
}

sourceCompatibility = 1.7
group = 'example'
version = '1.0'
mainClassName = 'se.transmode.example.docker.JettyMain'

repositories { mavenCentral() }
repositories { jcenter() }
dependencies {
compile 'org.eclipse.jetty.aggregate:jetty-all:9.0.6.v20130930'
}
Expand Down
Binary file modified examples/application/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions examples/application/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Oct 29 23:01:20 CET 2013
#Sat Jul 26 09:30:47 CEST 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.0-bin.zip
90 changes: 90 additions & 0 deletions examples/application/gradlew.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################

@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto init

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:init
@rem Get command-line arguments, handling Windowz variants

if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args

:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2

:win9xME_args_slurp
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*
goto execute

:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1

:mainEnd
if "%OS%"=="Windows_NT" endlocal

:omega
17 changes: 16 additions & 1 deletion examples/simple/build.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
apply plugin: 'docker'

buildscript {
repositories { jCentral() }
repositories { mavenLocal(); jcenter() }
dependencies {
classpath 'se.transmode.gradle:gradle-docker:1.2'
}
}

task wrapper(type: Wrapper) {
gradleVersion = '2.0'
}

group = 'org.acme'

docker {
maintainer = 'Victor Vieux <victor@docker.com>'
}

task nginxDocker(type: Docker) {
// The default image tag contains the applicationName
applicationName = 'nginx'

// Dockerfile instruction 'RUN'
runCommand 'echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list'
runCommand "apt-get update"
runCommand "apt-get install -y inotify-tools nginx apache2 openssh-server"

/* addFile accepts copySpec closure (like project.copy)
The source files are added to a tar archive which is then copied
into the image using the Dockerfile 'ADD' instruction. */
addFile {
from 'input'
into 'docs'
}
}
Binary file modified examples/simple/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions examples/simple/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Oct 29 23:01:20 CET 2013
#Sat Jul 26 09:25:24 CEST 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.0-bin.zip
Loading

0 comments on commit 3da20d5

Please sign in to comment.