Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
Chapter 9. Performing advanced builds
The following sections provide instructions for advanced build operations including setting build resources and maximum duration, assigning builds to nodes, chaining builds, build pruning, and build run policies.
9.1. Setting build resources Link kopierenLink in die Zwischenablage kopiert!
By default, builds are completed by pods using unbound resources, such as memory and CPU. These resources can be limited.
Procedure
You can limit resource use in two ways:
- Limit resource use by specifying resource limits in the default container limits of a project.
Limit resource use by specifying resource limits as part of the build configuration. ** In the following example, each of the
,resources, andcpuparameters are optional:memoryapiVersion: "v1" kind: "BuildConfig" metadata: name: "sample-build" spec: resources: limits: cpu: "100m"1 memory: "256Mi"2 However, if a quota has been defined for your project, one of the following two items is required:
A
section set with an explicitresources:requestsresources: requests:1 cpu: "100m" memory: "256Mi"- 1
- The
requestsobject contains the list of resources that correspond to the list of resources in the quota.
A limit range defined in your project, where the defaults from the
object apply to pods created during the build process.LimitRangeOtherwise, build pod creation will fail, citing a failure to satisfy quota.
9.2. Setting maximum duration Link kopierenLink in die Zwischenablage kopiert!
When defining a
BuildConfig
completionDeadlineSeconds
The maximum duration is counted from the time when a build pod gets scheduled in the system, and defines how long it can be active, including the time needed to pull the builder image. After reaching the specified timeout, the build is terminated by OpenShift Container Platform.
Procedure
To set maximum duration, specify
in yourcompletionDeadlineSeconds. The following example shows the part of aBuildConfigspecifyingBuildConfigfield for 30 minutes:completionDeadlineSecondsspec: completionDeadlineSeconds: 1800
This setting is not supported with the Pipeline Strategy option.
9.3. Assigning builds to specific nodes Link kopierenLink in die Zwischenablage kopiert!
Builds can be targeted to run on specific nodes by specifying labels in the
nodeSelector
nodeSelector
Node
The
nodeSelector
nodeSelector
nodeSelector:{}
If the specified
NodeSelector
Pending
Procedure
Assign builds to run on specific nodes by assigning labels in the
field of thenodeSelector, for example:BuildConfigapiVersion: "v1" kind: "BuildConfig" metadata: name: "sample-build" spec: nodeSelector:1 key1: value1 key2: value2- 1
- Builds associated with this build configuration will run only on nodes with the
key1=value2andkey2=value2labels.
9.4. Chained builds Link kopierenLink in die Zwischenablage kopiert!
For compiled languages such as Go, C, C++, and Java, including the dependencies necessary for compilation in the application image might increase the size of the image or introduce vulnerabilities that can be exploited.
To avoid these problems, two builds can be chained together. One build that produces the compiled artifact, and a second build that places that artifact in a separate image that runs the artifact.
In the following example, a source-to-image (S2I) build is combined with a docker build to compile an artifact that is then placed in a separate runtime image.
Although this example chains a S2I build and a docker build, the first build can use any strategy that produces an image containing the desired artifacts, and the second build can use any strategy that can consume input content from an image.
The first build takes the application source and produces an image containing a
WAR
artifact-image
assemble
/wildfly/standalone/deployments/ROOT.war
apiVersion: build.openshift.io/v1
kind: BuildConfig
metadata:
name: artifact-build
spec:
output:
to:
kind: ImageStreamTag
name: artifact-image:latest
source:
git:
uri: https://github.com/openshift/openshift-jee-sample.git
ref: "master"
strategy:
sourceStrategy:
from:
kind: ImageStreamTag
name: wildfly:10.1
namespace: openshift
The second build uses image source with a path to the WAR file inside the output image from the first build. An inline
dockerfile
WAR
apiVersion: build.openshift.io/v1
kind: BuildConfig
metadata:
name: image-build
spec:
output:
to:
kind: ImageStreamTag
name: image-build:latest
source:
dockerfile: |-
FROM jee-runtime:latest
COPY ROOT.war /deployments/ROOT.war
images:
- from:
kind: ImageStreamTag
name: artifact-image:latest
paths:
- sourcePath: /wildfly/standalone/deployments/ROOT.war
destinationDir: "."
strategy:
dockerStrategy:
from:
kind: ImageStreamTag
name: jee-runtime:latest
triggers:
- imageChange: {}
type: ImageChange
- 1
fromspecifies that the docker build should include the output of the image from theartifact-imageimage stream, which was the target of the previous build.- 2
pathsspecifies which paths from the target image to include in the current docker build.- 3
- The runtime image is used as the source image for the docker build.
The result of this setup is that the output image of the second build does not have to contain any of the build tools that are needed to create the
WAR
9.5. Pruning builds Link kopierenLink in die Zwischenablage kopiert!
By default, builds that have completed their lifecycle are persisted indefinitely. You can limit the number of previous builds that are retained.
Procedure
Limit the number of previous builds that are retained by supplying a positive integer value for
orsuccessfulBuildsHistoryLimitin yourfailedBuildsHistoryLimit, for example:BuildConfigapiVersion: "v1" kind: "BuildConfig" metadata: name: "sample-build" spec: successfulBuildsHistoryLimit: 21 failedBuildsHistoryLimit: 22 Trigger build pruning by one of the following actions:
- Updating a build configuration.
- Waiting for a build to complete its lifecycle.
Builds are sorted by their creation timestamp with the oldest builds being pruned first.
Administrators can manually prune builds using the 'oc adm' object pruning command.
9.6. Build run policy Link kopierenLink in die Zwischenablage kopiert!
The build run policy describes the order in which the builds created from the build configuration should run. This can be done by changing the value of the
runPolicy
spec
Build
It is also possible to change the
runPolicy
-
Changing to
ParallelorSerialand triggering a new build from this configuration causes the new build to wait until all parallel builds complete as the serial build can only run alone.SerialLatestOnly -
Changing to
Serialand triggering a new build causes cancellation of all existing builds in queue, except the currently running build and the most recently created build. The newest build runs next.SerialLatestOnly