Questo contenuto non è disponibile nella lingua selezionata.
Chapter 6. Automatically building Dockerfiles with Build workers
Red Hat Quay supports building Dockerfiles using a set of worker nodes on OpenShift Container Platform or Kubernetes. Build triggers, such as GitHub webhooks, can be configured to automatically build new versions of your repositories when new code is committed.
This document shows you how to enable Builds with your Red Hat Quay installation, and set up one more more OpenShift Container Platform or Kubernetes clusters to accept Builds from Red Hat Quay.
6.1. Setting up Red Hat Quay Builders with OpenShift Container Platform
You must pre-configure Red Hat Quay Builders prior to using it with OpenShift Container Platform.
6.1.1. Configuring the OpenShift Container Platform TLS component
					The tls component allows you to control TLS configuration.
				
Red Hat Quay does not support Builders when the TLS component is managed by the Red Hat Quay Operator.
					If you set tls to unmanaged, you supply your own ssl.cert and ssl.key files. In this instance, if you want your cluster to support Builders, you must add both the Quay route and the Builder route name to the SAN list in the certificate; alternatively you can use a wildcard.
				
To add the builder route, use the following format:
[quayregistry-cr-name]-quay-builder-[ocp-namespace].[ocp-domain-name]
[quayregistry-cr-name]-quay-builder-[ocp-namespace].[ocp-domain-name]6.1.2. Preparing OpenShift Container Platform for Red Hat Quay Builders
Prepare Red Hat Quay Builders for OpenShift Container Platform by using the following procedure.
Prerequisites
- You have configured the OpenShift Container Platform TLS component.
Procedure
- Enter the following command to create a project where Builds will be run, for example, - builder:- oc new-project builder - $ oc new-project builder- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Create a new - ServiceAccountin the the- buildernamespace by entering the following command:- oc create sa -n builder quay-builder - $ oc create sa -n builder quay-builder- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Enter the following command to grant a user the - editrole within the- buildernamespace:- oc policy add-role-to-user -n builder edit system:serviceaccount:builder:quay-builder - $ oc policy add-role-to-user -n builder edit system:serviceaccount:builder:quay-builder- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Enter the following command to retrieve a token associated with the - quay-builderservice account in the- buildernamespace. This token is used to authenticate and interact with the OpenShift Container Platform cluster’s API server.- oc sa get-token -n builder quay-builder - $ oc sa get-token -n builder quay-builder- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Identify the URL for the OpenShift Container Platform cluster’s API server. This can be found in the OpenShift Container Platform Web Console.
- Identify a worker node label to be used when schedule Build - jobs. Because Build pods need to run on bare metal worker nodes, typically these are identified with specific labels.- Check with your cluster administrator to determine exactly which node label should be used. 
- Optional. If the cluster is using a self-signed certificate, you must get the Kube API Server’s certificate authority (CA) to add to Red Hat Quay’s extra certificates. - Enter the following command to obtain the name of the secret containing the CA: - oc get sa openshift-apiserver-sa --namespace=openshift-apiserver -o json | jq '.secrets[] | select(.name | contains("openshift-apiserver-sa-token"))'.name- $ oc get sa openshift-apiserver-sa --namespace=openshift-apiserver -o json | jq '.secrets[] | select(.name | contains("openshift-apiserver-sa-token"))'.name- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- 
									Obtain the ca.crtkey value from the secret in the OpenShift Container Platform Web Console. The value begins with "-----BEGIN CERTIFICATE-----"`.
- 
									Import the CA to Red Hat Quay. Ensure that the name of this file matches K8S_API_TLS_CA.
 
- Create the following - SecurityContextConstraintsresource for the- ServiceAccount:- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
6.1.3. Configuring Red Hat Quay Builders
Use the following procedure to enable Red Hat Quay Builders.
Procedure
- Ensure that your Red Hat Quay - config.yamlfile has Builds enabled, for example:- FEATURE_BUILD_SUPPORT: True - FEATURE_BUILD_SUPPORT: True- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Add the following information to your Red Hat Quay - config.yamlfile, replacing each value with information that is relevant to your specific installation:- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow - For more information about each configuration field, see 
6.2. OpenShift Container Platform Routes limitations
				The following limitations apply when you are using the Red Hat Quay Operator on OpenShift Container Platform with a managed route component:
			
- Currently, OpenShift Container Platform Routes are only able to serve traffic to a single port. Additional steps are required to set up Red Hat Quay Builds.
- 
						Ensure that your kubectlorocCLI tool is configured to work with the cluster where the Red Hat Quay Operator is installed and that yourQuayRegistryexists; theQuayRegistrydoes not have to be on the same bare metal cluster where Builders run.
- Ensure that HTTP/2 ingress is enabled on the OpenShift cluster by following these steps.
- The Red Hat Quay Operator creates a - Routeresource that directs gRPC traffic to the Build manager server running inside of the existing- Quaypod, or pods. If you want to use a custom hostname, or a subdomain like- <builder-registry.example.com>, ensure that you create a CNAME record with your DNS provider that points to the- status.ingress[0].hostof the create- Routeresource. For example:- kubectl get -n <namespace> route <quayregistry-name>-quay-builder -o jsonpath={.status.ingress[0].host}- $ kubectl get -n <namespace> route <quayregistry-name>-quay-builder -o jsonpath={.status.ingress[0].host}- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Using the OpenShift Container Platform UI or CLI, update the - Secretreferenced by- spec.configBundleSecretof the- QuayRegistrywith the Build cluster CA certificate. Name the key- extra_ca_cert_build_cluster.cert. Update the- config.yamlfile entry with the correct values referenced in the Builder configuration that you created when you configured Red Hat Quay Builders, and add the- BUILDMAN_HOSTNAMECONFIGURATION FIELD:- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow - 1
- The externally accessible server hostname which the build jobs use to communicate back to the Build manager. Default is the same asSERVER_HOSTNAME. For OpenShiftRoute, it is eitherstatus.ingress[0].hostor the CNAME entry if using a custom hostname.BUILDMAN_HOSTNAMEmust include the port number, for example,somehost:443for an OpenShift Container Platform Route, as the gRPC client used to communicate with the build manager does not infer any port if omitted.
 
6.3. Troubleshooting Builds
The Builder instances started by the Build manager are ephemeral. This means that they will either get shut down by Red Hat Quay on timeouts or failure, or garbage collected by the control plane (EC2/K8s). In order to obtain the Build logs, you must do so while the Builds are running.
6.3.1. DEBUG config flag
					The DEBUG flag can be set to true in order to prevent the Builder instances from getting cleaned up after completion or failure. For example:
				
					When set to true, the debug feature prevents the Build nodes from shutting down after the quay-builder service is done or fails. It also prevents the Build manager from cleaning up the instances by terminating EC2 instances or deleting Kubernetes jobs. This allows debugging Builder node issues.
				
Debugging should not be set in a production cycle. The lifetime service still exists; for example, the instance still shuts down after approximately two hours. When this happens, EC2 instances are terminated, and Kubernetes jobs are completed.
					Enabling debug also affects the ALLOWED_WORKER_COUNT, because the unterminated instances and jobs still count toward the total number of running workers. As a result, the existing Builder workers must be manually deleted if ALLOWED_WORKER_COUNT is reached to be able to schedule new Builds.
				
					Setting DEBUG will also affect ALLOWED_WORKER_COUNT, as the unterminated instances/jobs will still count towards the total number of running workers. This means the existing builder workers will need to manually be deleted if ALLOWED_WORKER_COUNT is reached to be able to schedule new Builds.
				
6.3.2. Troubleshooting OpenShift Container Platform and Kubernetes Builds
Use the following procedure to troubleshooting OpenShift Container Platform Kubernetes Builds.
Procedure
- Create a port forwarding tunnel between your local machine and a pod running with either an OpenShift Container Platform cluster or a Kubernetes cluster by entering the following command: - oc port-forward <builder_pod> 9999:2222 - $ oc port-forward <builder_pod> 9999:2222- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Establish an SSH connection to the remote host using a specified SSH key and port, for example: - ssh -i /path/to/ssh/key/set/in/ssh_authorized_keys -p 9999 core@localhost - $ ssh -i /path/to/ssh/key/set/in/ssh_authorized_keys -p 9999 core@localhost- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Obtain the - quay-builderservice logs by entering the following commands:- systemctl status quay-builder - $ systemctl status quay-builder- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow - journalctl -f -u quay-builder - $ journalctl -f -u quay-builder- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
6.4. Setting up Github builds
If your organization plans to have Builds be conducted by pushes to Github, or Github Enterprise, continue with Creating an OAuth application in GitHub.