-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.mm2
More file actions
41 lines (33 loc) · 1.77 KB
/
Dockerfile.mm2
File metadata and controls
41 lines (33 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Enhanced MirrorMaker 2: apache/kafka:4.0.0 with a patched MirrorSourceTask.
#
# Rather than rebuilding all of Kafka (~30+ min), we recompile only the modified
# source file against the jars from the official image, then drop the new .class
# files into the existing connect-mirror jar. Same package, same classloader,
# so package-private references resolve at runtime.
ARG KAFKA_IMAGE=apache/kafka:4.0.0
FROM ${KAFKA_IMAGE} AS kafka-base
FROM eclipse-temurin:17-jdk AS builder
WORKDIR /work
# Pull the runtime libs so we can compile against them
COPY --from=kafka-base /opt/kafka/libs /kafka-libs
# Only the file we changed (mirrored from the apache/kafka fork at kafka-fork/connect/mirror/...)
COPY mm2-patch/org/apache/kafka/connect/mirror/MirrorSourceTask.java \
/work/src/org/apache/kafka/connect/mirror/MirrorSourceTask.java
RUN mkdir -p /work/classes && \
javac -source 17 -target 17 -d /work/classes -cp "/kafka-libs/*" \
/work/src/org/apache/kafka/connect/mirror/MirrorSourceTask.java
# Find the existing connect-mirror jar (not the -client variant) and overlay our class files
RUN SRC_JAR=$(ls /kafka-libs/connect-mirror-[0-9]*.jar | head -1) && \
echo "patching: $SRC_JAR" && \
cp "$SRC_JAR" /work/connect-mirror.jar && \
cd /work/classes && \
jar uf /work/connect-mirror.jar org/apache/kafka/connect/mirror/MirrorSourceTask.class && \
(ls org/apache/kafka/connect/mirror/MirrorSourceTask\$*.class 2>/dev/null | \
xargs -r jar uf /work/connect-mirror.jar || true)
FROM ${KAFKA_IMAGE}
USER root
COPY --from=builder /work/connect-mirror.jar /tmp/connect-mirror-patched.jar
RUN ORIG=$(ls /opt/kafka/libs/connect-mirror-[0-9]*.jar | head -1) && \
cp /tmp/connect-mirror-patched.jar "$ORIG" && \
rm /tmp/connect-mirror-patched.jar
USER appuser