kafka

Форк
0
/
generate_kafka_pr_template.py 
92 строки · 3.6 Кб
1
#!/usr/bin/env python
2

3
# Licensed to the Apache Software Foundation (ASF) under one or more
4
# contributor license agreements.  See the NOTICE file distributed with
5
# this work for additional information regarding copyright ownership.
6
# The ASF licenses this file to You under the Apache License, Version 2.0
7
# (the "License"); you may not use this file except in compliance with
8
# the License.  You may obtain a copy of the License at
9
#
10
#    http://www.apache.org/licenses/LICENSE-2.0
11
#
12
# Unless required by applicable law or agreed to in writing, software
13
# distributed under the License is distributed on an "AS IS" BASIS,
14
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
# See the License for the specific language governing permissions and
16
# limitations under the License.
17

18
"""
19
Python script to prepare the PR template for the docker official image
20
This script is used to prepare the PR template for the docker official image
21

22
Usage:
23
    Example command:-
24
        generate_kafka_pr_template.py --help
25
        Get detailed description of each option
26

27
        generate_kafka_pr_template.py --image-type <image_type>
28

29
        This command will build a PR template for <image_type> as image type (jvm by default) based docker official image,
30
        on the directories present under docker/docker_official_images.
31
        This PR template will be used to raise a PR in the Docker Official Images Repo.
32
"""
33

34
import os
35
import subprocess
36
import sys
37
import argparse
38
from pathlib import Path
39

40

41
# Returns the hash of the most recent commit that modified any of the specified files.
42
def file_commit(*files):
43
    return subprocess.check_output(["git", "log", "-1", "--format=format:%H", "HEAD", "--"] + list(files)).strip().decode('utf-8')
44

45

46
# Returns the latest commit hash for all files in a given directory.
47
def dir_commit(directory):
48
    docker_required_scripts = [str(path) for path in Path(directory).rglob('*') if path.is_file()]
49
    files_to_check = [os.path.join(directory, "Dockerfile")] + docker_required_scripts
50
    return file_commit(*files_to_check)
51

52

53
# Split the version string into parts and convert them to integers for version comparision
54
def get_version_parts(version):
55
    return tuple(int(part) for part in version.name.split('.'))
56

57

58
def main():
59
    parser = argparse.ArgumentParser()
60
    parser.add_argument("--image-type", "-type", choices=[
61
                        "jvm"], default="jvm", dest="image_type", help="Image type you want to build")
62
    args = parser.parse_args()
63
    self = os.path.basename(__file__)
64
    current_dir = os.path.dirname(os.path.abspath(__file__))
65
    docker_official_images_dir = Path(os.path.join(current_dir, "docker_official_images"))
66
    highest_version = ""
67

68
    header = f"""
69
# This file is generated via https://github.com/apache/kafka/blob/{file_commit(os.path.join(current_dir, self))}/docker/generate_kafka_pr_template.py
70
Maintainers: The Apache Kafka Project <dev@kafka.apache.org> (@ApacheKafka)
71
GitRepo: https://github.com/apache/kafka.git
72
"""
73
    print(header)
74
    versions = sorted((d for d in docker_official_images_dir.iterdir() if d.is_dir()), key=get_version_parts, reverse=True)
75
    highest_version = max(versions).name if versions else ""
76

77
    for dir in versions:
78
        version = dir.name
79
        tags = version + (", latest" if version == highest_version else "")
80
        commit = dir_commit(dir.joinpath(args.image_type))
81

82
        info = f"""
83
Tags: {tags}
84
Architectures: amd64,arm64v8
85
GitCommit: {commit}
86
Directory: ./docker/docker_official_images/{version}/{args.image_type}
87
"""
88
        print(info.strip(), '\n')
89

90

91
if __name__ == "__main__":
92
    main()
93

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.