Skip to content
Closed
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
67cea41
adding doi pr changes
KrishVora2912 Jul 22, 2024
11521ab
3.7.0 testing with doi pr changes
KrishVora2912 Jul 22, 2024
4f68262
adding 3.8.0 key
KrishVora2912 Jul 22, 2024
2c2b29a
testing on local
KrishVora2912 Jul 23, 2024
dfd1f19
bringing back commented lines in workflow
KrishVora2912 Jul 23, 2024
fee1e30
3.7.0 DOI Dockerfile revert to original state
KrishVora2912 Jul 23, 2024
1de2621
adding newline at end of 3.7.0 doi dockerfile
KrishVora2912 Jul 23, 2024
8da6e72
using annotations in place of labels
KrishVora2912 Jul 23, 2024
af07079
using apache keyserver as keyserver
KrishVora2912 Jul 24, 2024
947ce53
making ubuntu as default keyserver
KrishVora2912 Jul 24, 2024
372dacb
addressing PR comments -> version_keys to version_gpg_keys
KrishVora2912 Jul 25, 2024
d21dff3
reverting faulty import
KrishVora2912 Jul 25, 2024
ab4a0bf
adding servers as server list insted of keys.apache.org due to failures
KrishVora2912 Jul 25, 2024
a82c1fc
changing version_gpg_keys to json file as per PR comments
KrishVora2912 Jul 31, 2024
1f589a5
testing pushing
KrishVora2912 Jul 31, 2024
f027b78
3.7.0 doi testing, will be reverted
KrishVora2912 Jul 31, 2024
6d8615f
Revert "3.7.0 doi testing, will be reverted"
KrishVora2912 Jul 31, 2024
321fd4d
Revert "testing pushing"
KrishVora2912 Jul 31, 2024
a63adc4
using PR comments for verification of packages
KrishVora2912 Aug 13, 2024
d08cf6a
Fixing few issues, changing order of keyservers
KrishVora2912 Aug 13, 2024
89127e0
fixing gpg url error
KrishVora2912 Aug 13, 2024
3d3c915
reverting to test
KrishVora2912 Aug 13, 2024
5c6bfc4
Merge branch 'trunk' of https://github.com/apache/kafka into trunk
KrishVora2912 Aug 13, 2024
53c75cb
Checking docker compose
KrishVora2912 Aug 13, 2024
5b54175
Trying compose v2
KrishVora2912 Aug 13, 2024
92ec952
Using new gpg commands for native image too
KrishVora2912 Aug 13, 2024
2e5a354
Adding extra \n at the end
KrishVora2912 Aug 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions docker/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,44 @@
import tempfile
import os
from distutils.dir_util import copy_tree
import json
import shutil
import sys
import re

def load_version_gpg_keys():
'''
Loads the version-specific GPG keys from the 'version_gpg_keys.json' file.
'''
script_dir = os.path.dirname(os.path.abspath(__file__))
json_file = os.path.join(script_dir, 'version_gpg_keys.json')
with open(json_file, 'r') as f:
version_gpg_keys = json.load(f)
return version_gpg_keys

def get_gpg_key(kafka_version):
"""
Retrieves the GPG key for the specified kafka version, if it exists, from docker/version_gpg_keys.py.
"""
version_gpg_keys = load_version_gpg_keys()
gpg_key = version_gpg_keys.get(kafka_version)
if gpg_key is not None:
return gpg_key
else:
print(f"No GPG Key data exists for kafka version {kafka_version}.")
print("Please ensure an entry corresponding to it exists under docker/version_gpg_keys.py")
sys.exit(1)

def get_kafka_version_from_url(kafka_url):
"""
Retrives the major.minor.patch (x.x.x) version from the given Kafka URL.
"""
match = re.search("\d+\.\d+\.\d+", kafka_url)
if match:
return match.group(0)
else:
print(f"No pattern found matching x.x.x in {kafka_url}. No version number extracted")
sys.exit(1)

def execute(command):
if subprocess.run(command).returncode != 0:
Expand Down
7 changes: 5 additions & 2 deletions docker/docker_build_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@
from distutils.dir_util import copy_tree
import shutil
from test.docker_sanity_test import run_tests
from common import execute, build_docker_image_runner
from common import execute, build_docker_image_runner, get_gpg_key, get_kafka_version_from_url
import tempfile
import os
import re
import sys

def build_docker_image(image, tag, kafka_url, image_type):
image = f'{image}:{tag}'
build_docker_image_runner(f"docker build -f $DOCKER_FILE -t {image} --build-arg kafka_url={kafka_url} --build-arg build_date={date.today()} $DOCKER_DIR", image_type)
kafka_version = get_kafka_version_from_url(kafka_url)
build_docker_image_runner(f"docker build -f $DOCKER_FILE -t {image} --build-arg kafka_url={kafka_url} --build-arg build_date={date.today()} --build-arg GPG_KEY={get_gpg_key(kafka_version)} $DOCKER_DIR", image_type)

def run_docker_tests(image, tag, kafka_url, image_type):
temp_dir_path = tempfile.mkdtemp()
Expand Down
5 changes: 3 additions & 2 deletions docker/docker_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@
from datetime import date
import argparse

from common import execute, build_docker_image_runner
from common import execute, build_docker_image_runner, get_gpg_key, get_kafka_version_from_url

def build_push(image, kafka_url, image_type):
try:
create_builder()
build_docker_image_runner(f"docker buildx build -f $DOCKER_FILE --build-arg kafka_url={kafka_url} --build-arg build_date={date.today()} --push \
kafka_version = get_kafka_version_from_url(kafka_url)
build_docker_image_runner(f"docker buildx build -f $DOCKER_FILE --build-arg kafka_url={kafka_url} --build-arg build_date={date.today()} --build-arg GPG_KEY={get_gpg_key(kafka_version)} --push \
--platform linux/amd64,linux/arm64 --tag {image} $DOCKER_DIR", image_type)
except:
raise SystemError("Docker image push failed")
Expand Down
56 changes: 30 additions & 26 deletions docker/jvm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,58 +18,63 @@

FROM eclipse-temurin:21-jre-alpine AS build-jsa

USER root

# Get kafka from https://archive.apache.org/dist/kafka and pass the url through build arguments
ARG kafka_url
ARG GPG_KEY

COPY jsa_launch /etc/kafka/docker/jsa_launch

RUN set -eux ; \
apk update ; \
apk upgrade ; \
apk add --no-cache wget gcompat gpg gpg-agent procps bash; \
mkdir opt/kafka; \
wget -nv -O kafka.tgz "$kafka_url"; \
wget -nv -O kafka.tgz.asc "$kafka_url.asc"; \
tar xfz kafka.tgz -C /opt/kafka --strip-components 1; \
wget -nv -O KEYS https://downloads.apache.org/kafka/KEYS; \
gpg --import KEYS; \
for server in ha.pool.sks-keyservers.net $(shuf -e \
hkp://p80.pool.sks-keyservers.net:80 \
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we try using https://downloads.apache.org/kafka/KEYS for verification

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made this change

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change does not work for all versions, so reverting to the original server list approach.

Copy link
Copy Markdown

@rzo1 rzo1 Jul 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The guys from docker hub official won't like external download dependencies - we had that discussion for Storm a few months ago. We workaround that for Apache Storm here: https://github.com/apache/storm-docker/blob/master/automation/create-key-section.sh and here https://github.com/apache/storm-docker/blob/master/2.6.3-jre17/Dockerfile#L40 - might also an option for Kafka ;-)

Copy link
Copy Markdown
Author

@KrishVora2912 KrishVora2912 Jul 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @rzo1 ! Thanks for these suggestions!

A few small queries here:

The guys from docker hub official won't like external download dependencies

By this you mean that they wont approve of something along the lines of

wget -nv -O KEYS https://downloads.apache.org/kafka/KEYS; \
    gpg --import KEYS;

correct?
We did receive a comment from the Dockerhub folks regarding this (see Point 5 here).

So we went along and changed the above approach. Now we pass the GPG_KEY as an argument/environment variable, and then use something along the lines of this.

I went through the approach followed by Storm, and that seems like a great way to approach this too. However, for Kafka, there are a lot of existing keys that are returned (see attached image), which might just inflate the length of the Dockerfile (hence we decided with the arg/env approach).

In your experience, do you think the modified approach (here, here and here) would be liked by the Dockerhub folks, or with the discussion you had for Storm, do you anticipate any issue in this approach too?

Thanks a lot again!
Krish.
image

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they will just complain, if they don't like it :-) - for Storm, we had one iteration.

keyserver.ubuntu.com \
hkp://keyserver.ubuntu.com:80 \
pgp.mit.edu \
hkp://keys.openpgp.org) ; do \
gpg --batch --keyserver "$server" --recv-keys "$GPG_KEY" && break || : ; \
done && \
gpg --batch --verify kafka.tgz.asc kafka.tgz

# Generate jsa files using dynamic CDS for kafka server start command and kafka storage format command
RUN /etc/kafka/docker/jsa_launch
RUN mkdir opt/kafka; \
tar xfz kafka.tgz -C /opt/kafka --strip-components 1; \
# Generate jsa files using dynamic CDS for kafka server start command and kafka storage format command
/etc/kafka/docker/jsa_launch


FROM eclipse-temurin:21-jre-alpine

# exposed ports
EXPOSE 9092

USER root

# Get kafka from https://archive.apache.org/dist/kafka and pass the url through build arguments
ARG kafka_url
ARG build_date
ARG GPG_KEY


LABEL org.label-schema.name="kafka" \
org.label-schema.description="Apache Kafka" \
org.label-schema.build-date="${build_date}" \
org.label-schema.vcs-url="https://github.com/apache/kafka" \
LABEL org.opencontainers.image.title="kafka" \
org.opencontainers.image.description="Apache Kafka" \
org.opencontainers.image.created="${build_date}" \
org.opencontainers.image.source="https://github.com/apache/kafka" \
maintainer="Apache Kafka"

RUN set -eux ; \
apk update ; \
apk upgrade ; \
apk add --no-cache wget gcompat gpg gpg-agent procps bash; \
mkdir opt/kafka; \
wget -nv -O kafka.tgz "$kafka_url"; \
wget -nv -O kafka.tgz.asc "$kafka_url.asc"; \
tar xfz kafka.tgz -C /opt/kafka --strip-components 1; \
wget -nv -O KEYS https://downloads.apache.org/kafka/KEYS; \
gpg --import KEYS; \
for server in ha.pool.sks-keyservers.net $(shuf -e \
hkp://p80.pool.sks-keyservers.net:80 \
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we try using https://downloads.apache.org/kafka/KEYS for verification

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made this change

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change does not work for all versions, so reverting to the original server list approach.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we confirm that the list of key servers is going to cover all the GPG keys created in future? If not can we have a mechanism for the RM to add their GPG key server, if it's not present in the list.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, we will add this to the documentation as part of the release process.

keyserver.ubuntu.com \
hkp://keyserver.ubuntu.com:80 \
pgp.mit.edu \
hkp://keys.openpgp.org) ; do \
gpg --batch --keyserver "$server" --recv-keys "$GPG_KEY" && break || : ; \
done && \
gpg --batch --verify kafka.tgz.asc kafka.tgz; \
mkdir opt/kafka; \
tar xfz kafka.tgz -C /opt/kafka --strip-components 1; \
mkdir -p /var/lib/kafka/data /etc/kafka/secrets; \
mkdir -p /etc/kafka/docker /usr/logs /mnt/shared/config; \
adduser -h /home/appuser -D --shell /bin/bash appuser; \
Expand All @@ -79,9 +84,8 @@ RUN set -eux ; \
cp /opt/kafka/config/log4j.properties /etc/kafka/docker/log4j.properties; \
cp /opt/kafka/config/tools-log4j.properties /etc/kafka/docker/tools-log4j.properties; \
cp /opt/kafka/config/kraft/server.properties /etc/kafka/docker/server.properties; \
rm kafka.tgz kafka.tgz.asc KEYS; \
apk del wget gpg gpg-agent; \
apk cache clean;
rm kafka.tgz kafka.tgz.asc; \
apk del wget gpg gpg-agent;

COPY --from=build-jsa kafka.jsa /opt/kafka/kafka.jsa
COPY --from=build-jsa storage.jsa /opt/kafka/storage.jsa
Expand Down
24 changes: 15 additions & 9 deletions docker/native/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
FROM ghcr.io/graalvm/graalvm-community:21 AS build-native-image

ARG kafka_url
ARG GPG_KEY

WORKDIR /app

Expand All @@ -33,10 +34,16 @@ RUN mkdir $KAFKA_DIR; \
microdnf install wget; \
wget -nv -O kafka.tgz "$KAFKA_URL"; \
wget -nv -O kafka.tgz.asc "$KAFKA_URL.asc"; \
tar xfz kafka.tgz -C $KAFKA_DIR --strip-components 1; \
wget -nv -O KEYS https://downloads.apache.org/kafka/KEYS; \
gpg --import KEYS; \
for server in ha.pool.sks-keyservers.net $(shuf -e \
hkp://p80.pool.sks-keyservers.net:80 \
keyserver.ubuntu.com \
hkp://keyserver.ubuntu.com:80 \
pgp.mit.edu \
hkp://keys.openpgp.org) ; do \
gpg --batch --keyserver "$server" --recv-keys "$GPG_KEY" && break || : ; \
done && \
gpg --batch --verify kafka.tgz.asc kafka.tgz; \
tar xfz kafka.tgz -C $KAFKA_DIR --strip-components 1; \
rm kafka.tgz ; \
# Build the native-binary of the apache kafka using graalVM native-image.
/app/native_command.sh $NATIVE_IMAGE_PATH $NATIVE_CONFIGS_DIR $KAFKA_LIBS_DIR $TARGET_PATH
Expand All @@ -48,14 +55,13 @@ EXPOSE 9092

ARG build_date

LABEL org.label-schema.name="kafka" \
org.label-schema.description="Apache Kafka" \
org.label-schema.build-date="${build_date}" \
org.label-schema.vcs-url="https://github.com/apache/kafka" \
LABEL org.opencontainers.image.title="kafka" \
org.opencontainers.image.description="Apache Kafka" \
org.opencontainers.image.created="${build_date}" \
org.opencontainers.image.source="https://github.com/apache/kafka" \
maintainer="Apache Kafka"

RUN apk update ; \
apk add --no-cache gcompat ; \
RUN apk add --no-cache gcompat ; \
apk add --no-cache bash ; \
mkdir -p /etc/kafka/docker /mnt/shared/config /opt/kafka/config /etc/kafka/secrets ; \
adduser -h /home/appuser -D --shell /bin/bash appuser ; \
Expand Down
3 changes: 3 additions & 0 deletions docker/prepare_docker_official_image_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from datetime import date
import argparse
from distutils.dir_util import copy_tree
from common import get_gpg_key
import os
import shutil
import re
Expand All @@ -45,6 +46,8 @@ def remove_args_and_hardcode_values(file_path, kafka_version, kafka_url):
filedata = filedata.replace("ARG kafka_url", f"ENV kafka_url {kafka_url}")
filedata = filedata.replace(
"ARG build_date", f"ENV build_date {str(date.today())}")
filedata = filedata.replace(
"ARG GPG_KEY", f"ENV GPG_KEY {get_gpg_key(kafka_version)}")
original_comment = re.compile(r"# Get kafka from https://archive.apache.org/dist/kafka and pass the url through build arguments")
updated_comment = f"# Get Kafka from https://archive.apache.org/dist/kafka, url passed as env var, for version {kafka_version}"
filedata = original_comment.sub(updated_comment, filedata)
Expand Down
5 changes: 5 additions & 0 deletions docker/version_gpg_keys.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"3.7.0": "7C38C2F6E7DF40E527C7C996DE0D9D12FB1360DA",
"3.7.1": "4687E2BC1319B57B321D6F0E39AB5531A7FCB08E",
"3.8.0": "CF9500821E9557AEB04E026C05EEA67F87749E61"
}