Version v1.39 of the documentation is no longer actively maintained. The site that you are currently viewing is an archived snapshot. For up-to-date documentation, see the latest version.
Building Artifacts with a Custom Build Script
This page describes building Skaffold artifacts using a custom build script, which builds images using ko. ko builds containers from Go source code, without the need for a Dockerfile or even installing Docker.
Before you begin
First, you will need to have Skaffold and a Kubernetes cluster set up. To learn more about how to set up Skaffold and a Kubernetes cluster, see the quickstart docs.
Tutorial - Hello World in Go
This tutorial will be based on the custom example in our repository.
Adding a Custom Builder to Your Skaffold Project
First, add a
build.sh file which Skaffold will call to build artifacts:
#!/usr/bin/env bash set -e if ! [ -x "$(command -v ko)" ]; then GO111MODULE=on go get -mod=readonly email@example.com fi output=$(ko publish --local --preserve-import-paths --tags= . | tee) ref=$(echo $output | tail -n1) docker tag $ref $IMAGE if $PUSH_IMAGE; then docker push $IMAGE fi
Then, configure artifacts in your
skaffold.yaml to build with
apiVersion: skaffold/v2alpha1 kind: Config build: artifacts: - image: gcr.io/k8s-skaffold/skaffold-custom custom: buildCommand: ./build.sh dependencies: paths: - .
List the file dependencies for each artifact; in the example above, Skaffold watches all files in the build context. For more information about listing dependencies for custom artifacts, see the documentation here.
You can check custom builder is properly configured by running
This command should build the artifacts and exit successfully.