Buildkit is a cache-efficient, distributed build system for Docker images made by Moby. It is the standard builder used in the Docker daemon, however, it can also be deployed as a service. This tutorial covers how to use the bundled Buildkit instance with Dispatch.
- Basic knowledge of git, bash, and Docker.
- A GitHub account.
- Owner permissions for a project hosted on GitHub or access to create one.
- A Git repository containing a Dockerfile.
- Deploy access to a namespace in Kubernetes cluster.
- Dispatch CLI installed in the environment.
See Dispatch Installation for details.
Note When installing Dispatch, be sure to enable the
buildkit.enabled flag to enable Buildkit.
Setup repository in Dispatch
See Setting up a Repository in Dispatch for details.
Add your repository to the Dispatch instance:
dispatch ci repository create --service-account=team-1
Add a Dispatchfile to git repository
This tutorial uses starlark to create a file named
Dispatchfile that holds the build specification. This is a step-by-step walk-through of creating the
Declare the DSL (Domain Specific Language) syntax for our
This specifies to use version
0.5of starlark DSL parser.
Dispatch Catalog holds syntactic sugar for reusing various starlark functions that makes your
Dispatchfilesmaller and allows you focus on actual testing aspects.
Next, import the following helpers:
gitResource: to declare the git repository as a resource that can be sent as input to tasks
pullRequest: to declare a condition to trigger the builds whenever a pull request is updated
buildkit: to build and publish the Docker image
# Import the gitResource, pullRequest, and kaniko helpers from dispatch catalog load("email@example.com", "gitResource", "pullRequest") load("firstname.lastname@example.org", "buildkit")
Declare the git resource:
git = gitResource("helloworld-git")
Any valid kubernetes resource name can be chosen here.
Declare a task to build and push the Docker image using buildkit:
# Build and push the docker image simple_docker = buildkit("build", git, "$YOURDOCKERUSERNAME/helloworld")
Define an Action to run the task on every pull request:
Dispatchfile looks like the following:
#!mesosphere/dispatch-starlark:v0.5 # vi:syntax=python load("email@example.com", "gitResource", "pullRequest") load("firstname.lastname@example.org", "buildkit") git = gitResource("helloworld-git") # Build and push the docker image simple_docker = buildkit("build", git, "$YOURDOCKERUSERNAME/helloworld") simpleTasks = ["unit-test-simple"] action(tasks=simpleTasks, on=pullRequest())
See full reference of a Dispatchfile. After you commit and push the Dispatchfile and then create a pull request to your repository, the image will build.