Chapter 4. Virtual builds with Red Hat Quay on OpenShift Container Platform
To build container images in virtualized environments with {product-title} on Red Hat Quay on OpenShift Container Platform, you can use virtual builds. Virtual builds run in unprivileged containers and provide isolation for your build processes.
With virtual builds, 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 Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
To configure virtual builds for Red Hat Quay on OpenShift Container Platform with {product-title}, you can create a build project, configure service accounts, and update your configuration file.
- 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-buildersCopy 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-builderCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
serviceaccount/quay-builder created
serviceaccount/quay-builder createdCopy 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-builderCopy 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-builderCopy 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-buildersCopy to Clipboard Copied! Toggle word wrap Toggle overflow NoteWhen 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-enterpriseCopy 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-apiserverCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
ca.crt
ca.crtCopy to Clipboard Copied! Toggle word wrap Toggle overflow Rename the
ca.crtfile tobuild-cluster.crtby entering the following command:mv ca.crt build-cluster.crt
$ mv ca.crt build-cluster.crtCopy 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 where:
BUILDMAN_HOSTNAME::Specifies the hostname of the Red Hat Quay registry. Obtain this by running the following command:$ oc get route quayregistry-quay-builder -n ${QUAY_PROJECT} -o jsonpath='{.spec.host}'.REDIS_HOST::Specifies the hostname for your Redis service.BUILDER_NAMESPACE::Specifies the name of your bare metal builds namespace. This example usedbare-metal-builder.K8S_API_SERVER::Specifies theK8S_API_SERVERis obtained by running$ oc cluster-info.K8S_API_TLS_CA::Specifies the name of your custom CA cert, for example,K8S_API_TLS_CA: /conf/stack/extra_ca_certs/build-cluster.crt.CONTAINER_MEMORY_LIMITS::Specifies the memory limit for your container. Defaults to5120Miif left unspecified.CONTAINER_CPU_LIMITS::Specifies the CPU limit for your container. Defaults to1000mif left unspecified.CONTAINER_MEMORY_REQUEST::Specifies the memory request for your container. Defaults to3968Miif left unspecified.CONTAINER_CPU_REQUEST::Specifies the CPU request for your container. Defaults to500mif left unspecified.SERVICE_ACCOUNT_TOKEN::Specifies the token for your service account. Obtain this by running$ oc create sa.SSH_AUTHORIZED_KEYS::Specifies the SSH authorized keys for your build environment. This key, or keys, should correspond to the private key that an admin or developer will use to SSH into the build worker for debugging purposes. This key can be obtained by establishing an SSH connection to the remote host using a specific SSH key and port. For example:$ ssh -i /path/to/ssh/key/set/in/ssh_authorized_keys -p 9999 core@localhost.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 Copy linkLink copied to clipboard!
To enable builds with AWS S3 storage in {product-title}, you can configure cross-origin resource sharing (CORS) settings in your S3 bucket. This allows build workers to access and store build artifacts in your S3 bucket.
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 Copy linkLink copied to clipboard!
To enable virtual builds with Google Cloud Platform storage in {product-title}, you can configure cross-origin resource sharing (CORS) settings in your GCP bucket. This allows build workers to upload Dockerfiles and access build artifacts.
Currently, modifying your Google Cloud Platform object bucket is not supported on IBM Power and IBM Z.
Procedure
Use the following reference to create a JSON file for your specific CORS needs. For example:
cat gcp_cors.json
$ cat gcp_cors.jsonCopy 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.jsonCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Updating Completed 1
Updating Completed 1Copy 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