Merge pull request 'Add build_yunohost_binaries.py' (#30) from yunohost into main

Reviewed-on: #30
This commit is contained in:
notplants 2022-05-13 13:45:17 +00:00
commit 757efb07cc
1 changed files with 96 additions and 0 deletions

View File

@ -0,0 +1,96 @@
"""
script to cross-compile PeachCloud packages for arm64 and other architectures
"""
import subprocess
from peach_package_builder.constants import *
from peach_package_builder.build_go_sbot import GO_SBOT_VERSION, GO_SSB_DIR
# constants
PEACHCLOUD_VERSION = "1.0"
PROJECT_PATH = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
RUST_WORKSPACE_DIR = WORKSPACE_SRC_DIR
BINARIES_DIR = "/srv/files.commoninternet.net/binaries"
PEACH_WORKSPACE_GIT_URL = "https://git.coopcloud.tech/PeachCloud/peach-workspace"
GO_SBOT_GIT_URL = "https://github.com/cryptoscope/ssb.git"
OUTPUT_DIR = "/srv/files.commoninternet.net"
def pull_go_repo():
if not os.path.exists(GO_SSB_DIR):
subprocess.check_call(["git", "clone", GO_SBOT_GIT_URL, GO_SSB_DIR])
else:
subprocess.check_call(["git", "pull"], cwd=GO_SSB_DIR)
def crosscompile_go_sbot(architecture, binaries_dir):
subprocess.check_call(["git", "pull"], cwd=GO_SSB_DIR)
print("[CROSS-COMPILING sbotcli]")
subprocess.check_call(["env", "GOOS=linux", "GOARCH={}".format(architecture), "go", "build", "./cmd/sbotcli"], cwd=GO_SSB_DIR)
print("[CROSS-COMPILING go-sbot]")
subprocess.check_call(["env", "GOOS=linux", "GOARCH={}".format(architecture), "go", "build", "./cmd/go-sbot"], cwd=GO_SSB_DIR)
for binary in ["sbotcli", "go-sbot"]:
binary_path = os.path.join(GO_SSB_DIR, binary)
output_path = os.path.join(binaries_dir, binary)
print("[COPYING {} TO {}]".format(binary_path, output_path))
subprocess.check_call(["cp", binary_path, output_path])
def build_rust_binary(service_name, binaries_dir, target="aarch64-unknown-linux-gnu"):
"""
this function builds a specific binary
:param service_name: string name of the service
:param target: architecture to build for
:return:
"""
print("[ BUILIDING SERVICE {} ]".format(service_name))
service_path = os.path.join(RUST_WORKSPACE_DIR, service_name)
subprocess.check_output(
[
CARGO_PATH,
"build",
"--release",
"--target",
target],
cwd=service_path).decode("utf-8").strip()
binary_path = os.path.join(RUST_WORKSPACE_DIR, "target/{}/release/{}".format(target, service_name))
output_path = os.path.join(binaries_dir, service_name)
print("[ COPYING {} TO {} ]".format(binary_path, output_path))
subprocess.call(["cp", binary_path, output_path])
def publish(binaries_dir, architecture):
subprocess.check_call(["mkdir", "-p", OUTPUT_DIR])
binaries = ["peach-web", "peach-config", "go-sbot", "sbotcli"]
output_folder_name = "peachcloud_{}_Linux_{}".format(PEACHCLOUD_VERSION, architecture)
output_folder_path = os.path.join(OUTPUT_DIR, output_folder_name)
subprocess.check_call(["mkdir", "-p", output_folder_path])
for binary in binaries:
f_path = os.path.join(binaries_dir, binary)
output_path = os.path.join(output_folder_path, binary)
subprocess.check_call(["cp", f_path, output_path])
# copy static files for peach-web
peach_web_static_path = os.path.join(RUST_WORKSPACE_DIR, "peach-web/static")
output_static_path = os.path.join(binaries_dir, "static")
subprocess.check_call(["cp", "-r", peach_web_static_path, output_static_path])
# create a tar
tar_path = output_folder_path + ".tar.gz"
subprocess.check_call(["tar", "-czvf", tar_path, "-C", binaries_dir, "."], cwd=binaries_dir)
if __name__ == '__main__':
subprocess.check_call(["mkdir", "-p", OUTPUT_DIR])
subprocess.check_call(["mkdir", "-p", BINARIES_DIR])
pull_go_repo()
architectures = [
("aarch64-unknown-linux-gnu", "arm64", "aarch64"),
("x86_64-unknown-linux-gnu", "amd64", "amd64"),
]
for rust_architecture, go_architecture, yunohost_architecture in architectures:
print("BUILDING WITH ARCHITECTURE {}, {}, {}".format(rust_architecture, go_architecture, yunohost_architecture))
binaries_dir = os.path.join(BINARIES_DIR, yunohost_architecture)
subprocess.check_call(["mkdir", "-p", binaries_dir])
crosscompile_go_sbot(architecture=go_architecture, binaries_dir=binaries_dir)
build_rust_binary("peach-web", target=rust_architecture, binaries_dir=binaries_dir)
build_rust_binary("peach-config", target=rust_architecture, binaries_dir=binaries_dir)
publish(binaries_dir=binaries_dir, architecture=yunohost_architecture)