Skip to content

Commit 06535bd

Browse files
committed
create Docker image in CI if additional packages need to be installed
1 parent 268e22d commit 06535bd

File tree

1 file changed

+50
-2
lines changed

1 file changed

+50
-2
lines changed

.github/scripts/run-container-test.py

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import subprocess
2424
import shlex
2525
import shutil
26+
import textwrap
2627

2728
VERBOSE = False
2829

@@ -32,6 +33,10 @@
3233
"al2": "public.ecr.aws/amazonlinux/amazonlinux:2"
3334
}
3435

36+
DISTRO_TO_PACKAGES = {
37+
"al2023": [ "libxcrypt-compat" ],
38+
}
39+
3540
DOCKER_PLATFORM_BY_ARCH = {
3641
"x64": "linux/amd64",
3742
"arm64": "linux/arm64"
@@ -83,17 +88,60 @@ def oci_executable():
8388
exit(1)
8489

8590

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):
87135
"""
88136
Run a docker test for a precompiled Kotlin/Native binary
89137
90138
:param opts: the parsed command line options
91139
"""
92140
platform = DOCKER_PLATFORM_BY_ARCH[opts.arch]
93141
oci_exe = oci_executable()
142+
image_name = create_docker_image(opts, oci_exe)
94143

95144
test_bin_dir = os.path.abspath(opts.test_bin_dir)
96-
image_name = DISTRO_TO_IMAGE_NAME[opts.distro]
97145
path_to_exe = f'./linux{opts.arch.capitalize()}/debugTest/test.kexe'
98146

99147
cmd = [

0 commit comments

Comments
 (0)