Skip to content

Commit

Permalink
Make Jib tasks future-proof with home changes
Browse files Browse the repository at this point in the history
- Set HOME env to /workspace
- Use $HOME for "home" wherever possible
- Gradle: mount empty dir at ~/.gradle to make it globally writable
- Maven: script to `script:` to use "$HOME" variable
  • Loading branch information
chanseokoh authored and tekton-robot committed Jul 22, 2020
1 parent f1e3864 commit f5a4936
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 24 deletions.
6 changes: 3 additions & 3 deletions task/jib-gradle/0.1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ kubectl apply -f https://raw.githubusercontent.com/tektoncd/catalog/master/task/
This TaskRun runs the Task to fetch a Git repo, and build and push a container
image using Jib (Gradle)

```
apiVersion: tekton.dev/v1alpha1
```yaml
apiVersion: tekton.dev/v1beta1
kind: PipelineResource
metadata:
name: example-image
Expand All @@ -43,7 +43,7 @@ spec:
value: gcr.io/tekton-task-project/my-image
```
```
```yaml
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
Expand Down
24 changes: 16 additions & 8 deletions task/jib-gradle/0.1/jib-gradle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,36 @@ spec:
project.apply plugin: com.google.cloud.tools.jib.gradle.JibPlugin
}
}
}" > /tekton/home/init-script.gradle
}" > $HOME/init-script.gradle
# Runs the Gradle Jib build.
gradle jib \
--stacktrace --console=plain \
--init-script=/tekton/home/init-script.gradle \
-Duser.home=/tekton/home \
-Dgradle.user.home=/tekton/home/.gradle \
--init-script=$HOME/init-script.gradle \
--gradle-user-home=$HOME/.gradle \
-Dgradle.user.home=$HOME/.gradle \
-Duser.home=$HOME \
-Djib.allowInsecureRegistries=$(params.INSECUREREGISTRY) \
-Djib.to.image=$(resources.outputs.image.url)
workingDir: $(workspaces.source.path)/$(params.DIRECTORY)
env:
- name: HOME
value: /workspace
volumeMounts:
# empty volume required to make the Gradle home globally writable
- name: empty-dir-volume
mountPath: /workspace/.gradle
subPath: gradle-user-home
- name: $(params.CACHE)
mountPath: /tekton/home/.gradle/caches
mountPath: /workspace/.gradle/caches
subPath: gradle-caches
- name: $(params.CACHE)
mountPath: /tekton/home/.gradle/wrapper
mountPath: /workspace/.gradle/wrapper
subPath: gradle-wrapper
- name: $(params.CACHE)
mountPath: /tekton/home/.m2
mountPath: /workspace/.m2
subPath: m2-cache
- name: $(params.CACHE)
mountPath: /tekton/home/.cache
mountPath: /workspace/.cache
subPath: jib-cache
securityContext:
runAsUser: 0
Expand Down
6 changes: 3 additions & 3 deletions task/jib-maven/0.1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ kubectl apply -f https://raw.githubusercontent.com/tektoncd/catalog/master/task/
This TaskRun runs the Task to fetch a Git repo, and build and push a container
image using Jib (Maven)

```
apiVersion: tekton.dev/v1alpha1
```yaml
apiVersion: tekton.dev/v1beta1
kind: PipelineResource
metadata:
name: example-image
Expand All @@ -43,7 +43,7 @@ spec:
value: gcr.io/tekton-task-project/my-image
```
```
```yaml
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
Expand Down
24 changes: 14 additions & 10 deletions task/jib-maven/0.1/jib-maven.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,25 @@ spec:
steps:
- name: build-and-push
image: gcr.io/cloud-builders/mvn
command:
- mvn
- -B
- compile
- com.google.cloud.tools:jib-maven-plugin:build
- -Duser.home=/tekton/home
- -Djib.allowInsecureRegistries=$(params.INSECUREREGISTRY)
- -Djib.to.image=$(resources.outputs.image.url)
# Make sh evaluate $HOME.
script: |
#!/bin/sh
mvn -B \
-Duser.home=$HOME \
-Djib.allowInsecureRegistries=$(params.INSECUREREGISTRY) \
-Djib.to.image=$(resources.outputs.image.url) \
compile \
com.google.cloud.tools:jib-maven-plugin:build
workingDir: $(workspaces.source.path)/$(params.DIRECTORY)
env:
- name: HOME
value: /workspace
volumeMounts:
- name: $(params.CACHE)
mountPath: /tekton/home/.m2
mountPath: /workspace/.m2
subPath: m2-cache
- name: $(params.CACHE)
mountPath: /tekton/home/.cache
mountPath: /workspace/.cache
subPath: jib-cache

volumes:
Expand Down

0 comments on commit f5a4936

Please sign in to comment.