Using OCI Connector to Build Images in Tekton Pipeline
Before reading, please refer to General Logic of Using OCI Connector Proxy in K8S Workload
TOC
Feature Overview
This article will teach you how to use the OCI Connector in the Tekton Pipeline to build images and push them to a Registry. With the capabilities of the OCI Connector, ordinary users do not need to handle authentication information, thus maximizing the security of credentials.
When using the OCI Connector in Tekton Pipeline, there are several key points to note:
- The address of the target image to be built is changed to the connector's proxy address.
- For example, build-harbor.alauda.cn/test/abc:v1 -> harbor.default.cluster.local/test/abc:v1
- Mount the configuration provided by the Connector.
- Configure
insecure registryfor the client tools.
This article will take the buildkit-daemonless task as an example to detail how to use the OCI Connector to complete the image build and push process without configuring authentication information on the client side.
Prerequisites
- The
buildkit-daemonlessTekton Task - A Dockerfile for image building
buildkit-daemonless task
We need to make some modifications based on the TektonHub buildkit-daemonless
- Add a
docker configworkspace to allow users to specifydocker/config.json. - Add a
buildkitd configworkspace to allow users to specifybuildkitd.toml.
The content is as follows. You can use the following command to install the Task into the cluster.
Dockerfile
To demonstrate the build and push process, we need to prepare a Dockerfile. To simplify the operation, we will save the content of the Dockerfile in a ConfigMap and then mount it to the Pod through the Tekton Task's workspace.
Operational Steps
Execute TaskRun
Pass the following parameters to TaskRun:
- Specify the
docker-configworkspace as thedocker-configconfiguration of the OCI connector, thereby mountingdocker/config.json. - Specify the
buildkitd-configworkspace as thebuildkitdconfiguration of the OCI connector, thereby mountingbuildkitd.toml. - Adjust the target image address for the push to the proxy address.
To obtain the Connector's proxy address, refer to: OCI Connectorclass Proxy Information Description
Operational Results
We can check whether the TaskRun executed successfully with the following command.
Conclusion
We have completed the entire process of "Using OCI Connector to Build and Push Images in Tekton Pipeline." We can see that we did not require the user to specify the authentication information for the image repository when executing the TaskRun, and the user also cannot access the authentication data configured by the Connector in the Pod executing the TaskRun. This greatly ensures that credentials are not leaked and safeguards the security of the tool's authentication information.