mirror of
https://github.com/tektoncd/catalog.git
synced 2024-11-21 05:55:35 +00:00
Make Jib tasks future-proof with home changes
- 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
This commit is contained in:
parent
f1e386419c
commit
f5a4936531
@ -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
|
||||
@ -43,7 +43,7 @@ spec:
|
||||
value: gcr.io/tekton-task-project/my-image
|
||||
```
|
||||
|
||||
```
|
||||
```yaml
|
||||
apiVersion: tekton.dev/v1beta1
|
||||
kind: TaskRun
|
||||
metadata:
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
@ -43,7 +43,7 @@ spec:
|
||||
value: gcr.io/tekton-task-project/my-image
|
||||
```
|
||||
|
||||
```
|
||||
```yaml
|
||||
apiVersion: tekton.dev/v1beta1
|
||||
kind: TaskRun
|
||||
metadata:
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user