KAFKA-19490: Remove usages of distutils in docker scripts (#20178)

The
[distutils](https://docs.python.org/3.13/whatsnew/3.12.html#distutils)
package is removed from Python 3.12.

Change `distutils` usage to `shutil`.

Reviewers: Mickael Maison <mimaison@apache.org>

---------

Signed-off-by: PoAn Yang <payang@apache.org>
This commit is contained in:
PoAn Yang 2025-09-10 13:02:03 +08:00 committed by GitHub
parent 8015c87390
commit 675552a724
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 14 additions and 21 deletions

View File

@ -18,9 +18,6 @@
import subprocess import subprocess
import tempfile import tempfile
import os import os
from distutils.file_util import copy_file
from distutils.dir_util import copy_tree
import shutil import shutil
def execute(command): def execute(command):
@ -36,11 +33,11 @@ def get_input(message):
def build_docker_image_runner(command, image_type, kafka_archive=None): def build_docker_image_runner(command, image_type, kafka_archive=None):
temp_dir_path = tempfile.mkdtemp() temp_dir_path = tempfile.mkdtemp()
current_dir = os.path.dirname(os.path.realpath(__file__)) current_dir = os.path.dirname(os.path.realpath(__file__))
copy_tree(f"{current_dir}/{image_type}", f"{temp_dir_path}/{image_type}") shutil.copytree(f"{current_dir}/{image_type}", f"{temp_dir_path}/{image_type}", dirs_exist_ok=True)
copy_tree(f"{current_dir}/resources", f"{temp_dir_path}/{image_type}/resources") shutil.copytree(f"{current_dir}/resources", f"{temp_dir_path}/{image_type}/resources", dirs_exist_ok=True)
copy_file(f"{current_dir}/server.properties", f"{temp_dir_path}/{image_type}") shutil.copy(f"{current_dir}/server.properties", f"{temp_dir_path}/{image_type}")
if kafka_archive: if kafka_archive:
copy_file(kafka_archive, f"{temp_dir_path}/{image_type}/kafka.tgz") shutil.copy(kafka_archive, f"{temp_dir_path}/{image_type}/kafka.tgz")
command = command.replace("$DOCKER_FILE", f"{temp_dir_path}/{image_type}/Dockerfile") command = command.replace("$DOCKER_FILE", f"{temp_dir_path}/{image_type}/Dockerfile")
command = command.replace("$DOCKER_DIR", f"{temp_dir_path}/{image_type}") command = command.replace("$DOCKER_DIR", f"{temp_dir_path}/{image_type}")
try: try:

View File

@ -36,7 +36,6 @@ Usage:
from datetime import date from datetime import date
import argparse import argparse
from distutils.dir_util import copy_tree
import shutil import shutil
from test.docker_sanity_test import run_tests from test.docker_sanity_test import run_tests
from common import execute, build_docker_image_runner from common import execute, build_docker_image_runner
@ -47,7 +46,7 @@ def run_docker_tests(image, tag, kafka_url, image_type):
temp_dir_path = tempfile.mkdtemp() temp_dir_path = tempfile.mkdtemp()
try: try:
current_dir = os.path.dirname(os.path.realpath(__file__)) current_dir = os.path.dirname(os.path.realpath(__file__))
copy_tree(f"{current_dir}/test/fixtures", f"{temp_dir_path}/fixtures") shutil.copytree(f"{current_dir}/test/fixtures", f"{temp_dir_path}/fixtures", dirs_exist_ok=True)
execute(["wget", "-nv", "-O", f"{temp_dir_path}/kafka.tgz", kafka_url]) execute(["wget", "-nv", "-O", f"{temp_dir_path}/kafka.tgz", kafka_url])
execute(["mkdir", f"{temp_dir_path}/fixtures/kafka"]) execute(["mkdir", f"{temp_dir_path}/fixtures/kafka"])
execute(["tar", "xfz", f"{temp_dir_path}/kafka.tgz", "-C", f"{temp_dir_path}/fixtures/kafka", "--strip-components", "1"]) execute(["tar", "xfz", f"{temp_dir_path}/kafka.tgz", "-C", f"{temp_dir_path}/fixtures/kafka", "--strip-components", "1"])

View File

@ -34,7 +34,6 @@ Usage:
""" """
import argparse import argparse
from distutils.dir_util import copy_tree
import shutil import shutil
from common import execute from common import execute
from docker_build_test import run_docker_tests from docker_build_test import run_docker_tests
@ -46,10 +45,11 @@ def build_docker_official_image(image, tag, kafka_version, image_type):
image = f'{image}:{tag}' image = f'{image}:{tag}'
current_dir = os.path.dirname(os.path.realpath(__file__)) current_dir = os.path.dirname(os.path.realpath(__file__))
temp_dir_path = tempfile.mkdtemp() temp_dir_path = tempfile.mkdtemp()
copy_tree(f"{current_dir}/docker_official_images/{kafka_version}/{image_type}", shutil.copytree(f"{current_dir}/docker_official_images/{kafka_version}/{image_type}",
f"{temp_dir_path}/{image_type}") f"{temp_dir_path}/{image_type}", dirs_exist_ok=True)
copy_tree(f"{current_dir}/docker_official_images/{kafka_version}/jvm/resources", shutil.copytree(f"{current_dir}/docker_official_images/{kafka_version}/jvm/resources",
f"{temp_dir_path}/{image_type}/resources") f"{temp_dir_path}/{image_type}/resources", dirs_exist_ok=True)
shutil.copy(f"{current_dir}/server.properties", f"{temp_dir_path}/{image_type}")
command = f"docker build -f $DOCKER_FILE -t {image} $DOCKER_DIR" command = f"docker build -f $DOCKER_FILE -t {image} $DOCKER_DIR"
command = command.replace("$DOCKER_FILE", f"{temp_dir_path}/{image_type}/Dockerfile") command = command.replace("$DOCKER_FILE", f"{temp_dir_path}/{image_type}/Dockerfile")
command = command.replace("$DOCKER_DIR", f"{temp_dir_path}/{image_type}") command = command.replace("$DOCKER_DIR", f"{temp_dir_path}/{image_type}")

View File

@ -33,7 +33,6 @@ Usage:
from datetime import date from datetime import date
import argparse import argparse
from distutils.dir_util import copy_tree
import os import os
import shutil import shutil
import re import re
@ -61,12 +60,10 @@ if __name__ == '__main__':
args = parser.parse_args() args = parser.parse_args()
kafka_url = f"https://archive.apache.org/dist/kafka/{args.kafka_version}/kafka_2.13-{args.kafka_version}.tgz" kafka_url = f"https://archive.apache.org/dist/kafka/{args.kafka_version}/kafka_2.13-{args.kafka_version}.tgz"
current_dir = os.path.dirname(os.path.realpath(__file__)) current_dir = os.path.dirname(os.path.realpath(__file__))
new_dir = os.path.join( new_dir = os.path.join(current_dir, 'docker_official_images', args.kafka_version)
current_dir, f'docker_official_images', args.kafka_version)
if os.path.exists(new_dir): if os.path.exists(new_dir):
shutil.rmtree(new_dir) shutil.rmtree(new_dir)
os.makedirs(new_dir) os.makedirs(new_dir)
copy_tree(os.path.join(current_dir, args.image_type), os.path.join(new_dir, args.kafka_version, args.image_type)) shutil.copytree(os.path.join(current_dir, args.image_type), os.path.join(new_dir, args.image_type), dirs_exist_ok=True)
copy_tree(os.path.join(current_dir, 'resources'), os.path.join(new_dir, args.kafka_version, args.image_type, 'resources')) shutil.copytree(os.path.join(current_dir, 'resources'), os.path.join(new_dir, args.image_type, 'resources'), dirs_exist_ok=True)
remove_args_and_hardcode_values( remove_args_and_hardcode_values(os.path.join(new_dir, args.image_type, 'Dockerfile'), args.kafka_version, kafka_url)
os.path.join(new_dir, args.kafka_version, args.image_type, 'Dockerfile'), args.kafka_version, kafka_url)