|
23 | 23 | import subprocess |
24 | 24 | import shlex |
25 | 25 | import shutil |
| 26 | +import textwrap |
26 | 27 |
|
27 | 28 | VERBOSE = False |
28 | 29 |
|
|
32 | 33 | "al2": "public.ecr.aws/amazonlinux/amazonlinux:2" |
33 | 34 | } |
34 | 35 |
|
| 36 | +DISTRO_TO_PACKAGES = { |
| 37 | + "al2023": [ "libxcrypt-compat" ], |
| 38 | +} |
| 39 | + |
35 | 40 | DOCKER_PLATFORM_BY_ARCH = { |
36 | 41 | "x64": "linux/amd64", |
37 | 42 | "arm64": "linux/arm64" |
@@ -83,17 +88,60 @@ def oci_executable(): |
83 | 88 | exit(1) |
84 | 89 |
|
85 | 90 |
|
86 | | -def run_docker_test(opts): |
| 91 | +def create_docker_image(opts, oci_exe, base_image_name, packages): |
| 92 | + lines = [] |
| 93 | + |
| 94 | + # Set base image |
| 95 | + lines.append(f"FROM {base_image_name}") |
| 96 | + |
| 97 | + # Install extra packages if necessary |
| 98 | + if packages: |
| 99 | + cmd = [ |
| 100 | + "RUN yum -y install", |
| 101 | + *packages, |
| 102 | + ].join(" ") |
| 103 | + lines.append(cmd) |
| 104 | + |
| 105 | + # Compile the contents |
| 106 | + content = lines.join('\n') |
| 107 | + |
| 108 | + # Write the Dockerfile |
| 109 | + with open("Dockerfile", "w") as f: |
| 110 | + f.write(content) |
| 111 | + |
| 112 | + # Build the image |
| 113 | + image_name = f"container-test-{opts.distro}:latest" |
| 114 | + cmd = shlex.join([ |
| 115 | + oci_exe, |
| 116 | + "build", |
| 117 | + "-t", |
| 118 | + image_name, |
| 119 | + ]) |
| 120 | + shell(cmd) |
| 121 | + |
| 122 | + return image_name |
| 123 | + |
| 124 | + |
| 125 | +def get_docker_image(opts, oci_exe): |
| 126 | + base_image_name = DISTRO_TO_IMAGE_NAME[opts.distro] |
| 127 | + packages = DISTRO_TO_PACKAGES.get(opts.distro) |
| 128 | + if packages: |
| 129 | + return create_docker_image(opts, oci_exe, base_image_name, packages) |
| 130 | + else: |
| 131 | + return base_image_name |
| 132 | + |
| 133 | + |
| 134 | +def run_docker_test(opts): |
87 | 135 | """ |
88 | 136 | Run a docker test for a precompiled Kotlin/Native binary |
89 | 137 |
|
90 | 138 | :param opts: the parsed command line options |
91 | 139 | """ |
92 | 140 | platform = DOCKER_PLATFORM_BY_ARCH[opts.arch] |
93 | 141 | oci_exe = oci_executable() |
| 142 | + image_name = create_docker_image(opts, oci_exe) |
94 | 143 |
|
95 | 144 | test_bin_dir = os.path.abspath(opts.test_bin_dir) |
96 | | - image_name = DISTRO_TO_IMAGE_NAME[opts.distro] |
97 | 145 | path_to_exe = f'./linux{opts.arch.capitalize()}/debugTest/test.kexe' |
98 | 146 |
|
99 | 147 | cmd = [ |
|
0 commit comments