Skip to content
Permalink
Browse files

Sets up jib-maven-plugin. (#5)

  • Loading branch information...
coollog committed Jan 31, 2018
1 parent 87b4006 commit 2da4ce8c264d4b586fb12049dfa67eaecde5ca21
Showing with 1,868 additions and 113 deletions.
  1. +111 βˆ’1 README.md
  2. +11 βˆ’0 jib-core/.gitignore
  3. +9 βˆ’1 jib-core/build.gradle
  4. +1 βˆ’1 jib-core/gradle.properties
  5. BIN jib-core/gradle/wrapper/gradle-wrapper.jar
  6. +1 βˆ’2 jib-core/settings.gradle
  7. +73 βˆ’0 jib-core/src/main/java/com/google/cloud/tools/jib/Timer.java
  8. +64 βˆ’70 jib-core/src/main/java/com/google/cloud/tools/jib/builder/BuildImageSteps.java
  9. +29 βˆ’15 jib-core/src/main/java/com/google/cloud/tools/jib/builder/PushImageStep.java
  10. +9 βˆ’1 jib-core/src/main/java/com/google/cloud/tools/jib/http/Authorizations.java
  11. +2 βˆ’1 jib-core/src/main/java/com/google/cloud/tools/jib/image/LayerBuilder.java
  12. +2 βˆ’1 jib-core/src/main/java/com/google/cloud/tools/jib/registry/DockerCredentialRetriever.java
  13. +23 βˆ’12 jib-core/src/main/java/com/google/cloud/tools/jib/registry/RegistryClient.java
  14. +1 βˆ’1 jib-core/src/main/java/com/google/cloud/tools/jib/registry/RegistryUnauthorizedException.java
  15. +8 βˆ’4 jib-core/src/test/java/com/google/cloud/tools/jib/builder/TestSourceFilesConfiguration.java
  16. +4 βˆ’2 jib-core/src/test/java/com/google/cloud/tools/jib/http/ConnectionTest.java
  17. +2 βˆ’1 jib-core/src/test/java/com/google/cloud/tools/jib/image/LayerBuilderTest.java
  18. +12 βˆ’0 jib-maven-plugin/.gitignore
  19. BIN jib-maven-plugin/.mvn/wrapper/maven-wrapper.jar
  20. +1 βˆ’0 jib-maven-plugin/.mvn/wrapper/maven-wrapper.properties
  21. +10 βˆ’0 jib-maven-plugin/config/checkstyle-header.xml
  22. +15 βˆ’0 jib-maven-plugin/config/copyright.header
  23. +230 βˆ’0 jib-maven-plugin/config/google-checks-no-indent.xml
  24. +227 βˆ’0 jib-maven-plugin/mvnw
  25. +145 βˆ’0 jib-maven-plugin/mvnw.cmd
  26. +181 βˆ’0 jib-maven-plugin/pom.xml
  27. +180 βˆ’0 jib-maven-plugin/src/main/java/com/google/cloud/tools/jib/maven/BuildImageMojo.java
  28. +115 βˆ’0 jib-maven-plugin/src/main/java/com/google/cloud/tools/jib/maven/MavenSourceFilesConfiguration.java
  29. +87 βˆ’0 jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/BuildImageMojoIT.java
  30. +107 βˆ’0 ...aven-plugin/src/test/java/com/google/cloud/tools/jib/maven/MavenSourceFilesConfigurationTest.java
  31. +50 βˆ’0 jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/TestPlugin.java
  32. +64 βˆ’0 jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/TestProject.java
  33. BIN jib-maven-plugin/src/test/resources/application/dependencies/dependency-1.0.0.jar
  34. 0 jib-maven-plugin/src/test/resources/application/dependencies/libraryA.jar
  35. 0 jib-maven-plugin/src/test/resources/application/dependencies/libraryB.jar
  36. BIN jib-maven-plugin/src/test/resources/application/output/HelloWorld.class
  37. 0 jib-maven-plugin/src/test/resources/application/output/resourceA
  38. 0 jib-maven-plugin/src/test/resources/application/output/resourceB
  39. 0 jib-maven-plugin/src/test/resources/application/output/some.class
  40. +1 βˆ’0 jib-maven-plugin/src/test/resources/application/output/world
  41. 0 jib-maven-plugin/src/test/resources/application/source/HelloWorld.java
  42. 0 jib-maven-plugin/src/test/resources/application/source/some.java
  43. BIN jib-maven-plugin/src/test/resources/project/libs/dependency-1.0.0.jar
  44. +51 βˆ’0 jib-maven-plugin/src/test/resources/project/pom.xml
  45. +41 βˆ’0 jib-maven-plugin/src/test/resources/project/src/main/java/com/test/HelloWorld.java
  46. +1 βˆ’0 jib-maven-plugin/src/test/resources/project/src/main/resources/world
112 README.md
@@ -1 +1,111 @@
This is a temporary location for a Gradle plugin for building Java application images, similar to what [bazelbuild/rules_docker](https://github.com/bazelbuild/rules_docker) does.
## Important: This project is in an early alpha stage.

*TODO: Add a logo and badges.*

# Jib

## What is Jib?

Jib is a tool for building container images for your Java applications.

## Goals

* Fast - Your Java application gets broken down into multiple layers, separating dependencies from classes. Deploy your changes faster - don’t wait for Docker to rebuild your entire Java application.

<!--* Reproducible - Rebuilding your container image with the same contents always generates the same image. Never trigger an unnecessary update again.-->

* 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.

## Quickstart

### Setup

In your Maven Java project, add the plugin to your `pom.xml`:

```
<plugin>
<groupId>com.google.com.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>0.1.0</version>
<configuration>
<registry></registry>
<repository></repository>
<credentialHelperName></credentialHelperName>
</configuration>
</plugin>
```

### Configuration

Configure the plugin by changing `registry`, `repository`, and `credentialHelperName` accordingly.

#### I am using Google Container Registry (GCR)

*TODO: Add reference for how to get the credential helper.*

For example, to build the image `gcr.io/my-gcp-project/my-app`, the configuration would be:

```
<configuration>
<registry>gcr.io</registry>
<repository>my-gcp-project/my-app</repository>
<credentialHelperName>gcr</credentialHelperName>
</configuration>
```

#### I am using Amazon Elastic Container Registry (ECR)

*TODO: Add reference for how to get the credential helper.*

For example, to build the image `aws_account_id.dkr.ecr.region.amazonaws.com/my-app`, the configuration would be:

```
<configuration>
<registry>aws_account_id.dkr.ecr.region.amazonaws.com</registry>
<repository>my-app</repository>
<credentialHelperName>ecr-login</credentialHelperName>
</configuration>
```

#### *TODO: Add more examples for common registries.*

### Build Your Image

Build your container image with:

```
$ mvn compile jib:build
```

Subsequent builds would usually be much faster than the initial build.

## Extended Usage

Extended configuration options provide additional options for customizing the image build.

Field | Default | Description
--- | --- | ---
<!--from|`gcr.io/distroless/java`|The base image to build your application on top of.-->
baseImageRegistry|`gcr.io`|The registry for the base image
baseImageRepository|`distroless/java`|The image name/repository of the base image
baseImageTag|`latest`|The tag for the base image
registry|*Required*|The registry server to push the built image to.
repository|*Required*|The image name/repository of the built image.
tag|`latest`|The image tag of the built image (the part after the colon).
jvmFlags|*None*|Additional flags to pass into the JVM when running your application.
<!--copy|*None*|Additional files to add to the image filesystem.-->
credentialHelperName|*Required*|The credential helper suffix (following `docker-credential-`)
## How Jib Works
Whereas traditionally a Java application is built as a single image layer with the application JAR, the build strategy here breaks 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.
See also [rules_docker](https://github.com/bazelbuild/rules_docker) for a similar existing container image build tool for the []Bazel build system]9https://github.com/bazelbuild/bazel).
## Frequently Asked Questions (FAQ)
*TODO: Add more answers.*

### But, I'm not a Java developer.

[bazelbuild/rules_docker](https://github.com/bazelbuild/rules_docker)
@@ -0,0 +1,11 @@
build
target
out
*.iml
*.ipr
*.iws
.idea
.gradle
/.settings
/.classpath
/.project
@@ -2,6 +2,7 @@ plugins {
id 'java-gradle-plugin'
id 'checkstyle'
id 'com.github.sherter.google-java-format' version '0.6'
id 'maven-publish'
}

group 'com.google.cloud.tools'
@@ -32,14 +33,21 @@ configurations {
dependencies {
compile gradleApi()
compile 'com.google.http-client:google-http-client:1.23.0'
compile 'com.google.http-client:google-http-client-jackson2:1.23.0'
compile 'org.apache.commons:commons-compress:1.15'
compile 'com.google.guava:guava:23.5-jre'
compile 'com.fasterxml.jackson.core:jackson-databind:2.9.2'
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.12.0'
}

publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}

task wrapper(type: Wrapper) {
gradleVersion = "4.3.1"
}
@@ -1 +1 @@
version = 1.0.0-SNAPSHOT
version = 0.1.0-SNAPSHOT
Binary file not shown.
@@ -1,2 +1 @@
rootProject.name = 'jib'

rootProject.name = 'jib-core'
@@ -0,0 +1,73 @@
/*
* Copyright 2018 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

package com.google.cloud.tools.jib;

import java.io.Closeable;
import java.util.Stack;

/**
* Times execution intervals. This is only for testing purposes and will be removed before the first
* release.
*/
public class Timer implements Closeable {

private static Stack<String> labels = new Stack<>();
private static Stack<Long> times = new Stack<>();

private static StringBuilder log = new StringBuilder();

public static void print() {
System.out.println(log);
}

public static Timer push(String label) {
logTabs();
log.append("TIMING\t");
log.append(label);
log.append("\n");
labels.push(label);
times.push(System.currentTimeMillis());
return new Timer();
}

public static void time(String label) {
pop();
push(label);
}

private static void pop() {
String label = labels.pop();
long time = times.pop();
logTabs();
log.append("TIMED\t");
log.append(label);
log.append(" : ");
log.append(System.currentTimeMillis() - time);
log.append("\n");
}

private static void logTabs() {
for (int i = 0; i < labels.size(); i++) {
log.append("\t");
}
}

@Override
public void close() {
Timer.pop();
}
}
Oops, something went wrong.

0 comments on commit 2da4ce8

Please sign in to comment.
You can’t perform that action at this time.