Skip to content

Commit fa4251a

Browse files
authored
DEVX-1334 Reworks Docker build and push (#48)
1 parent c8584c9 commit fa4251a

File tree

6 files changed

+70
-91
lines changed

6 files changed

+70
-91
lines changed

Dockerfile-confluenthub

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
# limitations under the License.
1515

1616
ARG CP_VERSION
17+
ARG BASE_PREFIX=confluentinc
18+
ARG CONNECT_IMAGE=cp-kafka-connect
1719

18-
FROM confluentinc/cp-kafka-connect:$CP_VERSION
20+
FROM $BASE_PREFIX/$CONNECT_IMAGE:$CP_VERSION
1921

2022
ENV CONNECT_PLUGIN_PATH="/usr/share/java,/usr/share/confluent-hub-components"
2123

Dockerfile renamed to Dockerfile-local

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
# limitations under the License.
1515

1616
ARG CP_VERSION
17+
ARG BASE_PREFIX=confluentinc
18+
ARG CONNECT_IMAGE=cp-kafka-connect
1719

18-
FROM confluentinc/cp-kafka-connect:$CP_VERSION
20+
FROM $BASE_PREFIX/$CONNECT_IMAGE:$CP_VERSION
1921

2022
ENV CONNECT_PLUGIN_PATH="/usr/share/java,/usr/share/confluent-hub-components"
2123

Dockerfile-operator

Lines changed: 0 additions & 23 deletions
This file was deleted.

Dockerfile-operator-local

Lines changed: 0 additions & 25 deletions
This file was deleted.

Makefile

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,50 +8,76 @@ SHELL=/bin/bash -o pipefail
88

99
check-dependency = $(if $(shell command -v $(1)),,$(error Make sure $(1) is installed))
1010

11-
check-dependencies:
12-
@#(call check-dependency,mvn)
13-
@#(call check-dependency,docker)
14-
@#(call check-dependency,grep)
15-
@#(call check-dependency,cut)
16-
@#(call check-dependency,sed)
17-
1811
CP_VERSION ?= 5.3.1
1912
OPERATOR_VERSION ?= 0
2013

21-
KAFKA_CONNECT_DATAGEN_VERSION ?= 0.1.6
14+
KAFKA_CONNECT_DATAGEN_VERSION ?= 0.1.7
2215
AGGREGATE_VERSION = $(KAFKA_CONNECT_DATAGEN_VERSION)-$(CP_VERSION)
2316
OPERATOR_AGGREGATE_VERSION = $(AGGREGATE_VERSION).$(OPERATOR_VERSION)
2417

2518
KAFKA_CONNECT_DATAGEN_LOCAL_VERSION = $(shell make local-package-version)
2619
AGGREGATE_LOCAL_VERSION = $(KAFKA_CONNECT_DATAGEN_LOCAL_VERSION)-$(CP_VERSION)
2720

21+
BASE_PREFIX ?= confluentinc
22+
PUSH_PREFIX ?= cnfldemos
23+
2824
help:
2925
@$(foreach m,$(MAKEFILE_LIST),grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(m) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-$(HELP_TAB_WIDTH)s\033[0m %s\n", $$1, $$2}';)
3026

31-
local-package-version: check-dependencies ## Retrieves the jar version from the maven project definition
27+
local-package-version: ## Retrieves the jar version from the maven project definition
3228
@mvn help:evaluate -Dexpression=project.version -q -DforceStdout
3329

34-
package: check-dependencies ## Creates the assembly jar
30+
package: ## Creates the assembly jar
3531
@mvn clean package
3632

37-
build-docker-from-local: check-dependencies package ## Build the Docker image using the locally mvn built kafka-connect-datagen package
38-
@docker build -t kafka-connect-datagen:$(AGGREGATE_LOCAL_VERSION) --build-arg KAFKA_CONNECT_DATAGEN_VERSION=$(KAFKA_CONNECT_DATAGEN_LOCAL_VERSION) --build-arg CP_VERSION=$(CP_VERSION) -f Dockerfile .
33+
build-docker-from-local: package ## Build the Docker image using the locally mvn built kafka-connect-datagen package
34+
@docker build -t kafka-connect-datagen:$(AGGREGATE_LOCAL_VERSION) --build-arg BASE_PREFIX=$(BASE_PREFIX) --build-arg KAFKA_CONNECT_DATAGEN_VERSION=$(KAFKA_CONNECT_DATAGEN_LOCAL_VERSION) --build-arg CP_VERSION=$(CP_VERSION) -f Dockerfile-local .
35+
36+
build-docker-from-released: ## Build a Docker image using a released version of the kafka-connect-datagen connector
37+
@docker build -t kafka-connect-datagen:$(AGGREGATE_VERSION) --build-arg BASE_PREFIX=$(BASE_PREFIX) --build-arg KAFKA_CONNECT_DATAGEN_VERSION=$(KAFKA_CONNECT_DATAGEN_VERSION) --build-arg CP_VERSION=$(CP_VERSION) -f Dockerfile-confluenthub .
38+
39+
build-cp-server-connect-from-local: package ## Build the Docker image based on cp-server-connect from locally mvn built kafka-connect-datagen package
40+
@docker build -t cp-server-connect-datagen:$(AGGREGATE_LOCAL_VERSION) --build-arg BASE_PREFIX=$(BASE_PREFIX) --build-arg KAFKA_CONNECT_DATAGEN_VERSION=$(KAFKA_CONNECT_DATAGEN_LOCAL_VERSION) --build-arg CP_VERSION=$(CP_VERSION) --build-arg CONNECT_IMAGE=cp-server-connect -f Dockerfile-local .
41+
42+
build-cp-server-connect-from-released: ## Build a Docker image using a released version of the kafka-connect-datagen connector
43+
@docker build -t cp-server-connect-datagen:$(AGGREGATE_VERSION) --build-arg BASE_PREFIX=$(BASE_PREFIX) --build-arg KAFKA_CONNECT_DATAGEN_VERSION=$(KAFKA_CONNECT_DATAGEN_VERSION) --build-arg CP_VERSION=$(CP_VERSION) --build-arg CONNECT_IMAGE=cp-server-connect -f Dockerfile-confluenthub .
44+
45+
# In the case of Operator based images, there is an additional REV version appended to the end of the CP Version
46+
# which allows Operator images to rev independently
47+
48+
build-cp-server-connect-operator-from-local: package ## Build the Docker image based on cp-server-connect from locally mvn built kafka-connect-datagen package
49+
@docker build -t cp-server-connect-operator-datagen:$(AGGREGATE_LOCAL_VERSION) --build-arg BASE_PREFIX=$(BASE_PREFIX) --build-arg KAFKA_CONNECT_DATAGEN_VERSION=$(KAFKA_CONNECT_DATAGEN_LOCAL_VERSION) --build-arg CP_VERSION=$(CP_VERSION).$(OPERATOR_VERSION) --build-arg CONNECT_IMAGE=cp-server-connect-operator -f Dockerfile-local .
50+
51+
build-cp-server-connect-operator-from-released: ## Build a Docker image using a released version of the kafka-connect-datagen connector
52+
@docker build -t cp-server-connect-operator-datagen:$(AGGREGATE_VERSION) --build-arg BASE_PREFIX=$(BASE_PREFIX) --build-arg KAFKA_CONNECT_DATAGEN_VERSION=$(KAFKA_CONNECT_DATAGEN_VERSION) --build-arg CP_VERSION=$(CP_VERSION).$(OPERATOR_VERSION) --build-arg CONNECT_IMAGE=cp-server-connect-operator -f Dockerfile-confluenthub .
53+
54+
push-from-local:
55+
@make --no-print-directory build-docker-from-local
56+
@docker tag kafka-connect-datagen:$(AGGREGATE_LOCAL_VERSION) $(PUSH_PREFIX)/kafka-connect-datagen:$(AGGREGATE_LOCAL_VERSION)
57+
@docker push $(PUSH_PREFIX)/kafka-connect-datagen:$(AGGREGATE_LOCAL_VERSION)
58+
59+
push-from-released:
60+
@make --no-print-directory build-docker-from-released
61+
@docker tag kafka-connect-datagen:$(AGGREGATE_VERSION) $(PUSH_PREFIX)/kafka-connect-datagen:$(AGGREGATE_VERSION)
62+
@docker push $(PUSH_PREFIX)/kafka-connect-datagen:$(AGGREGATE_VERSION)
3963

40-
build-docker-from-released: check-dependencies ## Build a Docker image using a released version of the kafka-connect-datagen connector
41-
@docker build -t kafka-connect-datagen:$(AGGREGATE_VERSION) --build-arg KAFKA_CONNECT_DATAGEN_VERSION=$(KAFKA_CONNECT_DATAGEN_VERSION) --build-arg CP_VERSION=$(CP_VERSION) -f Dockerfile-confluenthub .
64+
push-cp-server-connect-from-local:
65+
@make --no-print-directory build-cp-server-connect-from-local
66+
@docker tag cp-server-connect-datagen:$(AGGREGATE_LOCAL_VERSION) $(PUSH_PREFIX)/cp-server-connect-datagen:$(AGGREGATE_LOCAL_VERSION)
67+
@docker push $(PUSH_PREFIX)/cp-server-connect-datagen:$(AGGREGATE_LOCAL_VERSION)
4268

43-
publish-cp-kafka-connect-confluenthub: check-dependencies ## Build the cp-kafka-connect image pulling datagen from Confluent Hub
44-
@docker build -t cnfldemos/kafka-connect-datagen:$(AGGREGATE_VERSION) --build-arg KAFKA_CONNECT_DATAGEN_VERSION=$(KAFKA_CONNECT_DATAGEN_VERSION) --build-arg CP_VERSION=$(CP_VERSION) -f Dockerfile-confluenthub .
45-
@docker push cnfldemos/kafka-connect-datagen:$(AGGREGATE_VERSION)
69+
push-cp-server-connect-from-released:
70+
@make --no-print-directory build-cp-server-connect-from-released
71+
@docker tag cp-server-connect-datagen:$(AGGREGATE_VERSION) $(PUSH_PREFIX)/cp-server-connect-datagen:$(AGGREGATE_VERSION)
72+
@docker push $(PUSH_PREFIX)/cp-server-connect-datagen:$(AGGREGATE_VERSION)
4673

47-
# The combination of CP_VERSION & OPERATOR_VERSION will determine two things:
48-
# 1. The version of the operator base image used in the Dockerfiles for operator (Dockerfile-operator-local & Dockerfile-operator)
49-
# 2. The version of the docker images _this_ repository builds and pushes to cnfldemos (cp-server-connect-operator-with-datagen)
74+
push-cp-server-connect-operator-from-local:
75+
@make --no-print-directory build-cp-server-connect-operator-from-local
76+
@docker tag cp-server-connect-operator-datagen:$(AGGREGATE_LOCAL_VERSION) $(PUSH_PREFIX)/cp-server-connect-operator-datagen:$(AGGREGATE_LOCAL_VERSION)
77+
@docker push $(PUSH_PREFIX)/cp-server-connect-operator-datagen:$(AGGREGATE_LOCAL_VERSION)
5078

51-
publish-cp-server-connect-operator-confluenthub: check-dependencies ## Build the cp-server-connect-operator image pulling datagen from Confluent Hub
52-
@docker build -t cnfldemos/cp-server-connect-operator-with-datagen:$(AGGREGATE_VERSION).0 --build-arg KAFKA_CONNECT_DATAGEN_VERSION=$(KAFKA_CONNECT_DATAGEN_VERSION) --build-arg CP_VERSION=$(CP_VERSION) --build-arg OPERATOR_VERSION=$(OPERATOR_VERSION) -f Dockerfile-operator .
53-
@docker push cnfldemos/cp-server-connect-operator-with-datagen:$(OPERATOR_AGGREGATE_VERSION)
79+
push-cp-server-connect-operator-from-released:
80+
@make --no-print-directory build-cp-server-connect-operator-from-released
81+
@docker tag cp-server-connect-operator-datagen:$(AGGREGATE_VERSION) $(PUSH_PREFIX)/cp-server-connect-operator-datagen:$(AGGREGATE_VERSION)
82+
@docker push $(PUSH_PREFIX)/cp-server-connect-operator-datagen:$(AGGREGATE_VERSION)
5483

55-
publish-cp-server-connect-operator-local: check-dependencies ## Build the cp-server-connect-operator image installing datagen from the local build
56-
@docker build -t cnfldemos/cp-server-connect-operator-with-datagen:$(AGGREGATE_VERSION).0 --build-arg KAFKA_CONNECT_DATAGEN_VERSION=$(KAFKA_CONNECT_DATAGEN_VERSION) --build-arg CP_VERSION=$(CP_VERSION) --build-arg OPERATOR_VERSION=$(OPERATOR_VERSION) -f Dockerfile-operator-local .
57-
@docker push cnfldemos/cp-server-connect-operator-with-datagen:$(OPERATOR_AGGREGATE_VERSION)

README.md

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,29 +50,30 @@ confluent local consume test1 --value-format avro --max-messages 5 --property pr
5050

5151
A Docker image based on Kafka Connect with the `kafka-connect-datagen` plugin is already available in [Dockerhub](https://hub.docker.com/r/cnfldemos/kafka-connect-datagen), and it is ready for you to use.
5252

53-
If you want to build a local copy of the Docker image with `kafka-connect-datagen`, this project provides a [Dockerfile](Dockerfile) that you can reference.
53+
If you want to build a local copy of the Docker image with `kafka-connect-datagen`, this project provides a [Dockerfile](Dockerfile-local) that you can reference.
5454

55-
You can create a Docker image packaged with the locally built source by running:
55+
You can create a Docker image packaged with the locally built source by running (for example with the 5.3.1 version of Confluent Platform):
5656
```bash
57-
make build-docker-from-local
57+
make build-docker-from-local CP_VERSION=5.3.1
5858
```
5959

60-
This will build the connector from source and create a local image with an aggregate version number. The aggregate version number is the kafka-connect-datagen connector version number and the Confluent Platform version number separated with a `-`. The local kafka-connect-datagen version number is defined in the `pom.xml` file, and the Confluent Platform version defined in the [Makefile](Makfile). An example of the aggregate version number might be: `0.1.6-5.3.1`.
60+
This will build the connector from source and create a local image with an aggregate version number. The aggregate version number is the kafka-connect-datagen connector version number and the Confluent Platform version number separated with a `-`. The local kafka-connect-datagen version number is defined in the `pom.xml` file, and the Confluent Platform version defined in the [Makefile](Makfile). An example of the aggregate version number might be: `0.1.7-5.3.1`.
6161

6262
Alternatively, you can install the `kafka-connect-datagen` connector from [Confluent Hub](https://www.confluent.io/connector/kafka-connect-datagen/) into a Docker image by running:
6363
```bash
64-
make build-docker-from-released
64+
make build-docker-from-released CP_VERSION=5.3.1
6565
```
6666

6767
The [Makefile](Makefile) contains some default variables that affect the version numbers of both the installed `kafka-connect-datagen` as well as the base Confluent Platform version. The variables are located near the top of the [Makefile](Makefile) with the following names and current default values:
6868

6969
```bash
7070
CP_VERSION ?= 5.3.1
71-
KAFKA_CONNECT_DATAGEN_VERSION ?= 0.1.6
71+
KAFKA_CONNECT_DATAGEN_VERSION ?= 0.1.7
7272
```
7373
These values can be overriden with variable declarations before the `make` command. For example:
74+
7475
```bash
75-
KAFKA_CONNECT_DATAGEN_VERSION=0.1.4 make build-docker-from-released
76+
make build-docker-from-released KAFKA_CONNECT_DATAGEN_VERSION=0.1.6
7677
```
7778

7879
### Run connector in Docker Compose
@@ -193,13 +194,13 @@ The [Makefile](Makefile) contains some default variables that affect the version
193194

194195
```bash
195196
CP_VERSION ?= 5.3.1
196-
KAFKA_CONNECT_DATAGEN_VERSION ?= 0.1.6
197+
KAFKA_CONNECT_DATAGEN_VERSION ?= 0.1.7
197198
OPERATOR_VERSION ?= 0 # Operator is a 'rev' version appended at the end of the CP version, like so: 5.3.1.0
198199
```
199200

200201
To publish the https://hub.docker.com/r/cnfldemos/kafka-connect-datagen/ image:
201202
```bash
202-
make publish-cp-kafka-connect-confluenthub
203+
make push-from-released
203204
```
204205

205206
and to override the CP Version of the `kafka-connect-datagen` version you can run something similar to:
@@ -209,11 +210,7 @@ CP_VERSION=5.3.0 KAFKA_CONNECT_DATAGEN_VERSION=0.1.4 make publish-cp-kafka-conne
209210

210211
to override the CP Version and the Operator version, which may happen if Operator releases a patch version, you could run something similar to:
211212
```bash
212-
CP_VERSION=5.3.0 OPERATOR_VERSION=1 KAFKA_CONNECT_DATAGEN_VERSION=0.1.4 make publish-cp-server-connect-operator-confluenthub
213+
CP_VERSION=5.3.0 OPERATOR_VERSION=1 KAFKA_CONNECT_DATAGEN_VERSION=0.1.4 make push-cp-server-connect-operator-from-released
213214
```
214-
which would result in a docker image tagged as: `cp-server-connect-operator-with-datagen:0.1.4-5.3.0.1`
215+
which would result in a docker image tagged as: `cp-server-connect-operator-datagen:0.1.4-5.3.0.1` and pushed to DockerHub
215216

216-
To publish the https://hub.docker.com/r/cnfldemos/cp-server-connect-operator-with-datagen image:
217-
```bash
218-
make publish-cp-server-connect-operator-confluenthub
219-
```

0 commit comments

Comments
 (0)