mirror of
https://github.com/tektoncd/catalog.git
synced 2024-11-21 05:55:35 +00:00
Add version 0.2 to jib-maven task
- Add parameter for the maven image - Replace usage of PipelineResource to image name as param and image digest as results Signed-off-by: Yulia Gaponenko <yulia.gaponenko1@de.ibm.com>
This commit is contained in:
parent
dcaa00dca6
commit
0a29a36c5a
54
task/jib-maven/0.2/README.md
Normal file
54
task/jib-maven/0.2/README.md
Normal file
@ -0,0 +1,54 @@
|
||||
# Jib Maven
|
||||
|
||||
This Task builds Java/Kotlin/Groovy/Scala source into a container image using Google's [Jib](https://github.com/GoogleContainerTools/jib) tool.
|
||||
|
||||
Jib works with [Maven](https://github.com/GoogleContainerTools/jib/tree/master/jib-maven-plugin) and [Gradle](https://github.com/GoogleContainerTools/jib/tree/master/jib-gradle-plugin) projects, and this template is for Maven projects.
|
||||
|
||||
## Install the Task
|
||||
|
||||
```
|
||||
kubectl apply -f https://raw.githubusercontent.com/tektoncd/catalog/master/task/jib-maven/0.2/jib-maven.yaml
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
- **IMAGE**: The name of the image to build
|
||||
- **MAVEN_IMAGE**: The base image for maven (_default_: `gcr.io/cloud-builders/mvn`)
|
||||
- **DIRECTORY**: The directory in the source repository where source should be found. (*default: .*)
|
||||
- **CACHE**: The name of the volume for caching Maven artifacts and
|
||||
base image layers (*default: empty-dir-volume*)
|
||||
|
||||
## Workspaces
|
||||
|
||||
* **source**: A [Workspace](https://github.com/tektoncd/pipeline/blob/master/docs/workspaces.md) containing the source to build.
|
||||
|
||||
## Results
|
||||
|
||||
- **IMAGE_DIGEST**: Digest of the image just built.
|
||||
|
||||
## Usage
|
||||
|
||||
This TaskRun runs the Task to fetch a Git repo, and build and push a container
|
||||
image using Jib (Maven)
|
||||
|
||||
```yaml
|
||||
apiVersion: tekton.dev/v1beta1
|
||||
kind: TaskRun
|
||||
metadata:
|
||||
name: example-jib-maven
|
||||
spec:
|
||||
taskRef:
|
||||
name: jib-maven
|
||||
params:
|
||||
- name: IMAGE
|
||||
value: gcr.io/my-repo/my-image
|
||||
- name: DIRECTORY
|
||||
value: ./examples/helloworld
|
||||
workspaces:
|
||||
- name: source
|
||||
persistentVolumeClaim:
|
||||
claimName: my-source
|
||||
```
|
||||
|
||||
If you would like to customize the container, configure the `jib-maven-plugin` in your `pom.xml`.
|
||||
See [setup instructions for Maven](https://github.com/GoogleContainerTools/jib/tree/master/jib-maven-plugin#setup) for more information.
|
72
task/jib-maven/0.2/jib-maven.yaml
Normal file
72
task/jib-maven/0.2/jib-maven.yaml
Normal file
@ -0,0 +1,72 @@
|
||||
apiVersion: tekton.dev/v1beta1
|
||||
kind: Task
|
||||
metadata:
|
||||
name: jib-maven
|
||||
labels:
|
||||
app.kubernetes.io/version: "0.2"
|
||||
annotations:
|
||||
tekton.dev/pipelines.minVersion: "0.12.1"
|
||||
tekton.dev/tags: image-build
|
||||
tekton.dev/displayName: "jib maven"
|
||||
spec:
|
||||
description: >-
|
||||
This Task builds Java/Kotlin/Groovy/Scala source into a container image using Google's Jib tool.
|
||||
|
||||
Jib works with Maven and Gradle projects, and this template is for Maven projects.
|
||||
|
||||
params:
|
||||
- name: IMAGE
|
||||
description: Name of the image to build
|
||||
- name: MAVEN_IMAGE
|
||||
type: string
|
||||
description: Maven base image
|
||||
default: gcr.io/cloud-builders/mvn@sha256:57523fc43394d6d9d2414ee8d1c85ed7a13460cbb268c3cd16d28cfb3859e641 #tag: latest
|
||||
- name: DIRECTORY
|
||||
description: The directory containing the app, relative to the source repository root
|
||||
default: .
|
||||
- name: CACHE
|
||||
description: The name of the volume for caching Maven artifacts and base image layers
|
||||
default: empty-dir-volume
|
||||
- name: INSECUREREGISTRY
|
||||
description: Whether to allow insecure registry
|
||||
default: "false"
|
||||
workspaces:
|
||||
- name: source
|
||||
|
||||
results:
|
||||
- name: IMAGE_DIGEST
|
||||
description: Digest of the image just built.
|
||||
|
||||
steps:
|
||||
- name: build-and-push
|
||||
image: $(params.MAVEN_IMAGE)
|
||||
# Make sh evaluate $HOME.
|
||||
script: |
|
||||
#!/bin/sh
|
||||
mvn -B \
|
||||
-Duser.home=$HOME \
|
||||
-Djib.allowInsecureRegistries=$(params.INSECUREREGISTRY) \
|
||||
-Djib.to.image=$(params.IMAGE) \
|
||||
compile \
|
||||
com.google.cloud.tools:jib-maven-plugin:build
|
||||
workingDir: $(workspaces.source.path)/$(params.DIRECTORY)
|
||||
env:
|
||||
- name: HOME
|
||||
value: /workspace
|
||||
- name: "DOCKER_CONFIG"
|
||||
value: $(credentials.path)/.docker/
|
||||
volumeMounts:
|
||||
- name: $(params.CACHE)
|
||||
mountPath: /workspace/.m2
|
||||
subPath: m2-cache
|
||||
- name: $(params.CACHE)
|
||||
mountPath: /workspace/.cache
|
||||
subPath: jib-cache
|
||||
|
||||
- name: digest-to-results
|
||||
image: $(params.MAVEN_IMAGE)
|
||||
script: cat $(workspaces.source.path)/target/jib-image.digest | tee /tekton/results/IMAGE_DIGEST
|
||||
|
||||
volumes:
|
||||
- name: empty-dir-volume
|
||||
emptyDir: {}
|
8
task/jib-maven/0.2/tests/pre-apply-task-hook.sh
Executable file
8
task/jib-maven/0.2/tests/pre-apply-task-hook.sh
Executable file
@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Add an internal registry as sidecar to the task so we can upload it directly
|
||||
# from our tests withouth having to go to an external registry.
|
||||
add_sidecar_registry ${TMPF}
|
||||
|
||||
# Add git-clone
|
||||
add_task git-clone latest
|
11
task/jib-maven/0.2/tests/resources.yaml
Normal file
11
task/jib-maven/0.2/tests/resources.yaml
Normal file
@ -0,0 +1,11 @@
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: jib-maven-source-pvc
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 500Mi
|
65
task/jib-maven/0.2/tests/run.yaml
Normal file
65
task/jib-maven/0.2/tests/run.yaml
Normal file
@ -0,0 +1,65 @@
|
||||
---
|
||||
apiVersion: tekton.dev/v1beta1
|
||||
kind: Pipeline
|
||||
metadata:
|
||||
name: jib-maven-test-pipeline
|
||||
spec:
|
||||
workspaces:
|
||||
- name: shared-workspace
|
||||
tasks:
|
||||
- name: fetch-repository
|
||||
taskRef:
|
||||
name: git-clone
|
||||
workspaces:
|
||||
- name: output
|
||||
workspace: shared-workspace
|
||||
params:
|
||||
- name: url
|
||||
value: https://github.com/che-samples/console-java-simple
|
||||
- name: subdirectory
|
||||
value: ""
|
||||
- name: deleteExisting
|
||||
value: "true"
|
||||
- name: jib-maven
|
||||
taskRef:
|
||||
name: jib-maven
|
||||
runAfter:
|
||||
- fetch-repository
|
||||
workspaces:
|
||||
- name: source
|
||||
workspace: shared-workspace
|
||||
params:
|
||||
- name: IMAGE
|
||||
value: localhost:5000/tekton-pipelines/console-java-simple
|
||||
- name: INSECUREREGISTRY
|
||||
value: "true"
|
||||
- name: verify-digest
|
||||
runAfter:
|
||||
- jib-maven
|
||||
params:
|
||||
- name: digest
|
||||
value: $(tasks.jib-maven.results.IMAGE_DIGEST)
|
||||
taskSpec:
|
||||
params:
|
||||
- name: digest
|
||||
steps:
|
||||
- name: bash
|
||||
image: ubuntu
|
||||
script: |
|
||||
echo $(params.digest)
|
||||
case .$(params.digest) in
|
||||
".sha"*) exit 0 ;;
|
||||
*) echo "Digest value is not correct" && exit 1 ;;
|
||||
esac
|
||||
---
|
||||
apiVersion: tekton.dev/v1beta1
|
||||
kind: PipelineRun
|
||||
metadata:
|
||||
name: jib-maven-test-pipeline-run
|
||||
spec:
|
||||
pipelineRef:
|
||||
name: jib-maven-test-pipeline
|
||||
workspaces:
|
||||
- name: shared-workspace
|
||||
persistentvolumeclaim:
|
||||
claimName: jib-maven-source-pvc
|
Loading…
Reference in New Issue
Block a user