Questo contenuto non è disponibile nella lingua selezionata.
Chapter 4. Virtual builds with Red Hat Quay on OpenShift Container Platform
The procedures in this section explain how to create an environment for bare metal builds for Red Hat Quay on OpenShift Container Platform.
			Virtual builds can be run on virtualized machines with Red Hat Quay on OpenShift Container Platform. With this method, the build manager first creates the Job Object resource. Then, the Job Object creates a pod using the quay-builder-image. The quay-builder-image contains the quay-builder binary and the Podman service. The created pod runs as unprivileged. The quay-builder binary then builds the image while communicating status and retrieving build information from the build manager.
		
4.1. Virtual builds limitations
The following limitations apply to the virtual builds feature:
- Running virtual builds with Red Hat Quay on OpenShift Container Platform in an unprivileged context might cause some commands that were working under the previous build strategy to fail. Attempts to change the build strategy could potentially cause performance issues and reliability with the build.
- Running virtual builds directly in a container does not have the same isolation as using virtual machines. Changing the build environment might also cause builds that were previously working to fail.
4.2. Configuring virtual builds for Red Hat Quay on OpenShift Container Platform
The procedures in this section explain how to create an environment for virtual builds for Red Hat Quay on OpenShift Container Platform.
- If you are using Amazon Web Service (AWS) S3 storage, you must modify your storage bucket in the AWS console, prior to running builders. See "Modifying your AWS S3 storage bucket" in the following section for the required parameters.
- If you are using a Google Cloud Platform (GCP) object bucket, you must configure cross-origin resource sharing (CORS) to enable virtual builds.
Prerequisites
- You have an OpenShift Container Platform cluster provisioned with the Red Hat Quay Operator running.
- 
						You have set the tlscomponent tounmanagedand uploaded custom SSL/TLS certificates to the Red Hat Quay Operator. For more information, see SSL and TLS for Red Hat Quay.
- You have configured the OpenShift Container Platform TLS component for builds.
- You are logged into OpenShift Container Platform as a cluster administrator.
Procedure
- Create a new project where your virtual builders will be run, for example, - virtual-builders, by running the following command:- oc new-project virtual-builders - $ oc new-project virtual-builders- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Create a - ServiceAccountin the project that will be used to run builds by entering the following command:- oc create sa -n virtual-builders quay-builder - $ oc create sa -n virtual-builders quay-builder- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow - Example output - serviceaccount/quay-builder created - serviceaccount/quay-builder created- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Provide the created service account with editing permissions so that it can run a build: - oc adm policy -n virtual-builders add-role-to-user edit system:serviceaccount:virtual-builders:quay-builder - $ oc adm policy -n virtual-builders add-role-to-user edit system:serviceaccount:virtual-builders:quay-builder- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow - Example output - clusterrole.rbac.authorization.k8s.io/edit added: "system:serviceaccount:virtual-builders:quay-builder" - clusterrole.rbac.authorization.k8s.io/edit added: "system:serviceaccount:virtual-builders:quay-builder"- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Grant the builder worker - anyuid sccpermissions by entering the following command. This requires cluster administrator privileges, which is required because builders must run as the Podman user for unprivileged or rootless builds to work.- oc adm policy -n virtual-builders add-scc-to-user anyuid -z quay-builder - $ oc adm policy -n virtual-builders add-scc-to-user anyuid -z quay-builder- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow - Example output - clusterrole.rbac.authorization.k8s.io/system:openshift:scc:anyuid added: "quay-builder" - clusterrole.rbac.authorization.k8s.io/system:openshift:scc:anyuid added: "quay-builder"- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Obtain the token for the builder service account by entering the following command: - oc create token quay-builder -n virtual-builders - $ oc create token quay-builder -n virtual-builders- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow Note- When the token expires you will need to request a new token. Optionally, you can also add a custom expiration. For example, specify - --duration 20160mto retain the token for two weeks.- Example output - eyJhbGciOiJSUzI1NiIsImtpZCI6IldfQUJkaDVmb3ltTHZ0dGZMYjhIWnYxZTQzN2dJVEJxcDJscldSdEUtYWsifQ... - eyJhbGciOiJSUzI1NiIsImtpZCI6IldfQUJkaDVmb3ltTHZ0dGZMYjhIWnYxZTQzN2dJVEJxcDJscldSdEUtYWsifQ...- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Determine the builder route by entering the following command: - oc get route -n quay-enterprise - $ oc get route -n quay-enterprise- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow - Example output - Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Generate a self-signed SSL/TlS certificate with the - .crtextension by entering the following command:- oc extract cm/kube-root-ca.crt -n openshift-apiserver - $ oc extract cm/kube-root-ca.crt -n openshift-apiserver- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow - Example output - ca.crt - ca.crt- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Rename the - ca.crtfile to- build-cluster.crtby entering the following command:- mv ca.crt build-cluster.crt - $ mv ca.crt build-cluster.crt- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Update the - config.yamlfile of your Red Hat Quay on OpenShift Container Platform deployment to include an appropriate virtual builds configuration by using the OpenShift Container Platform web console.- 
								Click Operators Installed Operators Red Hat Quay Quay Registry. 
- Click the name of your registry, for example, example-registry.
- Under Config Bundle Secret, click the name of your configuration bundle, for example, extra-ca-certificate-config-bundle-secret.
- 
								Click Actions Edit Secret. 
- Add an appropriate virtual builds configuration using the following as a reference: - Copy to Clipboard Copied! - Toggle word wrap Toggle overflow - 1
- The build route is obtained by running$ oc get route -nwith the namespace of your Red Hat Quay on OpenShift Container Platform deployment. A port must be provided at the end of the route, and it should use the following format:[quayregistry-cr-name]-quay-builder-[ocp-namespace].[ocp-domain-name]:443.
- 2
- If theJOB_REGISTRATION_TIMEOUTparameter is set too low, you might receive the following error:failed to register job to build manager: rpc error: code = Unauthenticated desc = Invalid build token: Signature has expired. This parameter should be set to at least240.
- 3
- If your Redis host has a password or SSL/TLS certificates, you must update this field accordingly.
- 4
- Set to match the name of your virtual builds namespace. This example usedvirtual-builders.
- 5
- TheK8S_API_SERVERis obtained by running$ oc cluster-info.
- 6
- You must manually create and add your custom CA cert, for example,K8S_API_TLS_CA: /conf/stack/extra_ca_certs/build-cluster.crt.
- 7
- Defaults to5120Miif left unspecified.
- 8
- For virtual builds, you must ensure that there are enough resources in your cluster. Defaults to1000mif left unspecified.
- 9
- Defaults to3968Miif left unspecified.
- 10
- Defaults to500mif left unspecified.
- 11
- Obtained when running$ oc create sa.
 - Example virtual builds configuration - Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Click Save on the Edit Secret page.
 
- 
								Click Operators 
- Restart your Red Hat Quay on OpenShift Container Platform registry with the new configuration.
4.2.1. Modifying your AWS S3 storage bucket
If you are using AWS S3 storage, you must change your storage bucket in the AWS console prior to starting a build.
Procedure
- Log in to your AWS console at s3.console.aws.com.
- 
							In the search bar, search for S3and then click S3.
- 
							Click the name of your bucket, for example, myawsbucket.
- Click the Permissions tab.
- Under Cross-origin resource sharing (CORS), include the following parameters: - Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
4.2.2. Modifying your Google Cloud Platform object bucket
Currently, modifying your Google Cloud Platform object bucket is not supported on IBM Power and IBM Z.
Use the following procedure to configure cross-origin resource sharing (CORS) for virtual builders. Without CORS configuration, uploading a build Dockerfile fails.
Procedure
- Use the following reference to create a JSON file for your specific CORS needs. For example: - cat gcp_cors.json - $ cat gcp_cors.json- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow - Example output - Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Enter the following command to update your GCP storage bucket: - gcloud storage buckets update gs://<bucket_name> --cors-file=./gcp_cors.json - $ gcloud storage buckets update gs://<bucket_name> --cors-file=./gcp_cors.json- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow - Example output - Updating Completed 1 - Updating Completed 1- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- You can display the updated CORS configuration of your GCP bucket by running the following command: - gcloud storage buckets describe gs://<bucket_name> --format="default(cors)" - $ gcloud storage buckets describe gs://<bucket_name> --format="default(cors)"- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow - Example output - Copy to Clipboard Copied! - Toggle word wrap Toggle overflow