Chapter 1. Managing Builds
After installing Builds, you can create builds using buildah or source-to-image build strategies. You can also delete custom resources that are not required for a build.
1.1. Creating a buildah build Copy linkLink copied to clipboard!
You can create a buildah build and push the created image to the target registry.
Prerequisites
- You have installed the Builds for Red Hat OpenShift Operator on the OpenShift Container Platform cluster.
-
You have created a
ShipwrightBuildresource. -
You have installed the
ocCLI. -
Optional: You have installed the
shpCLI.
Procedure
Create a
Buildresource and apply it to the OpenShift Container Platform cluster by using one of the CLIs:Example: Using
ocCLI$ oc apply -f - <<EOF apiVersion: shipwright.io/v1beta1 kind: Build metadata: name: buildah-golang-build spec: source:1 type: Git git: url: https://github.com/shipwright-io/sample-go contextDir: docker-build strategy:2 name: buildah kind: ClusterBuildStrategy paramValues:3 - name: dockerfile value: Dockerfile output:4 image: image-registry.openshift-image-registry.svc:5000/buildah-example/sample-go-app EOF- 1
- The location where the source code is placed.
- 2
- The build strategy that you use to build the container.
- 3
- The parameter defined in the build strategy. To set the value of the
dockerfilestrategy parameter, specify the Dockerfile location required to build the output image. - 4
- The location where the built image is pushed. In this procedural example, the built image is pushed to the OpenShift Container Platform cluster internal registry.
buildah-exampleis the name of the current project. Ensure that the specified project exists to allow the image push.
Example: Using
shpCLI$ shp build create buildah-golang-build \ --source-url="https://github.com/redhat-openshift-builds/samples" --source-context-dir="buildah-build" \1 --strategy-name="buildah" \2 --dockerfile="Dockerfile" \3 --output-image="image-registry.openshift-image-registry.svc:5000/buildah-example/go-app"4 - 1
- The location where the source code is placed.
- 2
- The build strategy that you use to build the container.
- 3
- The parameter defined in the build strategy. To set the value of the
dockerfilestrategy parameter, specify the Dockerfile location required to build the output image. - 4
- The location where the built image is pushed. In this procedural example, the built image is pushed to the OpenShift Container Platform cluster internal registry.
buildah-exampleis the name of the current project. Ensure that the specified project exists to allow the image push.
Check if the
Buildresource is created by using one of the CLIs:Example: Using
ocCLI$ oc get builds.shipwright.io buildah-golang-buildExample: Using
shpCLI$ shp build listCreate a
BuildRunresource and apply it to the OpenShift Container Platform cluster by using one of the CLIs:Example: Using
ocCLI$ oc apply -f - <<EOF apiVersion: shipwright.io/v1beta1 kind: BuildRun metadata: name: buildah-golang-buildrun spec: build: name: buildah-golang-build1 EOF- 1
- The
spec.build.namefield denotes the respective build to run, which is expected to be available in the same namespace.
Example: Using
shpCLI$ shp build run buildah-golang-build --follow1 - 1
- Optional: By using the
--followflag, you can view the build logs in the output result.
Check if the
BuildRunresource is created by running one of the following commands:Example: Using
ocCLI$ oc get buildrun buildah-golang-buildrunExample: Using
shpCLI$ shp buildrun listThe
BuildRunresource creates aTaskRunresource, which then creates the pods to execute build strategy steps.
Verification
After all the containers complete their tasks, verify the following:
Check whether the pod shows the
STATUSfield asCompleted:$ oc get pods -wExample output
NAME READY STATUS RESTARTS AGE buildah-golang-buildrun-dtrg2-pod 2/2 Running 0 4s buildah-golang-buildrun-dtrg2-pod 1/2 NotReady 0 7s buildah-golang-buildrun-dtrg2-pod 0/2 Completed 0 55sCheck whether the respective
TaskRunresource shows theSUCCEEDEDfield asTrue:$ oc get trExample output
NAME SUCCEEDED REASON STARTTIME COMPLETIONTIME buildah-golang-buildrun-dtrg2 True Succeeded 11m 8m51sCheck whether the respective
BuildRunresource shows theSUCCEEDEDfield asTrue:$ oc get brExample output
NAME SUCCEEDED REASON STARTTIME COMPLETIONTIME buildah-golang-buildrun True Succeeded 13m 11mDuring verification, if a build run fails, you can check the
status.failureDetailsfield in yourBuildRunresource to identify the exact point where the failure happened in the pod or container.NoteThe pod might switch to a
NotReadystate because one of the containers has completed its task. This is an expected behavior.
Validate whether the image has been pushed to the registry that is specified in the
build.spec.output.imagefield. You can try to pull the image by running the following command from a node that can access the internal registry:$ podman pull image-registry.openshift-image-registry.svc:5000/<project>/<image>1 - 1
- The project name and image name used when creating the
Buildresource. For example, you can usebuildah-exampleas the project name andsample-go-appas the image name.
1.2. Creating a source-to-image build Copy linkLink copied to clipboard!
You can create a source-to-image build and push the created image to a custom Quay repository.
Prerequisites
- You have installed the Builds for Red Hat OpenShift Operator on the OpenShift Container Platform cluster.
-
You have created a
ShipwrightBuildresource. -
You have installed the
ocCLI. -
Optional: You have installed the
shpCLI.
Procedure
Create a
Buildresource and apply it to the OpenShift Container Platform cluster by using one of the CLIs:Example: Using
ocCLI$ oc apply -f - <<EOF apiVersion: shipwright.io/v1beta1 kind: Build metadata: name: s2i-nodejs-build spec: source:1 type: Git type: Git git: url: https://github.com/redhat-openshift-builds/samples contextDir: s2i-build/nodejs strategy:2 name: source-to-image kind: ClusterBuildStrategy paramValues:3 - name: builder-image value: quay.io/centos7/nodejs-12-centos7:master output: image: quay.io/<repo>/s2i-nodejs-example4 pushSecret: registry-credential5 EOF- 1
- The location where the source code is placed.
- 2
- The build strategy that you use to build the container.
- 3
- The parameter defined in the build strategy. To set the value of the
builder-imagestrategy parameter, specify the builder image location required to build the output image. - 4
- The location where the built image is pushed. You can push the built image to a custom Quay.io repository. Replace
repowith a valid Quay.io organization or your Quay user name. - 5
- The secret name that stores the credentials for pushing container images. To generate a secret of the type
docker-registryfor authentication, see "Authentication to container registries".
Example: Using
shpCLI$ shp build create s2i-nodejs-build \ --source-url="https://github.com/redhat-openshift-builds/samples" --source-context-dir="s2i-build/nodejs" \1 --strategy-name="source-to-image" \2 --builder-image="quay.io/centos7/nodejs-12-centos7" \3 --output-image="quay.io/<repo>/s2i-nodejs-example" \4 --output-credentials-secret="registry-credential"5 - 1
- The location where the source code is placed.
- 2
- The build strategy that you use to build the container.
- 3
- The parameter defined in the build strategy. To set the value of the
builder-imagestrategy parameter, specify the builder image location required to build the output image. - 4
- The location where the built image is pushed. You can push the built image to a custom Quay.io repository. Replace
repowith a valid Quay.io organization or your Quay user name. - 5
- The secret name that stores the credentials for pushing container images. To generate a secret of the type
docker-registryfor authentication, see "Authentication to container registries".
Check if the
Buildresource is created by using one of the CLIs:Example: Using
ocCLI$ oc get builds.shipwright.io s2i-nodejs-buildExample: Using
shpCLI$ shp build listCreate a
BuildRunresource and apply it to the OpenShift Container Platform cluster by using one of the CLIs:Example: Using
ocCLI$ oc apply -f - <<EOF apiVersion: shipwright.io/v1beta1 kind: BuildRun metadata: name: s2i-nodejs-buildrun spec: build: name: s2i-nodejs-build1 EOF- 1
- The
spec.build.namefield denotes the respective build to run, which is expected to be available in the same namespace.
Example: Using
shpCLI$ shp build run s2i-nodejs-build --follow1 - 1
- Optional: By using the
--followflag, you can view the build logs in the output result.
Check if the
BuildRunresource is created by running one of the following commands:Example: Using
ocCLI$ oc get buildrun s2i-nodejs-buildrunExample: Using
shpCLI$ shp buildrun listThe
BuildRunresource creates aTaskRunresource, which then creates the pods to execute build strategy steps.
Verification
After all the containers complete their tasks, verify the following:
Check whether the pod shows the
STATUSfield asCompleted:$ oc get pods -wExample output
NAME READY STATUS RESTARTS AGE s2i-nodejs-buildrun-phxxm-pod 2/2 Running 0 10s s2i-nodejs-buildrun-phxxm-pod 1/2 NotReady 0 14s s2i-nodejs-buildrun-phxxm-pod 0/2 Completed 0 2mCheck whether the respective
TaskRunresource shows theSUCCEEDEDfield asTrue:$ oc get trExample output
NAME SUCCEEDED REASON STARTTIME COMPLETIONTIME s2i-nodejs-buildrun-phxxm True Succeeded 2m39s 13sCheck whether the respective
BuildRunresource shows theSUCCEEDEDfield asTrue:$ oc get brExample output
NAME SUCCEEDED REASON STARTTIME COMPLETIONTIME s2i-nodejs-buildrun True Succeeded 2m41s 15sDuring verification, if a build run fails, you can check the
status.failureDetailsfield in yourBuildRunresource to identify the exact point where the failure happened in the pod or container.NoteThe pod might switch to a
NotReadystate because one of the containers has completed its task. This is an expected behavior.
Validate whether the image has been pushed to the registry that is specified in the
build.spec.output.imagefield. You can try to pull the image by running the following command after logging in to the registry:$ podman pull quay.io/<repo>/<image>1 - 1
- The repository name and image name used when creating the
Buildresource. For example, you can uses2i-nodejs-exampleas the image name.
1.3. Editing the resources Copy linkLink copied to clipboard!
You can edit the resources that are created by buildah and source-to-image build processes using the oc CLI. You can modify the resources as needed in your project.
Prerequisites
-
You have installed the
ocCLI.
Procedure
Run the following command to open the YAML definition in the default editor:
$ oc edit <resource_name> <build_resource_name>1 - 1
- Replace
<resource_name>with the name of the resource (build,buildrunorbuildstrategy) and<build_resource_name>with the name of the build resource that you want to edit.
- Edit the YAML definition and save the file.
1.4. Deleting the resources Copy linkLink copied to clipboard!
You can delete resources created by the Buildah and Source-to-Image (S2I) build processes using the oc CLI or the shp CLI. Deleting these resources helps you to clean up build configurations that are no longer required in your project.
1.4.1. Deleting a build resource Copy linkLink copied to clipboard!
You can delete a build resource if it is not required in your project.
Prerequisites
-
You have installed the
ocCLI. - Optional: You have installed the shp CLI.
Procedure
Delete a
buildresource by using one of the following CLIs:
1.4.2. Deleting a buildrun resource Copy linkLink copied to clipboard!
You can delete a buildrun resource if it is not required in your project.
Prerequisites
-
You have installed the
ocCLI. - Optional: You have installed the shp CLI.
Procedure
Delete a
buildresource by using one of the following CLIs:
1.4.3. Deleting a buildstrategy resource Copy linkLink copied to clipboard!
You can delete a buildstrategy resource if it is not required in your project.
Prerequisites
-
You have installed the
ocCLI.
Procedure
Delete a
buildstrategyresource by using theocCLI:$ oc delete buildstrategy <buildstartegy_resource_name>1 - 1
- Replace <buildstartegy_resource_name> with the name of the
buildstrategyresource.