-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
26 changed files
with
862 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: | ||
|
||
|
@@ -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' | ||
} | ||
} | ||
|
@@ -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: | ||
|
@@ -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: | ||
|
||
|
@@ -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`: | ||
|
||
|
@@ -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 '[email protected]' | ||
} | ||
``` | ||
|
||
|
||
## 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
4 changes: 2 additions & 2 deletions
4
examples/application/gradle/wrapper/gradle-wrapper.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <[email protected]>' | ||
} | ||
|
||
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.