Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 3 additions & 6 deletions docker/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
import subprocess
import tempfile
import os
from distutils.file_util import copy_file

from distutils.dir_util import copy_tree
import shutil

def execute(command):
Expand All @@ -36,9 +33,9 @@ def get_input(message):
def build_docker_image_runner(command, image_type):
temp_dir_path = tempfile.mkdtemp()
current_dir = os.path.dirname(os.path.realpath(__file__))
copy_tree(f"{current_dir}/{image_type}", f"{temp_dir_path}/{image_type}")
copy_tree(f"{current_dir}/resources", f"{temp_dir_path}/{image_type}/resources")
copy_file(f"{current_dir}/server.properties", f"{temp_dir_path}/{image_type}")
shutil.copytree(f"{current_dir}/{image_type}", f"{temp_dir_path}/{image_type}", dirs_exist_ok=True)
shutil.copytree(f"{current_dir}/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 = command.replace("$DOCKER_FILE", f"{temp_dir_path}/{image_type}/Dockerfile")
command = command.replace("$DOCKER_DIR", f"{temp_dir_path}/{image_type}")
try:
Expand Down
3 changes: 1 addition & 2 deletions docker/docker_build_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

from datetime import date
import argparse
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
Expand All @@ -49,7 +48,7 @@ def run_docker_tests(image, tag, kafka_url, image_type):
temp_dir_path = tempfile.mkdtemp()
try:
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(["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"])
Expand Down
9 changes: 4 additions & 5 deletions docker/docker_official_image_build_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"""

import argparse
from distutils.dir_util import copy_tree
import shutil
from common import execute
from docker_build_test import run_docker_tests
Expand All @@ -46,10 +45,10 @@ def build_docker_official_image(image, tag, kafka_version, image_type):
image = f'{image}:{tag}'
current_dir = os.path.dirname(os.path.realpath(__file__))
temp_dir_path = tempfile.mkdtemp()
copy_tree(f"{current_dir}/docker_official_images/{kafka_version}/{image_type}",
f"{temp_dir_path}/{image_type}")
copy_tree(f"{current_dir}/docker_official_images/{kafka_version}/jvm/resources",
f"{temp_dir_path}/{image_type}/resources")
shutil.copytree(f"{current_dir}/docker_official_images/{kafka_version}/{image_type}",
f"{temp_dir_path}/{image_type}", dirs_exist_ok=True)
shutil.copytree(f"{current_dir}/docker_official_images/{kafka_version}/jvm/resources",
f"{temp_dir_path}/{image_type}/resources", dirs_exist_ok=True)
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_DIR", f"{temp_dir_path}/{image_type}")
Expand Down
5 changes: 2 additions & 3 deletions docker/prepare_docker_official_image_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

from datetime import date
import argparse
from distutils.dir_util import copy_tree
import os
import shutil
import re
Expand Down Expand Up @@ -66,7 +65,7 @@ def remove_args_and_hardcode_values(file_path, kafka_version, kafka_url):
if os.path.exists(new_dir):
shutil.rmtree(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))
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, args.image_type), os.path.join(new_dir, args.kafka_version, args.image_type), dirs_exist_ok=True)
shutil.copytree(os.path.join(current_dir, 'resources'), os.path.join(new_dir, args.kafka_version, args.image_type, 'resources'), dirs_exist_ok=True)
remove_args_and_hardcode_values(
os.path.join(new_dir, args.kafka_version, args.image_type, 'Dockerfile'), args.kafka_version, kafka_url)
Loading