Skip to content

Commit d80ff17

Browse files
authored
Generifies root README and links to plugin-specific READMEs. (GoogleContainerTools#220)
1 parent 09985a2 commit d80ff17

3 files changed

Lines changed: 54 additions & 243 deletions

File tree

‎README.md‎

Lines changed: 47 additions & 238 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88

99
## What is Jib?
1010

11-
Jib is a Maven plugin for building Docker and OCI images for your Java applications.
11+
Jib builds Docker and OCI images for your Java applications and is available as plugins for [Maven](jib-maven-plugin) and [Gradle](jib-gradle-plugin).
12+
13+
[Maven](https://maven.apache.org/): See documentation for [jib-maven-plugin](jib-maven-plugin).
14+
[Gradle](https://gradle.org/): See documentation for [jib-gradle-plugin](jib-gradle-plugin).
1215

1316
## Goals
1417

@@ -18,252 +21,22 @@ Jib is a Maven plugin for building Docker and OCI images for your Java applicati
1821

1922
* **Native** - Reduce your CLI dependencies. Build your Docker image from within Maven <!--or Gradle--> and push to any registry of your choice. *No more writing Dockerfiles and calling docker build/push.*
2023

21-
## Upcoming Features
22-
23-
These features are not currently supported but will be added in later releases.
24-
25-
* Support for WAR format
26-
2724
## Quickstart
2825

29-
### Setup
30-
31-
In your Maven Java project, add the plugin to your `pom.xml`:
32-
33-
```xml
34-
<plugin>
35-
<groupId>com.google.cloud.tools</groupId>
36-
<artifactId>jib-maven-plugin</artifactId>
37-
<version>0.1.6</version>
38-
<configuration>
39-
<registry>myregistry</registry>
40-
<repository>myapp</repository>
41-
</configuration>
42-
</plugin>
43-
```
44-
45-
### Configuration
46-
47-
Configure the plugin by changing `registry` and `repository` to be the registry and repository to push the built image to.
48-
49-
#### Using [Google Container Registry (GCR)](https://cloud.google.com/container-registry/)...
50-
51-
*Make sure you have the [`docker-credential-gcr` command line tool](https://cloud.google.com/container-registry/docs/advanced-authentication#docker_credential_helper). Jib automatically uses `docker-credential-gcr` for obtaining credentials. See [Authentication Methods](#authentication-methods) for other ways of authenticating.*
52-
53-
For example, to build the image `gcr.io/my-gcp-project/my-app`, the configuration would be:
54-
55-
```xml
56-
<configuration>
57-
<registry>gcr.io</registry>
58-
<repository>my-gcp-project/my-app</repository>
59-
</configuration>
60-
```
61-
62-
#### Using [Amazon Elastic Container Registry (ECR)](https://aws.amazon.com/ecr/)...
63-
64-
*Make sure you have the [`docker-credential-ecr-login` command line tool](https://github.com/awslabs/amazon-ecr-credential-helper). Jib automatically uses `docker-credential-ecr-login` for obtaining credentials. See [Authentication Methods](#authentication-methods) for other ways of authenticating.*
65-
66-
For example, to build the image `aws_account_id.dkr.ecr.region.amazonaws.com/my-app`, the configuration would be:
67-
68-
```xml
69-
<configuration>
70-
<registry>aws_account_id.dkr.ecr.region.amazonaws.com</registry>
71-
<repository>my-app</repository>
72-
</configuration>
73-
```
74-
75-
#### Using [Docker Hub Registry](https://hub.docker.com/)...
26+
### Maven
7627

77-
*Make sure you have a [docker-credential-helper](https://github.com/docker/docker-credential-helpers#available-programs) set up. For example, on macOS, the credential helper would be `docker-credential-osxkeychain`. See [Authentication Methods](#authentication-methods) for other ways of authenticating.*
78-
79-
For example, to build the image `my-docker-id/my-app`, the configuration would be:
80-
81-
```xml
82-
<configuration>
83-
<registry>registry.hub.docker.com</registry>
84-
<repository>my-docker-id/my-app</repository>
85-
<credHelpers><credHelper>osxkeychain</credHelper></credHelpers>
86-
</configuration>
87-
```
88-
89-
#### *TODO: Add more examples for common registries.*
90-
91-
### Build Your Image
92-
93-
Build your container image with:
94-
95-
```shell
96-
mvn compile jib:build
97-
```
98-
99-
Subsequent builds are much faster than the initial build.
100-
101-
If you want to clear Jib's build cache and force it to re-pull the base image and re-build the application layers, run:
102-
103-
```shell
104-
mvn clean compile jib:build
105-
```
106-
107-
*Having trouble? Let us know by [submitting an issue](/../../issues/new), contacting us on [Gitter](https://gitter.im/google/jib), or posting to the [Jib users forum](https://groups.google.com/forum/#!forum/jib-users).*
108-
109-
### Bind to a lifecycle
110-
111-
You can also bind `jib:build` to a Maven lifecycle, such as `package`, by adding the following execution to your `jib-maven-plugin` definition:
112-
113-
```xml
114-
<plugin>
115-
<groupId>com.google.com.tools</groupId>
116-
<artifactId>jib-maven-plugin</artifactId>
117-
...
118-
<executions>
119-
<execution>
120-
<phase>package</phase>
121-
<goals>
122-
<goal>build</goal>
123-
</goals>
124-
</execution>
125-
</executions>
126-
</plugin>
127-
```
128-
129-
Then, you can build your container image by running:
130-
131-
```shell
132-
mvn package
133-
```
28+
See documentation for using [jib-maven-plugin](jib-maven-plugin#quickstart).
13429

135-
### Export to a Docker context
30+
### Gradle
13631

137-
Jib can also export to a Docker context so that you can build with Docker, if needed:
138-
139-
```shell
140-
mvn compile jib:dockercontext
141-
```
142-
143-
The Docker context will be created at `target/jib-dockercontext` by default. You can change this directory with the `targetDir` configuration option or the `jib.dockerDir` parameter:
144-
145-
```shell
146-
mvn compile jib:dockercontext -Djib.dockerDir=my/docker/context/
147-
```
148-
149-
You can then build your image with Docker:
150-
151-
```shell
152-
docker build -t myregistry/myapp my/docker/context/
153-
```
154-
155-
## Extended Usage
156-
157-
Extended configuration options provide additional options for customizing the image build.
158-
159-
Field | Default | Description
160-
--- | --- | ---
161-
`from`|[`gcr.io/distroless/java`](https://github.com/GoogleCloudPlatform/distroless)|The base image to build your application on top of.
162-
`registry`|*Required*|The registry server to push the built image to.
163-
`repository`|*Required*|The image name/repository of the built image.
164-
`tag`|`latest`|The image tag of the built image (the part after the colon).
165-
`credHelpers`|*Required*|Suffixes for credential helpers (following `docker-credential-`)
166-
`jvmFlags`|*None*|Additional flags to pass into the JVM when running your application.
167-
`mainClass`|Uses `mainClass` from `maven-jar-plugin`|The main class to launch the application from.
168-
`enableReproducibleBuilds`|`true`|Building with the same application contents always generates the same image. Note that this does *not* preserve file timestamps and ownership.
169-
`imageFormat`|`Docker`|Use `OCI` to build an [OCI container image](https://www.opencontainers.org/).
170-
`useOnlyProjectCache`|`false`|If set to true, Jib does not share a cache between different Maven projects.
171-
172-
### Example
173-
174-
In this configuration, the image is:
175-
* Built from a base of `openjdk:alpine` (pulled from Docker Hub)
176-
* Pushed to `localhost:5000/my-image:built-with-jib`
177-
* Runs by calling `java -Xms512m -Xdebug -Xmy:flag=jib-rules -cp app/libs/*:app/resources:app/classes mypackage.MyApp`
178-
* Reproducible
179-
* Built as OCI format
180-
181-
```xml
182-
<configuration>
183-
<from>openjdk:alpine</from>
184-
<registry>localhost:5000</registry>
185-
<repository>my-image</repository>
186-
<tag>built-with-jib</tag>
187-
<credHelpers>
188-
<credHelper>osxkeychain</credHelper>
189-
</credHelpers>
190-
<jvmFlags>
191-
<jvmFlag>-Xms512m</jvmFlag>
192-
<jvmFlag>-Xdebug</jvmFlag>
193-
<jvmFlag>-Xmy:flag=jib-rules</jvmFlag>
194-
</jvmFlags>
195-
<mainClass>mypackage.MyApp</mainClass>
196-
<enableReproducibleBuilds>true</enableReproducibleBuilds>
197-
<imageFormat>OCI</imageFormat>
198-
</configuration>
199-
```
200-
201-
### Authentication Methods
202-
203-
Pushing/pulling from private registries require authorization credentials. These can be [retrieved using Docker credential helpers](#using-docker-credential-helpers) or [defined in your Maven settings](#using-maven-settings). If you do not define credentials explicitly, Jib will try to [use credentials defined in your Docker config](/../../issues/101) or infer common credential helpers.
204-
205-
#### Using Docker Credential Helpers
206-
207-
Docker credential helpers are CLI tools that handle authentication with various registries.
208-
209-
Some common credential helpers include:
210-
211-
* Google Container Registry: [`docker-credential-gcr`](https://cloud.google.com/container-registry/docs/advanced-authentication#docker_credential_helper)
212-
* AWS Elastic Container Registry: [`docker-credential-ecr-login`](https://github.com/awslabs/amazon-ecr-credential-helper)
213-
* Docker Hub Registry: [`docker-credential-*`](https://github.com/docker/docker-credential-helpers)
214-
<!--* Azure Container Registry: [`docker-credential-acr-*`](https://github.com/Azure/acr-docker-credential-helper)
215-
-->
216-
217-
Configure credential helpers to use by specifying them in the `credHelpers` configuration.
218-
219-
*Example configuration:*
220-
```xml
221-
<configuration>
222-
...
223-
<credHelpers>
224-
<credHelper>osxkeychain</credHelper>
225-
</credHelpers>
226-
...
227-
</configuration>
228-
```
229-
230-
#### Using Maven Settings
231-
232-
Registry credentials can be added to your [Maven settings](https://maven.apache.org/settings.html). These credentials will be used if credentials could not be found in any specified Docker credential helpers.
233-
234-
If you're considering putting credentials in Maven, we highly *recommend* using [maven password encryption](https://maven.apache.org/guides/mini/guide-encryption.html).
235-
236-
*Example `settings.xml`:*
237-
```xml
238-
<settings>
239-
...
240-
<servers>
241-
...
242-
<server>
243-
<id>MY_REGISTRY</id>
244-
<username>MY_USERNAME</username>
245-
<password>{MY_SECRET}</password>
246-
</server>
247-
</servers>
248-
</settings>
249-
```
250-
251-
* The `id` field should be the registry server these credentials are for.
252-
* We *do not* recommend putting your raw password in `settings.xml`.
32+
See documentation for using [jib-gradle-plugin](jib-gradle-plugin#quickstart).
25333

25434
## How Jib Works
25535

25636
Whereas traditionally a Java application is built as a single image layer with the application JAR, Jib's build strategy separates the Java application into multiple layers for more granular incremental builds. When you change your code, only your changes are rebuilt, not your entire application. These layers, by default, are layered on top of a [distroless](https://github.com/GoogleCloudPlatform/distroless) base image.
25737

25838
See also [rules_docker](https://github.com/bazelbuild/rules_docker) for a similar existing container image build tool for the [Bazel build system](https://github.com/bazelbuild/bazel).
25939

260-
## Known Limitations
261-
262-
These limitations will be fixed in later releases.
263-
264-
* Cannot build directly to a Docker daemon.
265-
* Pushing to Azure Container Registry is not currently supported.
266-
26740
## Frequently Asked Questions (FAQ)
26841

26942
If a question you have is not answered below, please [submit an issue](/../../issues/new).
@@ -274,7 +47,15 @@ See [rules_docker](https://github.com/bazelbuild/rules_docker) for a similar exi
27447

27548
### What image format does Jib use?
27649

277-
Jib currently builds into the [Docker V2.2](https://docs.docker.com/registry/spec/manifest-v2-2/) image format or [OCI image format](https://github.com/opencontainers/image-spec). See [Extended Usage](#extended-usage) for the `imageFormat` configuration.
50+
Jib currently builds into the [Docker V2.2](https://docs.docker.com/registry/spec/manifest-v2-2/) image format or [OCI image format](https://github.com/opencontainers/image-spec).
51+
52+
#### Maven
53+
54+
See [Extended Usage](jib-maven-plugin#extended-usage) for the `imageFormat` configuration.
55+
56+
#### Gradle
57+
58+
See [Extended Usage](jib-gradle-plugin#extended-usage) for the `format` configuration.
27859

27960
### Can I define a custom entrypoint?
28061

@@ -306,21 +87,39 @@ Jib packages your Java application into the following paths on the image:
30687

30788
Running commands like `apt-get` slows down the container build process. We **do not recommend or support** running commands as part of the build.
30889

309-
However, if you need to run commands, you can build a custom base image. You can then use this custom base image in the `jib-maven-plugin` by adding the following configuration:
90+
However, if you need to run commands, you can build a custom image and configure Jib to use it as the base image.
91+
92+
<details>
93+
<summary>Base image configuration examples</summary>
94+
<p>
95+
96+
#### Maven
97+
98+
In [`jib-maven-plugin`](jib-maven-plugin), you can then use this custom base image by adding the following configuration:
31099

311100
```xml
312101
<configuration>
313102
<from>custom-base-image</from>
314103
</configuration>
315104
```
316105

106+
#### Gradle
107+
108+
In [`jib-gradle-plugin`](jib-gradle-plugin), you can then use this custom base image by adding the following configuration:
109+
110+
```groovy
111+
jib.from.image = 'custom-base-image'
112+
```
113+
</p>
114+
</details>
115+
317116
### Can I ADD a custom directory to the image?
318117

319118
We currently do not support adding a custom directory to the image. If your application needs to use custom files, place them into your application's resources directory (`src/main/resources` by default). These resource files will be available on the classpath.
320119

321120
### Can I build to a local Docker daemon?
322121

323-
We currently do not support building to a local Docker daemon. However, this feature is in the pipeline and will be added in the future.
122+
We currently do not support building to a local Docker daemon. However, [this feature is in the pipeline and will be added in the future](/../../issues/48).
324123

325124
You can still [`docker pull`](https://docs.docker.com/engine/reference/commandline/pull/) the image built with `jib-maven-plugin` to have it available in your local Docker daemon.
326125

@@ -366,6 +165,8 @@ See more at [Using Google Container Registry (GCR) with Minikube](https://ryanes
366165

367166
### How can I tag my image with a timestamp?
368167

168+
#### Maven
169+
369170
To tag the image with a simple timestamp, add the following to your `pom.xml`:
370171

371172
```xml
@@ -384,6 +185,14 @@ Then in the `jib-maven-plugin` configuration, set the `tag` to:
384185

385186
You can then use the same timestamp to reference the image in other plugins.
386187

188+
#### Gradle
189+
190+
To tag the image with a timestamp, simply set the timestamp as the tag for `to.image` in your `jib` configuration. For example:
191+
192+
```groovy
193+
jib.to.image = 'gcr.io/my-gcp-project/my-app:' + System.nanoTime()
194+
```
195+
387196
## Community
388197

389198
* Chat with us on [gitter](https://gitter.im/google/jib)

‎jib-gradle-plugin/README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
Jib is [Gradle](https://gradle.org/) plugin for building Docker and OCI images for your Java applications.
88

9-
For information about the project, see the [Jib project README](/../../).
10-
For the Maven plugin, see the [jib-maven-plugin project](/../../tree/master/jib-maven-plugin).
9+
For information about the project, see the [Jib project README](..).
10+
For the Maven plugin, see the [jib-maven-plugin project](../jib-maven-plugin).
1111

1212
## Upcoming Features
1313

‎jib-maven-plugin/README.md‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
Jib is a [Maven](https://maven.apache.org/) plugin for building Docker and OCI images for your Java applications.
88

9-
For information about the project, see the [Jib project README](/../../).
10-
For the Gradle plugin, see the [jib-gradle-plugin project](/../../tree/master/jib-gradle-plugin).
9+
For information about the project, see the [Jib project README](..).
10+
For the Gradle plugin, see the [jib-gradle-plugin project](../jib-gradle-plugin).
1111

1212
## Upcoming Features
1313

@@ -222,6 +222,8 @@ Configure credential helpers to use by specifying them in the `credHelpers` conf
222222

223223
Registry credentials can be added to your [Maven settings](https://maven.apache.org/settings.html). These credentials will be used if credentials could not be found in any specified Docker credential helpers.
224224

225+
If you're considering putting credentials in Maven, we highly *recommend* using [maven password encryption](https://maven.apache.org/guides/mini/guide-encryption.html).
226+
225227
*Example `settings.xml`:*
226228
```xml
227229
<settings>
@@ -231,7 +233,7 @@ Registry credentials can be added to your [Maven settings](https://maven.apache.
231233
<server>
232234
<id>MY_REGISTRY</id>
233235
<username>MY_USERNAME</username>
234-
<password>MY_SECRET</password>
236+
<password>{MY_SECRET}</password>
235237
</server>
236238
</servers>
237239
</settings>

0 commit comments

Comments
 (0)