From d227d1d0ba652fe789e71066b31782344e3385f3 Mon Sep 17 00:00:00 2001 From: Jorge Esteban Quilcate Otoya Date: Tue, 15 Aug 2023 23:29:17 +0300 Subject: [PATCH] [aiven] feat: add docker support --- Dockerfile | 38 ++++++++++++++++++++++++++++++++++++++ Makefile | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 Dockerfile create mode 100644 Makefile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000..5bf5d969112a7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +## +# Copyright 2023 Aiven Oy +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +## +# Kafka 3.4.x +FROM confluentinc/cp-kafka:7.4.0 + +ARG _SCALA_VERSION +ARG _KAFKA_VERSION +ENV _KAFKA_FULL_VERSION "kafka_${_SCALA_VERSION}-${_KAFKA_VERSION}" + +USER root +COPY core/build/distributions/${_KAFKA_FULL_VERSION}.tgz / +RUN cd / \ + && tar -xf ${_KAFKA_FULL_VERSION}.tgz \ + && rm -r /usr/share/java/kafka/* \ + && cp /${_KAFKA_FULL_VERSION}/libs/* /usr/share/java/kafka/ \ + && ln -s /usr/share/java/kafka/${_KAFKA_FULL_VERSION}.jar /usr/share/java/kafka/kafka.jar \ + && rm -r /${_KAFKA_FULL_VERSION}.tgz /${_KAFKA_FULL_VERSION} + +# Add test jars with local implementations. +COPY clients/build/libs/kafka-clients-${_KAFKA_VERSION}-test.jar /usr/share/java/kafka/ +COPY storage/build/libs/kafka-storage-${_KAFKA_VERSION}-test.jar /usr/share/java/kafka/ +COPY storage/api/build/libs/kafka-storage-api-${_KAFKA_VERSION}-test.jar /usr/share/java/kafka/ + +# Restore the user. +USER appuser diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000000..04233523e94cc --- /dev/null +++ b/Makefile @@ -0,0 +1,48 @@ +## +# Copyright 2023 Aiven Oy +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +## +SCALA_VERSION := $(shell grep -o -E '^scalaVersion=[0-9]+\.[0-9]+\.[0-9]+' gradle.properties | cut -c14-) +SCALA_MAJOR_VERSION := $(shell grep -o -E '^scalaVersion=[0-9]+\.[0-9]+' gradle.properties | cut -c14-) +KAFKA_VERSION := $(shell grep -o -E '^version=[0-9]+\.[0-9]+\.[0-9]+(-SNAPSHOT)?' gradle.properties | cut -c9-) +IMAGE_NAME=aivenoy/kafka + +BRANCH := $(shell git rev-parse --abbrev-ref HEAD) +IMAGE_TAG := $(subst /,_,$(BRANCH)) + +.PHONY: all build clean + +all: clean build + +clean: + ./gradlew clean + +build: core/build/distributions/kafka_$(SCALA_VERSION)-$(KAFKA_VERSION).tgz + +core/build/distributions/kafka_$(SCALA_VERSION)-$(KAFKA_VERSION).tgz: + echo "Version: $(KAFKA_VERSION)-$(SCALA_VERSION)" + ./gradlew -PscalaVersion=$(SCALA_VERSION) testJar releaseTarGz + +.PHONY: docker_image +docker_image: build + docker build . \ + --build-arg _SCALA_VERSION=$(SCALA_MAJOR_VERSION) \ + --build-arg _KAFKA_VERSION=$(KAFKA_VERSION) \ + -t $(IMAGE_NAME):$(IMAGE_TAG) + +.PHONY: docker_push +docker_push: + docker push $(IMAGE_NAME):$(IMAGE_TAG) + +# TODO publish docker images