-
Notifications
You must be signed in to change notification settings - Fork 1.8k
RHDEVDOCS-6488: creating build with buildpacks #95748
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
deerskindoll
wants to merge
2
commits into
openshift:build-docs-main
Choose a base branch
from
deerskindoll:RHDEVDOCS-6488
base: build-docs-main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,257 @@ | ||
:_mod-docs-content-type: PROCEDURE | ||
[id="ob-creating-a-buildpacks-build_{context}"] | ||
= Creating a buildpacks build | ||
|
||
Learn how to create a buildpacks build and push the created image into the target registry. | ||
There are two buildpacks `ClusterBuildStrategy` options are available for {builds-title}: | ||
|
||
* `buildpacks` strategy | ||
* `buildpacks-extender`strategy | ||
|
||
[NOTE] | ||
==== | ||
The `buildpacks-extender`strategy is compatible with the experimental buildpacks`extender` lifecycle phase. You can use this strategy e.g for builds based on Node.js. However, the `extender` phase does not support Quarkus or any other Java-based builds. For such builds, you should use the `buildpacks` strategy instead. | ||
==== | ||
|
||
[IMPORTANT] | ||
==== | ||
Buildpacks is a Technology Preview feature only. Technology Preview features are not supported with Red{nbsp}Hat production service level agreements (SLAs) and might not be functionally complete. Red{nbsp}Hat does not recommend using them in production. These features provide early access to upcoming product features, enabling customers to test functionality and provide feedback during the development process. | ||
|
||
For more information about the support scope of Red{nbsp}Hat Technology Preview features, see link:https://access.redhat.com/support/offerings/techpreview/[Technology Preview Features Support Scope]. | ||
==== | ||
|
||
.Prerequisites | ||
|
||
* You have installed the {builds-operator} on the {ocp-product-title} cluster. | ||
* You have installed the `oc` CLI. | ||
* You have created the project where your final application image will be stored by using the command `oc new-project buildpacks-example`. | ||
* Optional: You have installed the `shp` CLI. | ||
|
||
.Procedure | ||
. Grant permission to access the image registry in the `buildpacks-example` project to the `pipeline` service with the two following commands: | ||
+ | ||
[source,terminal] | ||
---- | ||
$ oc policy add-role-to-user system:image-puller system:serviceaccount:default:pipeline --namespace=buildpacks-example | ||
---- | ||
+ | ||
[source,terminal] | ||
---- | ||
$ oc policy add-role-to-user system:image-pusher system:serviceaccount:default:pipeline --namespace=buildpacks-example | ||
---- | ||
. Switch back to the primary working project: | ||
+ | ||
[source,terminal] | ||
---- | ||
$ oc project default | ||
---- | ||
. Apply the permission: | ||
+ | ||
[source,terminal] | ||
---- | ||
$ oc create rolebinding allow-builds-to-push \ | ||
|
||
--clusterrole=edit \ | ||
|
||
--serviceaccount=default:pipeline \ | ||
|
||
--namespace=buildpacks-example | ||
---- | ||
. Create a `Build` resource and apply it to the {ocp-product-title} cluster: | ||
.. Using `oc` CLI | ||
+ | ||
[source,terminal] | ||
---- | ||
$ oc apply -f - <<EOF | ||
apiVersion: shipwright.io/v1beta1 | ||
|
||
kind: Build | ||
|
||
metadata: | ||
|
||
name: buildpack-nodejs-build | ||
|
||
spec: | ||
|
||
source: <1> | ||
|
||
type: Git | ||
|
||
git: | ||
|
||
url: https://github.com/redhat-openshift-builds/samples.git | ||
|
||
strategy: <2> | ||
|
||
name: buildpacks | ||
|
||
kind: ClusterBuildStrategy | ||
|
||
retention: | ||
|
||
atBuildDeletion: true | ||
|
||
paramValues: <3> | ||
|
||
- name: run-image <4> | ||
|
||
value: paketobuildpacks/run-ubi8-base:latest | ||
|
||
- name: cnb-builder-image <5> | ||
|
||
value: paketobuildpacks/builder-jammy-tiny:0.0.344 | ||
|
||
- name: source-subpath <6> | ||
|
||
value: "buildpacks/nodejs" | ||
|
||
output: <7> | ||
image: image-registry.openshift-image-registry.svc:5000/buildpacks-example/taxi-app | ||
EOF | ||
---- | ||
<1> The Git repository containing your application source code. | ||
<2> The build strategy to build the container. | ||
<3> Parameters set for the buildpacks strategy. | ||
<4> The base image on which your application will run. | ||
<5> The builder image used by Cloud Native Buildpacks (CNB) to detect and build your application. | ||
<6> The subdirectory within your Git repository where the application source code is located. | ||
<7> The location where the built image is pushed. | ||
+ | ||
.. Using `shp` CLI: | ||
+ | ||
[source,terminal] | ||
---- | ||
$ shp build create buildpack-nodejs-build \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just for reference, this is the main command due to which we have to give permissions and follow extra steps if we wanna use shp cli. |
||
|
||
--source-git-url="https://github.com/redhat-openshift-builds/samples.git" \ | ||
|
||
--strategy-name="buildpacks" \ | ||
|
||
--output-image="image-registry.openshift-image-registry.svc:5000/buildpacks-example/taxi-app" \ | ||
|
||
--param-value="source-subpath=buildpacks/nodejs" \ | ||
|
||
--param-value="cnb-builder-image=paketobuildpacks/builder-jammy-tiny:0.0.344" \ | ||
--param-value="run-image=paketobuildpacks/run-ubi8-base:latest" | ||
---- | ||
. Check if the `Build` resource was created: | ||
.. Using `oc` CLI: | ||
+ | ||
[source,terminal] | ||
---- | ||
$ oc get builds.shipwright.io buildpack-nodejs-build | ||
---- | ||
.. Using `shp` CLI: | ||
+ | ||
[source,terminal] | ||
---- | ||
$ shp build list | ||
---- | ||
. Create a `BuildRun` resource and apply it to the {ocp-product-title} cluster: | ||
.. .. Using `oc` CLI: | ||
+ | ||
[source,terminal] | ||
---- | ||
$ oc apply -f - <<EOF | ||
apiVersion: shipwright.io/v1beta1 | ||
kind: BuildRun | ||
metadata: | ||
name: buildpack-nodejs-buildrun | ||
namespace: builds-test | ||
spec: | ||
build: | ||
name: buildpack-nodejs-build <1> | ||
EOF | ||
---- | ||
<1> Reference to the `buildpack-nodejs-build` resource that will be executed. | ||
.. Using `shp` CLI: | ||
+ | ||
... | ||
[source,terminal] | ||
---- | ||
$ shp build run buildpack-nodejs-buildrun --follow | ||
---- | ||
+ | ||
[IMPORTANT] | ||
==== | ||
The `shp` CLI version 0.16.0 cannot automatically generate a name for the `BuildRun` resource. | ||
You must create the name manually: | ||
|
||
. Create a `BuilRun` resource with a unique name | ||
+ | ||
[source,terminal] | ||
---- | ||
$ shp buildrun create buildpack-nodejs-<buildrun_resource_name> --buildref-name buildpack-nodejs-build <1> | ||
---- | ||
<1> Flag referencing the build. | ||
|
||
. Follow the logs: | ||
+ | ||
[source,terminal] | ||
---- | ||
$ shp buildrun logs buildpack-nodej-<buildrun_resource_name> --follow | ||
---- | ||
==== | ||
. Check if the `BuildRun` resource was created: | ||
.. Using `oc` CLI: | ||
+ | ||
[source,terminal] | ||
---- | ||
$ oc get buildrun buildpack-nodejs-buildrun | ||
---- | ||
.. Using `shp` CLI: | ||
+ | ||
[source,terminal] | ||
---- | ||
$ shp buildrun list | ||
---- | ||
[NOTE] | ||
==== | ||
The `BuildRun` resource creates a `TaskRun` resource, which then creates the pods to execute build strategy steps. | ||
==== | ||
|
||
.Verification | ||
. Wait for all containers to complete their tasks. | ||
. Check if the pod shows the `STATUS` field as `Completed`: | ||
+ | ||
[source,terminal] | ||
---- | ||
$ oc get pods -w | ||
---- | ||
. Check if the `TaskRun` resource shows the `SUCCESS` field as `True`: | ||
+ | ||
[source,terminal] | ||
---- | ||
$ oc get tr | ||
---- | ||
. Check if the `BuildRun` resource shows the `SUCCESS` field as `True`: | ||
+ | ||
[source,terminal] | ||
---- | ||
$ oc get br | ||
---- | ||
+ | ||
[NOTE] | ||
==== | ||
If the build run fails, you can check the `status.failureDetails` field in your `BuildRun` resource to identify the exact point where the failure happened in the pod or container. | ||
|
||
The pod might switch to a `NotReady` state because one of the containers has completed its task. This is an expected behavior. | ||
==== | ||
. Check if the image has been pushed to the registry you specified in the `build.spec.output.image` field by running the following command from a node that can access the internal registry to pull the image: | ||
+ | ||
[source,terminal] | ||
---- | ||
$ podman pull | ||
---- | ||
+ | ||
[NOTE] | ||
==== | ||
An example output of the `podman pull` command might look like this: | ||
|
||
[source,terminal] | ||
---- | ||
$ image-registry.openshift-image-registry.svc:5000/buildpacks-example/taxi-app | ||
---- | ||
|
||
The project name in this example is `buildpacks-example`, and the image name is `taxi-app`. | ||
==== |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Procedure from here till line 58 is only needed if someone wants to use buildpacks with
shp
cli. For using buildpacks or any other ClusterBuildStrategy in Builds for Openshift via oc cli these steps are not required.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can put a NOTE for this and mention that these steps are optional and only needed with shp cli
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the doc. let me know if it's ok now.