Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
Chapter 2. Configuring build strategies
As a platform engineer, you can define consistent build strategies by specifying parameters, system settings, resource requirements, annotations, and volumes in BuildStrategy or ClusterBuildStrategy custom resources (CR). These strategies enable controlled and reusable build execution across the cluster.
2.1. Strategy parameters definition Link kopierenLink in die Zwischenablage kopiert!
Define parameters in a BuildStrategy or ClusterBuildStrategy custom resource (CR). You can then set or modify these values in your Build or BuildRun CRs.
Consider the following points before defining parameters for your strategy:
-
Define a list of parameters in the
spec.parametersfield of your build strategy CR. Each item includes a name, description, type, and optionally a default value (or values for array types). If no default value is set, you must define a value in theBuildorBuildRunCR. -
Define parameters of string or array type in the
spec.stepsfield of your build strategy. Specify a parameter of string type by using the
$(params.your-parameter-name)syntax. You can set a value for theyour-parameter-nameparameter in yourBuildorBuildRunCR that references your strategy. You can define the following string parameters based on your needs:Expand Table 2.1. String parameters Parameter Description imageUse this parameter to define a custom tag, such as
golang:$(params.go-version)argsUse this parameter to pass data into your builder commands
envUse this parameter to provide a value for an environment variable
Specify a parameter of array type by using the
$(params.your-array-parameter-name[*])syntax. After specifying the array, you can use it in an argument or a command. For each item in the array, an argument will be set. The following example uses an array parameter in thespec.stepsfield of the build strategy:Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Provide parameter values as simple strings or as references to keys in config maps or secrets. For a parameter, you can use a config map or secret value only if it is defined in the
command,args, orenvsection of thespec.stepsfield.
2.2. System parameters definition Link kopierenLink in die Zwischenablage kopiert!
Use system parameters to define the steps of a build strategy to access system information, or user-defined information in a Build or BuildRun custom resource (CR). You cannot configure or modify system parameters as they are defined at runtime by the build run controller.
You can define the following system parameters in your build strategy definition:
| Parameter | Description |
|---|---|
|
| Specifies the absolute path to the directory that contains the source code. |
|
|
Specifies the absolute path to the context directory of the source code. If you do not specify any value for |
|
|
Specifies the URL of the image to push as defined in the |
2.3. Step resources definition Link kopierenLink in die Zwischenablage kopiert!
Define CPU, memory, and disk limits for each step in a build strategy. If a strategy has multiple steps, you can allocate different resource amounts to each.
As an administrator, you can provide different versions of the same strategy (for example, buildah-small and buildah-large) so users can choose the resource profile that fits their build requirements.
2.3.1. Strategies with different resources Link kopierenLink in die Zwischenablage kopiert!
Define multiple variants of the same strategy to apply different resource limits for different build requirements.
The following examples use the same buildah strategy with small and medium limits defined for the resources.These examples provide a strategy administrator more control over the step resources definition.
You can define the spec.steps[].resources field with a small resource limit for the buildah strategy, as shown in the following example:
You can define the spec.steps[].resources field with a medium resource limit for the buildah strategy, as shown in the following example:
After configuring the resource definition for a strategy, you must reference the strategy in your Build custom resource (CR), as shown in the following example:
2.3.2. Resource management in Tekton pipelines Link kopierenLink in die Zwischenablage kopiert!
The build controller works with the Tekton pipeline controller to schedule pods that run strategy steps. At runtime, the build controller creates a Tekton TaskRun, which executes a Task and records status and results. The TaskRun creates a pod in the target namespace that runs all steps sequentially.
2.4. Annotations definition Link kopierenLink in die Zwischenablage kopiert!
Define annotations for a BuildStrategy or ClusterBuildStrategy in the same way as for any Kubernetes object. The build strategy passes these annotations to the TaskRun resource. Then, Tekton passes them to the pod.
You can use annotations for the following purposes:
-
Network bandwidth: Use
kubernetes.io/ingress-bandwidthorkubernetes.io/egress-bandwidthto limit the network bandwidth. -
Security profiles: Use
container.apparmor.security.beta.kubernetes.io/<container_name>to define AppArmor profiles of a container.
The following example shows the usage of annotations in a build strategy:
The following annotations are not passed to resources:
-
kubectl.kubernetes.io/last-applied-configuration -
clusterbuildstrategy.shipwright.io/* -
buildstrategy.shipwright.io/* -
build.shipwright.io/* -
buildrun.shipwright.io/*
A strategy administrator can further restrict the usage of annotations by using policy engines.
2.5. Secure referencing of string parameters Link kopierenLink in die Zwischenablage kopiert!
Use the $(params.your-parameter-name) syntax to reference string parameters in your build strategy. When the build runs, the system replaces the variable with the actual strings.
You can use the $(params.your-parameter-name) syntax for system and strategy parameters.
To prevent command injection vulnerabilities when using inline scripts, use one of the following secure methods:
- Use environment variables
Use arguments
- Reference a string parameter into an environment variable
Pass the parameter into an environment variable. Then, use quotes around that variable in your script. The following example uses an environment variable inside the script to reference a string parameter:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Reference a string parameter into an argument
Pass the parameter as an argument to the script. Then, use a shell variable to read it. The following example uses an argument defined within your script to reference a string parameter:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.6. System results definition Link kopierenLink in die Zwischenablage kopiert!
Store the image size and digest or content hash produced by the build strategy in a set of result files. Error details for debugging can also be recorded when a BuildRun resource fails.
The following result parameters can be defined in the BuildStrategy or ClusterBuildStrategy custom resource (CR):
| Parameter | Description |
|---|---|
|
| Specifies the path to the file that stores the digest or the content hash of the image. |
|
| Specifies the path to the file that stores the compressed size of the image. |
|
| Specifies the path to the file that stores the error reason. |
|
| Specifies the path to the file that stores the error message. |
The following example shows the size and digest or the content hash of the image in the .status.output field of the BuildRun CR:
The following example shows the error reason and message in the .status.failureDetails field of the BuildRun CR:
2.7. Volumes and volume mounts definition Link kopierenLink in die Zwischenablage kopiert!
Build strategies use volumes and volume mounts to manage data during build steps. By default, you cannot override the volumes in a BuildStrategy. To allow a Build or BuildRun to use a custom volume, you must set overridable field to true in the strategy.
The volume mount defined in build steps allows you to access volumes defined in a BuildStrategy, Build or BuildRun resource.
Volumes in build strategy use an overridable boolean flag, which is set to false by default. If a Build or BuildRun resource tries to override the volumes defined in a BuildStrategy resource, it will fail because the default value of the overridable flag is false.
The following example shows a BuildStrategy resource that defines the volumes and volumeMounts fields: