This demo shows how to use Tekton Pipelines to build java code from source code in a su-directory of git repository. In this demo I will build a sample Spring app using Google Cloud Vision API and deploy it to a Knative cluster.
Assumes you already installed Tekton Pipelines and its dependencies
kubectl apply -f https://storage.googleapis.com/tekton-releases/latest/release.yaml
Maven will be downloading a lot of dependencies, to ensure the subsequent build run faster, first define a PersistentVolumeClaim
on your cluster
kubectl apply -f cache.yaml
The Tekton Task for Maven builds Java/Kotlin/Groovy/Scala source into a container image using Google's Jib tool.
kubectl apply -f task-jdk-8.yaml
First you need to create a GCP service account with sufficient rights to push images to GCR. Then edit the provided secret.yaml
file and paste the secret into the password
field.
Tekton will use this account to authenticate to the registry
kubectl apply -f secret.yaml
With Tokton configured on your Knative cluster, you can now build Java apps.
Make sure to edit the
PipelineResource
component to changecloudylabs
to your own project name
apiVersion: tekton.dev/v1alpha1
kind: PipelineResource
metadata:
name: vision-image-build
spec:
type: image
params:
- name: url
value: gcr.io/cloudylabs/vision:3.2.10
To submit your build now, run:
kubectl apply -f maven-build.yaml
First time you build, Maven will have to download all the dependencies (~3 min). After that, things get a lot faster. Subsequent builds as fast as ~15 sec.
kubectl get pods
If you are interested in watching the on-cluster build, you can watch the build-step-build-and-push
logs
kubectl logs jib-maven-vision-image-build-pod-**** -c step-build-and-push -f
Replace pod name in the above command with the unique name on your cluster with the name listed by
kubectl get pods
The resulting output should look like something like this
[INFO] Built and pushed image as gcr.io/cloudylabs/vision:3.2.10
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 33.250 s
[INFO] Finished at: 2019-09-14T13:34:29Z
[INFO] Final Memory: 58M/537M
[INFO] ------------------------------------------------------------------------
With the image built, you can now deploy
Make sure to replace
cloudylabs
with the name of your project
container:
image: gcr.io/cloudylabs/vision:3.2.10
Now apply the updated manifest
kubectl apply -f service.yaml
Navigate to the vision
URL (https://vision.demo.knative.tech/) to see the results.
To remove the sample app from your cluster, delete the service record:
kubectl delete -f service.yaml