Images provide a configuration for build service to build and maintain a docker image utilizing Tanzu, Paketo, and custom Cloud Native Buildpacks.
Build Service will monitor the inputs to the image configuration to rebuild the image when the underlying source or buildpacks have changed.
The following procedures describe how to create and manage images in Build Service with the kp
cli.
Prerequisites:
The kp
cli supports creating Images using source code from the following locations:
You can specify only one location for app source code.
Users can select a Custom Builder or a Custom Cluster Builder to be used to create image builds. You can use any of the available Custom Builders or Custom Cluster Builders with any of the source types (git, blob, or local).
If you do not use the --custom-builder
or --custom-cluster-builder
flags, the default
Custom Cluster Builder will be used.
For more information on Builders, see Managing Builders.
To create an image using source code from a git repository run:
kp image create <name> <tag> \
[--custom-builder <custom-builder> or --custom-cluster-builder <custom-cluster-builder>] \
--namespace <namespace> \
--env <env> \
--git <git-repo> \
--git-revision <git-revision>
Where:
name
: The name of the image.tag
: The registry location where the image will be created.custom-builder
: (optional) Custom Builder name to be used in the image.custom-cluster-builder
: (optional) Custom Cluster Builder name to be used in the image. Defaults to default
when custom-builder
is not set.namespace
: (optional) The kubernetes namespace for the image. Defaults to the local kubernetes current-context namespace.env
(optional): Image environment variable configuration as key=val pairs (env_var=env_val
). The --env
flag can be specified multiple times.git-repo
Git repository url of the source code.git-revision
(optional) The Git revision of the code that the image is built against. Can be either a branch
, tag
or a commit sha
. When you target the image against a branch, Build Service triggers a build for every new commit. Defaults to master
.Note: If the `git-repo` is a private repository, you must configure the git credentials. For more info, see [Managing Git Repositories for a Project](managing-secrets.html#manage-git-repos)
Users can apply local source code from a directory, compressed source code (zip
, tar.gz
, .tar
), or a .jar
file.
To create an image using source code from a local machine run:
kp image create <name> <tag> --custom-builder <custom-builder> --namespace <namespace> --env <env> --local-path <source-path>
or
kp image create <name> <tag> --custom-cluster-builder <custom-cluster-builder> --namespace <namespace> --env <env> --local-path <source-path>
Where:
name
: The name of the image.tag
: The registry location where the image will be created.custom-builder
: (optional) Custom Builder name to be used in the image.custom-cluster-builder
: (optional) Custom Cluster Builder name to be used in the image. Defaults to default
when custom-builder
is not set.namespace
: (optional) The kubernetes namespace for the image. Defaults to the local kubernetes current-context namespace.env
(optional): Image environment variable configuration as key=val pairs (env_var=env_val
). The --env
flag can be specified multiple times.source-path
Path to local source code.Users can specify source code in a blob store saved as a compressed file (zip
, tar.gz
, .tar
) or a .jar
file.
To create an image using source code from blob store:
kp image create <name> <tag> --custom-builder <custom-builder> --namespace <namespace> --env <env> --blob <blob-url>
or
kp image create <name> <tag> --custom-cluster-builder <custom-cluster-builder> --namespace <namespace> --env <env> --blob <blob-url>
Where:
name
: The name of the image.tag
: The registry location where the image will be created.custom-builder
: (optional) Custom Builder name to be used in the image.custom-cluster-builder
: (optional) Custom Cluster Builder name to be used in the image. Defaults to default
when custom-builder
is not set.namespace
: (optional) The kubernetes namespace for the image. Defaults to the local kubernetes current-context namespace.env
(optional): Image environment variable configuration as key=val pairs (env_var=env_val
). The --env
flag can be specified multiple times.blob-url
URL of the source code blob file.Note: The source code file in the blobstore must be publically viewable.
Users can patch their existing images with the kp
cli with the same arguments as (create)[#create-image]. Running a patch will trigger a new build of the image if any of the build inputs are changed.
Patch images with the following commands:
With Source Code in a Git Repository
With With Local Source Code
With Source Code In A Blob Store
Where:
name
: The name of the image to patch.tag
: The registry location where the image will be created.namespace
: (optional) The kubernetes namespace for the image. Defaults to the local kubernetes current-context namespace.env
(optional): Image environment variable configuration as key=val pairs (env_var=env_val
). The --env
flag can be specified multiple times.git-repo
Git repository url of the source code. Must select one of git-repo
, blob-url
, or source-path
git-revision
(optional) The Git revision of the code that the image is built against. Can be either a branch
, tag
or a commit sha
. When you target the image against a branch, Build Service triggers a build for every new commit. Defaults to master
.blob-url
URL of the source code blob file. Must select one of git-repo
, blob-url
, or source-path
source-path
Path to local source code. Must select one of git-repo
, blob-url
, or source-path
Note: If the `git-repo` is a private repository, you must configure the git credentials. For more info, see [Managing Git Repositories for a Project](managing-secrets.html#manage-git-repos)
Note: The `tag` (location in a registry) of an image cannot be modified. To push builds to a new `tag` you must create a new image.
To list all the image configurations in a kubernetes namespace:
kp image list --namespace <namespace>
The following is an example of the output for this command:
Rebuilds happen in three ways:
kp image patch
.An imperative rebuild will be initiated if any of the following changes are made to an image:
An update to the commit, branch, Git repository, or other arguments to kp image patch
.
You upload a new copy of the local source code by running kp image patch --local-path <source-path>
, where <source-path>
is the source code path.
For more information, see Patching Images.
Build Service auto-rebuilds images when one or more of the following build inputs change:
New buildpack versions are made available through an updated builder image.
There is a new commit on a branch or tag Tanzu Build Service is tracking.
There is a new Stack (ie. base OS image) available, such as full
, tiny
, or base
.
You can initiate a manual rebuild using kp
:
kp image trigger <image-name>
This is useful for debugging image builds.
When a user creates an image using the above workflow, they are configuring Tanzu Build Service to start creating builds of the image which create container images to be pushed to a registry.
If a particular build associated with an image fails, check the status of the image by running:
kp image status <image-name>
Where image-name
is the name of the image. See Listing Images to get image names.
The following is an example output of this command:
This procedure describes how to delete a Build Service image with the kp
cli.
Warning: Deleting an image also deletes all the builds that the image owns. It does not delete the images generated by those builds.
To delete an image:
kp image delete <image>
Where image
is the name of the image.
When you successfully delete an image, you will see this message:
The procedures in this section describe how to view information and logs for image builds using the kp
cli.
Build Service stores the ten most recent successful builds and the ten most recent failed builds.
To see a the list of builds for an image run:
kp build list <image-name>
The following is an example of the output for this command:
The following describes the fields in the example output:
BUILD
: Describes the index of builds in the order that they were built.
STATUS
: Describes the status of a previous build image.
IMAGE
: The full image reference for the app image produced by the build.
STARTED
: Describes when a build started.
FINISHED
: Describes when a build finished.
REASON
: Describes why an image rebuild occured. These reasons include:
CONFIG
: Occurs when a change is made to commit, branch, Git repository, or build fields on the image's configuration file and you run kp image apply
.COMMIT
: Occurs when new source code is committed to a branch or tag build service is monitoring for changes.BUILDER
: Occurs when new buildpack versions are made available through an updated builder image. Note: A rebuild can occur for more than one reason. When there are multiple reasons for a rebuild, the kp
CLI output shows the primary Reason
and appends a +
sign to the Reason
field. The priority rank for the Reason
, from highest to lowest, is CONFIG
, COMMIT
, and BUILDER
.
STACK
: Occurs when a new base OS image, called a run image
, is available.TRIGGER
: Occurs when a new build is manually triggered.To display retrieve a detailed Bill of Materials for a particular build:
kp build status <image> -b <build-number>
Where:
image-name
is the name of the image the build is associated withbuild-name
(optional) is the index of the build from listing builds. Defaults to latest build.The following is an example of the output for this command:
The following describes the fields in the example output:
Image
: The full image reference for the app image produced by the build.
Status
: Describes the status of a previous build image.
Reason
: Describes why an image rebuild occured. These reasons include:
CONFIG
: Occurs when a change is made to commit, branch, Git repository, or build fields on the image's configuration file and you run kp image apply
.COMMIT
: Occurs when new source code is committed to a branch or tag build service is monitoring for changes.BUILDER
: Occurs when new buildpack versions are made available through an updated builder image. Note: A rebuild can occur for more than one reason. When there are multiple reasons for a rebuild, the kp
CLI output shows the primary Reason
and appends a +
sign to the Reason
field. The priority rank for the Reason
, from highest to lowest, is CONFIG
, COMMIT
, and BUILDER
.
STACK
: Occurs when a new base OS image (called a run image
) is available.TRIGGER
: Occurs when a new build is manually triggered.Builder
: The full image tag for the builder image used by the build.
Run Image
: The full image tag for the run image used by the app.
Source
: Describes where the source code used to build the image is coming from. Can be Git
, Blob
, or Local Source
.
Url
: The Git repository URL for Git
source, the Blob file URL for Blob
source. Unset for Local Source
.
Revision
: The Git commit sha of the source code used to create the build for Git
source.
BUILDPACK ID
: A list of buildpack ids the build used.
BUILDPACK VERSION
: A list of buildpack versions the build used.
An image that a user creates will cause builds to be initiated for that image. Builds are where Cloud Native Buildpacks are run and apps get built into images.
Build logs are a good way to debug issues and to get information about how your app is being built.
If you get logs of a build in progress, the logs will be tailed and will terminate when the build completes.
To get logs from a build run:
kp build logs <image> --build <build-number>
Where:
image-name
is the name of the image the build is associated withbuild-name
(optional) is the index of the build from listing builds. Defaults to latest build.The following is an example of the output of the command:
Build Services images can be created by applying the kpack image resources to cluster.
The default
service account should be used to utilize build service registry and git secrets.
The builder
field on the kpack Image spec describes the builder that will build the image.
Using a a Custom Builder
name
: The name of the Custom Builder.Using a Custom Cluster Builder
name
: The name of the cluster builder resource.For more info on manging builders, see Managing Builders.
Warning: Unlike with kp
you will need to explicitly set the builder in the image configuration and it will not default to the default
builder.
The default
service account should be used to utilize build service registry and git secrets. kpack will default to the default
service account if no service account is specified.
When an image has successfully built with its current configuration, its status will report the up to date fully qualified built image reference.
This information is available with kubectl describe image <image-name>
.
When a build fails its status will report the condition Succeeded=False.