mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Add some build tooling
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#!/bin/env python3
|
||||
|
||||
# it is assumed this is run from ./utils/
|
||||
|
||||
import sys
|
||||
import json
|
||||
import argparse
|
||||
|
||||
92
utils/package_release.py
Executable file
92
utils/package_release.py
Executable file
@@ -0,0 +1,92 @@
|
||||
#!/bin/env python3
|
||||
|
||||
# it is assumed this is run from the root of the project
|
||||
|
||||
import argparse
|
||||
import zipfile
|
||||
import os
|
||||
|
||||
def generate_ip_script(binary_name: str) -> str:
|
||||
return f"""#!/bin/bash
|
||||
export RUST_LOG=info
|
||||
|
||||
./{binary_name} --ip "0.0.0.0"
|
||||
"""
|
||||
|
||||
def generate_plain_script(binary_name: str) -> str:
|
||||
return f"""#!/bin/bash
|
||||
export RUST_LOG=info
|
||||
|
||||
./{binary_name}
|
||||
"""
|
||||
|
||||
BINARIES_TO_INCLUDE = {
|
||||
"oj_auth": generate_plain_script,
|
||||
"oj_cdn": generate_ip_script,
|
||||
"oj_rc_chat": generate_ip_script, "oj_rc_chat_room": generate_ip_script,
|
||||
"oj_rc_microtransactions": generate_plain_script,
|
||||
"oj_rc_services": generate_ip_script, "oj_rc_services_room": generate_ip_script,
|
||||
"oj_rc_singleplayer": generate_ip_script, "oj_rc_singleplayer_room": generate_ip_script,
|
||||
"oj_rc_social": generate_ip_script, "oj_rc_social_room": generate_ip_script,
|
||||
}
|
||||
|
||||
PROJECT_FOLDERS_TO_INCLUDE = [
|
||||
"assets",
|
||||
]
|
||||
|
||||
# extra assets; not ones in one of the listed folders
|
||||
PROJECT_ASSETS_TO_INCLUDE = [
|
||||
"auth/Rocket.toml",
|
||||
"rc_microtransactions/Rocket.toml"
|
||||
]
|
||||
|
||||
BLANK_FOLDERS_TO_CREATE = [
|
||||
"data/robocraft",
|
||||
"data/robocraft/brawldata",
|
||||
"data/robocraft/campaigndata",
|
||||
"data/robocraft/clanavatar",
|
||||
"data/robocraft/customavatars",
|
||||
]
|
||||
|
||||
def add_folder_to_zip(archive: zipfile.ZipFile, root_dir: str):
|
||||
archive.mkdir(root_dir)
|
||||
for (root, dirs, files) in os.walk(root_dir):
|
||||
for f in files:
|
||||
archive.write(os.path.join(root, f))
|
||||
for d in dirs:
|
||||
archive.mkdir(os.path.join(root, d))
|
||||
|
||||
def main(build_root: str, outfile: str):
|
||||
print("Packaging binaries in", build_root)
|
||||
archive = zipfile.ZipFile(outfile, mode="w", compression=zipfile.ZIP_DEFLATED, compresslevel=9)
|
||||
# handle release binaries
|
||||
print("Adding", len(BINARIES_TO_INCLUDE), "binaries")
|
||||
for binary_file in BINARIES_TO_INCLUDE.keys():
|
||||
fp = os.path.join(build_root, binary_file)
|
||||
folder_name = binary_file.replace("oj_", "")
|
||||
archive.write(fp, arcname=os.path.join(folder_name, binary_file))
|
||||
script_generator = BINARIES_TO_INCLUDE[binary_file]
|
||||
if script_generator is not None:
|
||||
script = BINARIES_TO_INCLUDE[binary_file](binary_file)
|
||||
info = zipfile.ZipInfo(os.path.join(folder_name, "run.sh"))
|
||||
info.external_attr = 0o0755 << 16 # unix file permissions
|
||||
archive.writestr(info, script)
|
||||
# handle release assets
|
||||
print("Adding", len(PROJECT_FOLDERS_TO_INCLUDE), "project folders")
|
||||
for folder in PROJECT_FOLDERS_TO_INCLUDE:
|
||||
add_folder_to_zip(archive, folder)
|
||||
for asset in PROJECT_ASSETS_TO_INCLUDE:
|
||||
archive.write(asset)
|
||||
# handle project setup niceties
|
||||
print("Creating", len(BLANK_FOLDERS_TO_CREATE), "folders")
|
||||
for folder in BLANK_FOLDERS_TO_CREATE:
|
||||
archive.mkdir(folder)
|
||||
archive.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("build_dir")
|
||||
parser.add_argument("--output", default="package.zip")
|
||||
args = parser.parse_args()
|
||||
main(args.build_dir, args.output)
|
||||
Reference in New Issue
Block a user