Skip to content

Latest commit

 

History

History
131 lines (98 loc) · 3.9 KB

building_with_buildkit.md

File metadata and controls

131 lines (98 loc) · 3.9 KB

Building with BuildKit

Before starting, make sure you have Tekton and Shipwright Build installed.

See the Try It! section for more information.

Getting Started

Registry Authentication

For this tutorial, we will require to create a tutorial-secret Kubernetes secret to access a DockerHub registry, as follows:

$ REGISTRY_SERVER=https://index.docker.io/v1/ REGISTRY_USER=<your_registry_user> REGISTRY_PASSWORD=<your_registry_password>
$ kubectl create secret docker-registry tutorial-secret --docker-server=$REGISTRY_SERVER --docker-username=$REGISTRY_USER --docker-password=$REGISTRY_PASSWORD  [email protected]

Note: For more information about authentication, please refer to the related document.

Create the strategy

Ensure all strategies are in place, see the Try It! section for more information.

$ kubectl get cbs
NAME              AGE
buildah           96s
buildkit          78s
buildkit-insecure 78s
buildpacks-v3     96s
kaniko            96s
ko                96s
source-to-image   96s

Note: For more information about strategies, please refer to the related docs.

Creating a Build

For the Build definition, we will require the following:

  • A GitHub repository containing a Go application that requires a Dockerfile.
  • The tutorial-secret we just created.
  • The buildkit ClusterBuildStrategy.

Let's apply our Build and wait for it to be ready:

$ export REGISTRY_ORG=<your_registry_org>
$ cat <<EOF | kubectl apply -f -
apiVersion: shipwright.io/v1beta1
kind: Build
metadata:
  name: go-tutorial-buildkit
spec:
  source:
    git:
      url: https://github.com/shipwright-io/sample-go
    contextDir: docker-build
  strategy:
    name: buildkit
    kind: ClusterBuildStrategy
  output:
    image: docker.io/${REGISTRY_ORG}/go-tutorial:latest
    pushSecret: tutorial-secret
EOF

Verify that the go-tutorial Build was created successfully:

$ kubectl get build
NAME                         REGISTERED   REASON      BUILDSTRATEGYKIND      BUILDSTRATEGYNAME   CREATIONTIME
go-tutorial-buildkit         True         Succeeded   ClusterBuildStrategy   buildkit            4s

Note: For more information about Build resources, please refer to the related docs.

Creating a BuildRun

Second, we will create a BuildRun resource that references our previous go-tutorial Build:

$ cat <<EOF | kubectl create -f -
apiVersion: shipwright.io/v1beta1
kind: BuildRun
metadata:
  name: a-buildkit-buildrun
spec:
  build:
    name: go-tutorial-buildkit
EOF

Wait until your go-tutorial-buildrun buildrun is completed:

$ kubectl get buildrun
NAME                  SUCCEEDED   REASON    STARTTIME   COMPLETIONTIME
a-buildkit-buildrun   Unknown     Pending   4s

To know more about the state of the BuildRun, the .status.conditions fields provide more data:

$ kubectl get buildrun a-buildkit-buildrun -o json | jq '.status.conditions[]'
{
  "lastTransitionTime": "2021-04-01T09:15:13Z",
  "message": "All Steps have completed executing",
  "reason": "Succeeded",
  "status": "True",
  "type": "Succeeded"
}

Note: A BuildRun is a resource that runs to completion. The REASON column reflects the state of the resource. If the BuildRun ran to completion successfully, a Succeeded REASON is expected.

Note: For more information about BuildRun resources, please refer to the related docs.

Closing

Congratulations! You just created a container image from https://github.com/shipwright-io/sample-go using BuildKit.

The new container image should now be available in your container registry.