Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env python3
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
 
import argparse
import os
import shlex
import shutil
import sys
from pathlib import Path
 
from logger import get_logger
 
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
REPO_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, "..", ".."))
sys.path.append(os.path.join(REPO_DIR, "tools", "python"))
from util import run  # noqa: E402
 
log = get_logger("get_docker_image")
 
 
def parse_args():
    parser = argparse.ArgumentParser(
        description="Build a docker image and push it to a remote Azure Container Registry."
        "The content in the remote registry can be used as a cache when we need to build the thing again."
        "The user must be logged in to the container registry."
    )
 
    parser.add_argument("--dockerfile", default="Dockerfile", help="Path to the Dockerfile.")
    parser.add_argument("--context", default=".", help="Path to the build context.")
    parser.add_argument(
        "--docker-build-args", default="", help="Arguments that will be passed to the 'docker build' command."
    )
 
    parser.add_argument(
        "--container-registry",
        help="The Azure container registry name. If not provided, no container registry will be used.",
    )
    parser.add_argument("--repository", required=True, help="The image repository name.")
 
    parser.add_argument("--use_imagecache", action="store_true", help="use cached image in pipeline cache")
 
    parser.add_argument("--docker-path", default="docker", help="Path to docker.")
 
    parser.add_argument("--manylinux-src", default="manylinux", help="Path to manylinux src folder")
 
    parser.add_argument(
        "--multiple_repos",
        action="store_true",
        help="used in packaging pipeline, which couldn't use get-docker-images-steps.yml",
    )
 
    return parser.parse_args()
 
 
def main():
    args = parse_args()
 
    log.debug(f"Dockerfile: {args.dockerfile}, context: {args.context}, docker build args: '{args.docker_build_args}'")
 
    use_container_registry = args.container_registry is not None
 
    if not use_container_registry:
        log.info("No container registry will be used")
 
    full_image_name = (
        f"{args.container_registry}.azurecr.io/{args.repository}:latest"
        if use_container_registry
        else f"{args.repository}:latest"
    )
 
    log.info(f"Image: {full_image_name}")
 
    dst_scripts_dir = Path(args.context) / "scripts"
    dst_deps_file = dst_scripts_dir / "deps.txt"
    # The docker file may provide a special deps.txt in its docker context dir and uses that one.
    # Otherwise, copy a generic one from this repo's cmake dir.
    if not dst_deps_file.exists():
        log.info(f"Copy deps.txt to : {dst_deps_file}")
        if not dst_scripts_dir.exists():
            dst_scripts_dir.mkdir(parents=True, exist_ok=True)
        shutil.copyfile(Path(REPO_DIR) / "cmake" / "deps.txt", str(dst_deps_file))
 
    if "manylinux" in args.dockerfile and args.multiple_repos:
        manylinux_build_scripts_folder = Path(args.manylinux_src) / "docker" / "build_scripts"
        dest = Path(args.context) / "build_scripts"
        if dest.exists():
            log.info(f"Deleting: {dest!s}")
            shutil.rmtree(str(dest))
        shutil.copytree(str(manylinux_build_scripts_folder), str(dest))
        src_entrypoint_file = str(Path(args.manylinux_src) / "docker" / "manylinux-entrypoint")
        dst_entrypoint_file = str(Path(args.context) / "manylinux-entrypoint")
        shutil.copyfile(src_entrypoint_file, dst_entrypoint_file)
        shutil.copymode(src_entrypoint_file, dst_entrypoint_file)
        run(
            "patch",
            "-p1",
            "-i",
            str((Path(SCRIPT_DIR) / "github" / "linux" / "docker" / "manylinux.patch").resolve()),
            cwd=str(dest),
        )
 
    if use_container_registry:
        run(
            args.docker_path,
            "--log-level",
            "error",
            "buildx",
            "build",
            "--load",
            "--tag",
            full_image_name,
            "--cache-from=type=registry,ref=" + full_image_name,
            "--build-arg",
            "BUILDKIT_INLINE_CACHE=1",
            *shlex.split(args.docker_build_args),
            "-f",
            args.dockerfile,
            args.context,
        )
        run(
            args.docker_path,
            "push",
            full_image_name,
        )
    else:
        log.info("Building image...")
        run(
            args.docker_path,
            "build",
            "--pull",
            *shlex.split(args.docker_build_args),
            "--tag",
            full_image_name,
            "--file",
            args.dockerfile,
            args.context,
        )
 
    # tag so we can refer to the image by repository name
    run(args.docker_path, "tag", full_image_name, args.repository)
 
    return 0
 
 
if __name__ == "__main__":
    sys.exit(main())