Skip to content

Commit 3da20d5

Browse files
committed
Merge release branch for v1.2
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
2 parents cc13962 + 7f18644 commit 3da20d5

File tree

26 files changed

+862
-138
lines changed

26 files changed

+862
-138
lines changed

CHANGELOG.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,45 @@
11
# Changelog
22

3+
## Version 1.2 (2014-07-28)
4+
5+
#### Docker Remote API
6+
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.
7+
8+
#### addFile
9+
* Fixed `addFile` accepting a copySpec as an argument (issue #4).
10+
* `addFile` now accepts the destination path as an optional second argument (default: `/`)
11+
12+
#### Base image
13+
* Fixed setting of a custom base image both through the plugin extension or a task property (issue #11).
14+
* Fixed default base image detection based on project's `targetCompatibility`.
15+
* Added default base image for Java 8 (PR #9).
16+
17+
#### External Dockerfile
18+
* Supply an external Dockerfile instead of defining it in the build script. See the [docs](README.md#building-your-dockerfile) (issue #13).
19+
* Mix and match loading external Dockerfiles and extending in the build script.
20+
21+
#### Gradle 2.0
22+
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)
23+
24+
#### Image tagging
25+
* Possible to set docker image tag version to something else than *:latest* (PR #5).
26+
* Fixed setting of the image tag name and version (issue #15).
27+
28+
Many thanks to the contributors
29+
30+
* [@aglover](https://github.com/aglover)
31+
* [@Teudimundo](https://github.com/Teudimundo)
32+
* [@sfitts](https://github.com/sfitts)
33+
* [@frvi](https://github.com/frvi)
34+
* [@mattgruter](https://github.com/mattgruter)
35+
36+
337
## Version 1.1.1 (2014-06-13)
438
* Possible to build without specifying group.
539
* Failing gradle build if Docker execution fails.
640

741
Many thanks to the contributors:
42+
843
* [@Teudimundo](https://github.com/Teudimundo)
944
* [@frvi](https://github.com/frvi)
1045

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

2257
Many thanks to the contributors:
58+
2359
* [@sfitts](https://github.com/sfitts)
2460
* [@kernel164](https://github.com/kernel164)
2561
* [@nicarlsson](https://github.com/nicarlsson)

README.md

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

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

7+
See the [change log](CHANGELOG.md) for information about the latest changes.
8+
79
## Extending the application plugin
810
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:
911

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

1719
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.
1820

19-
*Note: Only JVM based projects are supported.*
21+
**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.
2022

2123

22-
## Stand-alone
23-
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.
24+
## The `Docker`task
25+
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.
2426

25-
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):
27+
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):
2628

2729
```gradle
2830
apply plugin: 'docker'
2931
3032
buildscript {
3133
repositories { jcenter() }
3234
dependencies {
33-
classpath 'se.transmode.gradle:gradle-docker:1.1.1'
35+
classpath 'se.transmode.gradle:gradle-docker:1.2'
3436
}
3537
}
3638
@@ -49,8 +51,15 @@ task nginxDocker(type: Docker) {
4951
}
5052
```
5153

54+
## Building your Dockerfile
55+
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.
56+
57+
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.
58+
59+
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.
60+
5261
## Configuring the plugin
53-
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.)
62+
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.
5463

5564
### Global configuration through plugin extension properties
5665
Configuration properties in the plugin extension `docker` are applied to all Docker tasks. Available properties are:
@@ -59,6 +68,7 @@ Configuration properties in the plugin extension `docker` are applied to all Doc
5968
- `baseImage` - The base docker image used when building images (i.e. the name after `FROM` in the Dockerfile).
6069
- `maintainer` - The name and email address of the image maintainer.
6170
- `registry` - The hostname and port of the Docker image registry unless the official Docker index is used.
71+
- `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)
6272

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

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

8090
Where:
8191

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

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

@@ -98,8 +108,51 @@ task fooDocker(type: Docker) {
98108
### A note about base images ###
99109
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.
100110

111+
## Docker Remote API
112+
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:
113+
114+
```gradle
115+
docker {
116+
useApi true
117+
}
118+
```
119+
120+
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:
121+
122+
* `hostUrl` - set the URL used to contact the Docker server. Defaults to `http://localhost:2375`
123+
* `apiUsername` - set the username used to authenticate the user with the Docker server. Defaults to `nil` which means no authentication is performed.
124+
* `apiPassword` - set the password used to authenticate the user with the Docker server.
125+
* `apiEmail` - set the user's email used to authenticate the user with the Docker server.
126+
127+
For example:
128+
129+
```gradle
130+
docker {
131+
useApi true
132+
hostUrl 'http://myserver:4243`
133+
apiUsername 'user'
134+
apiPassword 'password'
135+
apiEmail 'me@mycompany.com'
136+
}
137+
```
138+
139+
101140
## Requirements
102-
* Gradle 1.10
103-
* Docker 0.6+
141+
* Gradle 2.x
142+
* Docker 0.11+
143+
144+
#### Note to Gradle 1.x users
145+
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:
146+
147+
```gradle
148+
buildscript {
149+
// ...
150+
dependencies {
151+
classpath 'se.transmode.gradle:gradle-docker:1.2'
152+
classpath 'org.codehaus.groovy:groovy-backports-compat23:2.3.5'
153+
}
154+
}
155+
```
104156

105-
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.
157+
#### Note to native docker client users
158+
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.

build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ configurations {
3838
dependencies {
3939
compile gradleApi()
4040
compile localGroovy()
41+
compile 'com.google.guava:guava:17.0'
42+
43+
compile 'com.google.guava:guava:17.0'
44+
compile 'com.github.docker-java:docker-java:0.9.0'
4145

4246
testCompile 'junit:junit-dep:4.11'
4347
testCompile 'org.hamcrest:hamcrest-all:1.3'

examples/application/build.gradle

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,22 @@ apply plugin: 'application'
33
apply plugin: 'docker'
44

55
buildscript {
6-
repositories { jcenter() }
6+
repositories { mavenLocal(); jcenter() }
77
dependencies {
88
classpath 'se.transmode.gradle:gradle-docker:1.2'
99
}
1010
}
1111

12+
task wrapper(type: Wrapper) {
13+
gradleVersion = '2.0'
14+
}
15+
1216
sourceCompatibility = 1.7
1317
group = 'example'
1418
version = '1.0'
1519
mainClassName = 'se.transmode.example.docker.JettyMain'
1620

17-
repositories { mavenCentral() }
21+
repositories { jcenter() }
1822
dependencies {
1923
compile 'org.eclipse.jetty.aggregate:jetty-all:9.0.6.v20130930'
2024
}
503 Bytes
Binary file not shown.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Tue Oct 29 23:01:20 CET 2013
1+
#Sat Jul 26 09:30:47 CEST 2014
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=http\://services.gradle.org/distributions/gradle-1.8-bin.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-2.0-bin.zip

examples/application/gradlew.bat

Lines changed: 90 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/simple/build.gradle

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,36 @@
11
apply plugin: 'docker'
22

33
buildscript {
4-
repositories { jCentral() }
4+
repositories { mavenLocal(); jcenter() }
55
dependencies {
66
classpath 'se.transmode.gradle:gradle-docker:1.2'
77
}
88
}
99

10+
task wrapper(type: Wrapper) {
11+
gradleVersion = '2.0'
12+
}
13+
1014
group = 'org.acme'
1115

1216
docker {
1317
maintainer = 'Victor Vieux <victor@docker.com>'
1418
}
1519

1620
task nginxDocker(type: Docker) {
21+
// The default image tag contains the applicationName
1722
applicationName = 'nginx'
23+
24+
// Dockerfile instruction 'RUN'
1825
runCommand 'echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list'
1926
runCommand "apt-get update"
2027
runCommand "apt-get install -y inotify-tools nginx apache2 openssh-server"
28+
29+
/* addFile accepts copySpec closure (like project.copy)
30+
The source files are added to a tar archive which is then copied
31+
into the image using the Dockerfile 'ADD' instruction. */
32+
addFile {
33+
from 'input'
34+
into 'docs'
35+
}
2136
}
834 Bytes
Binary file not shown.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Tue Oct 29 23:01:20 CET 2013
1+
#Sat Jul 26 09:25:24 CEST 2014
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=http\://services.gradle.org/distributions/gradle-1.8-bin.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-2.0-bin.zip

0 commit comments

Comments
 (0)