// Module included in the following assemblies:
//
// assembly-deploy-kafka-connect-with-plugins.adoc

[id='creating-new-image-using-kafka-connect-build-{context}']
= Building a new container image with connector plugins automatically

[role="_abstract"]
Configure Kafka Connect so that Strimzi automatically builds a new container image with additional connectors.
You define the connector plugins using the `.spec.build.plugins` property of the `KafkaConnect` custom resource.
Strimzi will automatically download and add the connector plugins into a new container image.
The container is pushed into the container repository specified in `.spec.build.output` and automatically used in the Kafka Connect deployment.

.Prerequisites

* xref:deploying-cluster-operator-str[The Cluster Operator must be deployed.]
* A container registry.

You need to provide your own container registry where images can be pushed to, stored, and pulled from.
Strimzi supports private container registries as well as public registries such as link:https://quay.io/[Quay^] or link:https://hub.docker.com//[Docker Hub^].

.Procedure

. Configure the `KafkaConnect` custom resource by specifying the container registry in `.spec.build.output`, and additional connectors in `.spec.build.plugins`:
+
[source,yaml,subs=attributes+,options="nowrap"]
----
apiVersion: {KafkaConnectApiVersion}
kind: KafkaConnect
metadata:
  name: my-connect-cluster
spec: # <1>
  #...
  build:
    output: # <2>
      type: docker
      image: my-registry.io/my-org/my-connect-cluster:latest
      pushSecret: my-registry-credentials
    plugins: # <3>
      - name: debezium-postgres-connector
        artifacts:
          - type: tgz
            url: https://repo1.maven.org/maven2/io/debezium/debezium-connector-postgres/2.1.1.Final/debezium-connector-postgres-2.1.1.Final-plugin.tar.gz
            sha512sum: 962a12151bdf9a5a30627eebac739955a4fd95a08d373b86bdcea2b4d0c27dd6e1edd5cb548045e115e33a9e69b1b2a352bee24df035a0447cb820077af00c03
      - name: camel-telegram
        artifacts:
          - type: tgz
            url: https://repo.maven.apache.org/maven2/org/apache/camel/kafkaconnector/camel-telegram-kafka-connector/0.9.0/camel-telegram-kafka-connector-0.9.0-package.tar.gz
            sha512sum: a9b1ac63e3284bea7836d7d24d84208c49cdf5600070e6bd1535de654f6920b74ad950d51733e8020bf4187870699819f54ef5859c7846ee4081507f48873479
  #...
----
<1> link:{BookURLConfiguring}#type-KafkaConnectSpec-reference[The specification for the Kafka Connect cluster^].
<2> (Required) Configuration of the container registry where new images are pushed.
<3> (Required) List of connector plugins and their artifacts to add to the new container image. Each plugin must be configured with at least one `artifact`.

. Create or update the resource:
+
[source,subs="+quotes"]
----
$ kubectl apply -f <kafka_connect_configuration_file>
----

. Wait for the new container image to build, and for the Kafka Connect cluster to be deployed.

. Use the Kafka Connect REST API or `KafkaConnector` custom resources to use the connector plugins you added.

[role="_additional-resources"]
.Additional resources

* link:{BookURLConfiguring}#type-Build-reference[Kafka Connect `Build` schema reference^]
