aboutsummaryrefslogtreecommitdiffstats
path: root/build/scripts/make_container.py
diff options
context:
space:
mode:
authoralexv-smirnov <alex@ydb.tech>2023-03-15 19:59:12 +0300
committeralexv-smirnov <alex@ydb.tech>2023-03-15 19:59:12 +0300
commit056bb284ccf8dd6793ec3a54ffa36c4fb2b9ad11 (patch)
tree4740980126f32e3af7937ba0ca5f83e59baa4ab0 /build/scripts/make_container.py
parent269126dcced1cc8b53eb4398b4a33e5142f10290 (diff)
downloadydb-056bb284ccf8dd6793ec3a54ffa36c4fb2b9ad11.tar.gz
add library/cpp/actors, ymake build to ydb oss export
Diffstat (limited to 'build/scripts/make_container.py')
-rw-r--r--build/scripts/make_container.py94
1 files changed, 94 insertions, 0 deletions
diff --git a/build/scripts/make_container.py b/build/scripts/make_container.py
new file mode 100644
index 0000000000..a485baffdd
--- /dev/null
+++ b/build/scripts/make_container.py
@@ -0,0 +1,94 @@
+import os
+import shutil
+import stat
+import struct
+import subprocess
+import sys
+
+import container # 1
+
+
+def main(output_path, entry_path, input_paths, squashfs_path):
+ output_tmp_path = output_path + '.tmp'
+ shutil.copy2(entry_path, output_tmp_path)
+ st = os.stat(output_tmp_path)
+ os.chmod(output_tmp_path, st.st_mode | stat.S_IWUSR)
+
+ layer_paths = []
+ other_paths = []
+ for input_path in input_paths:
+ (layer_paths if input_path.endswith('.container_layer') else other_paths).append(input_path)
+
+ if len(other_paths) == 0:
+ raise Exception('No program in container dependencies')
+
+ if len(other_paths) > 1:
+ raise Exception('Multiple non-layer inputs')
+
+ program_path = other_paths[0]
+ program_container_path = os.path.basename(program_path)
+
+ os.symlink(program_container_path, 'entry')
+ add_cmd = [ os.path.join(squashfs_path, 'mksquashfs') ]
+ add_cmd.extend([program_path, 'entry', 'program_layer'])
+ subprocess.run(add_cmd)
+
+ layer_paths.append('program_layer')
+
+ container.join_layers(layer_paths, 'container_data', squashfs_path)
+
+ size = 0
+ block_size = 1024 * 1024
+
+ with open(output_tmp_path, 'ab') as output:
+ with open('container_data', 'rb') as input_:
+ while True:
+ data = input_.read(block_size)
+ output.write(data)
+ size += len(data)
+
+ if len(data) < block_size:
+ break
+
+ with open(os.path.join(squashfs_path, 'unsquashfs'), 'rb') as input_:
+ while True:
+ data = input_.read(block_size)
+ output.write(data)
+ size += len(data)
+
+ if len(data) == 0:
+ break
+
+
+ output.write(struct.pack('<Q', size))
+
+ os.rename(output_tmp_path, output_path)
+
+
+def entry():
+ import argparse
+
+ parser = argparse.ArgumentParser()
+ parser.add_argument('-o', '--output', required=True)
+ parser.add_argument('-s', '--squashfs-path', required=True)
+ parser.add_argument('input', nargs='*')
+
+ args = parser.parse_args()
+
+ def is_container_entry(path):
+ return os.path.basename(path) == '_container_entry'
+
+ input_paths = []
+ entry_paths = []
+
+ for input_path in args.input:
+ (entry_paths if is_container_entry(input_path) else input_paths).append(input_path)
+
+ if len(entry_paths) != 1:
+ raise Exception('Could not select container entry from {}'.format(entry_paths))
+
+ return main(args.output, entry_paths[0], input_paths, args.squashfs_path)
+
+
+if __name__ == '__main__':
+ sys.exit(entry())