Skip to content

Latest commit

 

History

History
77 lines (53 loc) · 2.74 KB

buildpacksbuildtemplate.md

File metadata and controls

77 lines (53 loc) · 2.74 KB
As of Knative 0.8, Knative Build has been deprecated in favor of Tekton Pipelines. This doc is kept as a reference for pre-0.8 Knative installations. Please refer to Tekton Pipelines section of the tutorial on how to do builds in Knative going forward.

Buildpacks Build Template

Knative comes with a number of ready-to-use build-templates and one of my favorites is the template for Cloud Native Buildpacks.

Cloud Native Buildpacks allow you to go from source code to a container image without having to define a Dockerfile. Buildpacks does this with auto-detection magic to figure out what language your code is written in and what kind of dependencies it has. In this end, you end up with a runnable app image.

So far, all of the build labs required a Dockerfile in order to build and push an image. In this lab, let's use buildpacks template to create and push an image without a Dockerfile.

Install Buildpacks BuildTemplate

First, we need to install Buildpacks Build Template:

kubectl apply -f https://raw.githubusercontent.com/knative/build-templates/master/buildpacks/cnb.yaml

Check that it is installed:

kubectl get buildtemplate

NAME             AGE
buildpacks-cnb   1m

Design the build

Let's create a Build now to build a sample Java app on GitHub (sample-java-app).

Create a buildtemplate-buildpack-sample-java-app-gcr.yaml build file:

apiVersion: build.knative.dev/v1alpha1
kind: Build
metadata:
  name: buildtemplate-buildpack-sample-java-app-gcr
spec:
  source:
    git:
      url: https://github.com/buildpack/sample-java-app.git
      revision: master
  template:
      name: buildpacks-cnb
      arguments:
      - name: IMAGE
        # Replace {PROJECT_ID} with your GCP Project's ID.
        value: gcr.io/{PROJECT_ID}/sample-java-app:buildpack

One thing you'll notice is that the sample-java-app does not define a Dockerfile. Buildpacks will use its auto-detection to build the image and push it to the location specified in IMAGE argument.

Run and watch the build

Start the build:

kubectl apply -f buildtemplate-buildpack-sample-java-app-gcr.yaml

After a few minutes, check the build is succeeded:

kubectl get build

NAME                                          SUCCEEDED
buildtemplate-buildpack-sample-java-app-gcr    True

At this point, you should see the image pushed to GCR:

Java App on GCR

What's Next?