Skip to content
This repository has been archived by the owner on Sep 6, 2019. It is now read-only.

Jib: Adds init script to use with any Gradle project. #68

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions jib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,26 +113,15 @@ Future builds should now run much faster.

## Usage (Gradle)

This assumes the source repo is using the Gradle plugin, configured in
`build.gradle`:

```groovy
plugins {
id 'com.google.cloud.tools.jib' version '0.9.10'
}
```

See [setup instructions for
Gradle](https://github.com/GoogleContainerTools/jib/tree/master/jib-gradle-plugin#setup).

To use the `jib-gradle` template, first install the template:

```shell
kubectl apply -f https://github.com/knative/build-templates/master/jib/jib-gradle.yaml
```

Then, define a build that instantiates the template:
Then, define a `Build` that instantiates the template:

`jib-gradle-build.yaml`:
```yaml
apiVersion: build.knative.dev/v1alpha1
kind: Build
Expand All @@ -149,3 +138,16 @@ spec:
- name: IMAGE
value: gcr.io/my-project/my-app
```

Run the build:

```shell
kubectl apply -f jib-gradle-build.yaml
```

If you would like to customize the container, configure the `jib-gradle-plugin` in your `pom.xml`.
See [setup instructions for Gradle](https://github.com/GoogleContainerTools/jib/tree/master/jib-gradle-plugin#setup) for more information.

### Speed up builds

See [Speed up builds](#speed-up-builds).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though it's annoying to have two copies, it might be helpful to be explicit about the steps to speed up Gradle builds specifically. I'm thinking if I'm a heavy Gradle user and doesn't know anything about Maven, I don't want to have to figure out which parts of the Maven-specific "speeding up builds" doc apply to me and which don't.

Let me know if that's a silly thought, and that Gradle developers would necessarily know enough about Maven to figure it out, I don't know the Javas.

44 changes: 39 additions & 5 deletions jib/jib-gradle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,49 @@ spec:
steps:
- name: build-and-push
image: gcr.io/cloud-builders/gradle
command:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might indicate that we want a jib-gradle builder image that includes these files (and any future ones), without having to squeeze them into the build template.

If we go that route, my personal preference would be to base that image FROM gradle and not rely on the poorly-supported gcr.io/cloud-builders/gradle image. (Same with maven, tbh). That can happen in a later CL though if you'd prefer.

- sh
- -c
args:
- jib
- -Duser.home=/builder/home
- --image=${IMAGE}
- |
# Adds Gradle init script that applies the Jib Gradle plugin.
echo "\
initscript {
repositories {
maven {
url 'https://plugins.gradle.org/m2'
}
}
dependencies {
classpath 'gradle.plugin.com.google.cloud.tools:jib-gradle-plugin:+'
}
}

// Only applies the Jib plugin if the project does not apply it already.
rootProject {
afterEvaluate {
if (!project.plugins.hasPlugin('com.google.cloud.tools.jib')) {
project.apply plugin: com.google.cloud.tools.jib.gradle.JibPlugin
}
}
}\
" > /builder/home/auto-jib.gradle

# Runs the Gradle Jib build.
gradle jib \
--init-script=/builder/home/auto-jib.gradle \
-Dgradle.user.home=/builder/home/.gradle \
-Duser.home=/builder/home \
--image=${IMAGE}

workingDir: /workspace/${DIRECTORY}
volumeMounts:
- name: ${CACHE}
mountPath: /builder/home/.m2
subPath: m2-cache
mountPath: /builder/home/.gradle/caches
subPath: gradle-caches
- name: ${CACHE}
mountPath: /builder/home/.gradle/wrapper
subPath: gradle-wrapper
- name: ${CACHE}
mountPath: /builder/home/.cache
subPath: jib-cache
Expand Down