Build and serve signed Linux ARM64 agent releases
This commit is contained in:
@@ -19,9 +19,11 @@ from urllib.parse import urlencode, urlsplit
|
||||
import uuid
|
||||
|
||||
LINUX = 'x86_64-unknown-linux-gnu'
|
||||
LINUX_ARM64 = 'aarch64-unknown-linux-gnu'
|
||||
WINDOWS = 'x86_64-pc-windows-msvc'
|
||||
FILES = {LINUX: ('rmm-agent', 'rmm-privileged-helper', 'rmm-agent-updater'),
|
||||
WINDOWS: ('rmm-agent-windows.exe', 'rmm-helper-windows.exe', 'rmm-updater-windows.exe')}
|
||||
FILES[LINUX_ARM64] = FILES[LINUX]
|
||||
WINDOWS_GNU = 'x86_64-pc-windows-gnu'
|
||||
FILES[WINDOWS_GNU] = FILES[WINDOWS]
|
||||
LIMIT = 256 * 1024 * 1024
|
||||
@@ -55,9 +57,11 @@ def verify_native_image(path, target, size):
|
||||
with path.open('rb') as binary:
|
||||
header = binary.read(64)
|
||||
check(len(header) == 64, 'truncated binary header: ' + path.name)
|
||||
if target == LINUX:
|
||||
if target in (LINUX, LINUX_ARM64):
|
||||
machine = 62 if target == LINUX else 183
|
||||
check(header[:6] == b'\x7fELF\x02\x01' and header[16:18] in (b'\x02\x00', b'\x03\x00')
|
||||
and header[18:20] == b'\x3e\x00', 'Linux x86-64 ELF image required: ' + path.name)
|
||||
and int.from_bytes(header[18:20], 'little') == machine,
|
||||
f'{target} ELF image required: {path.name}')
|
||||
else:
|
||||
pe = int.from_bytes(header[60:64], 'little')
|
||||
check(header[:2] == b'MZ' and 64 <= pe <= size - 26, 'Windows PE image required: ' + path.name)
|
||||
@@ -130,7 +134,7 @@ def release_label(platform, official_windows):
|
||||
if official_windows:
|
||||
check(platform == WINDOWS_GNU, 'official Windows releases require a GNU x64 build receipt')
|
||||
return 'windows-gnu-official'
|
||||
return {LINUX: 'linux', WINDOWS: 'windows', WINDOWS_GNU: 'windows-gnu'}[platform]
|
||||
return {LINUX: 'linux', LINUX_ARM64: 'linux-arm64', WINDOWS: 'windows', WINDOWS_GNU: 'windows-gnu'}[platform]
|
||||
|
||||
|
||||
def prepare(args):
|
||||
|
||||
+18
-11
@@ -22,6 +22,12 @@ TARGETS = {
|
||||
"sha256:30ae3d90753bc39b0a98a897784c662aff9598ffab7a98a6298e8aa79145c2ec",
|
||||
[("rmm-server", "rmm-server"), ("rmm-time-broker-linux", "rmm-time-broker-linux")],
|
||||
),
|
||||
"linux-arm64": (
|
||||
"linux/arm64", "aarch64-unknown-linux-gnu",
|
||||
"sha256:30ae3d90753bc39b0a98a897784c662aff9598ffab7a98a6298e8aa79145c2ec",
|
||||
[("rmm-agent", "rmm-agent"), ("rmm-privileged-helper", "rmm-privileged-helper"),
|
||||
("rmm-updater-worker", "rmm-agent-updater")],
|
||||
),
|
||||
"linux-x64": (
|
||||
"linux/amd64", "x86_64-unknown-linux-gnu",
|
||||
"sha256:9a76ad3744ebfdddae96ca10001ce8291c1b332fb54c8df5eea0e8e999ac6fc6",
|
||||
@@ -34,6 +40,7 @@ TARGETS = {
|
||||
[("rmm-agent-windows", "rmm-agent-windows"), ("rmm-agent-windows", "rmm-helper-windows")],
|
||||
),
|
||||
}
|
||||
REMOTE_TARGETS = ("server-arm64", "linux-arm64")
|
||||
SOURCE_PATHS = ["Cargo.toml", "Cargo.lock", "rust-toolchain.toml", "crates", "proto",
|
||||
"migrations", "tools/apt-transaction", "deploy/linux", "tests"]
|
||||
|
||||
@@ -140,7 +147,7 @@ def build_archive(work, archive, revision, plan):
|
||||
print(f"Artifacts: {destination}\n{json.dumps(hashes, indent=2)}")
|
||||
|
||||
|
||||
def remote_build(archive, revision, jobs):
|
||||
def remote_build(archive, revision, jobs, target):
|
||||
from dev_stage import ssh_prefix
|
||||
|
||||
# The only SSH payload is this build driver and the selected Git sources.
|
||||
@@ -154,14 +161,14 @@ trap 'rm -rf -- "$stage"' EXIT
|
||||
cd "$stage"
|
||||
tar -xf - build.py source.tar.gz
|
||||
printf '%s build.py\\n%s source.tar.gz\\n' "$1" "$2" | sha256sum -c - >/dev/null
|
||||
python3 -I build.py _server_worker "$3" "$4"
|
||||
python3 -I build.py _server_worker "$3" "$4" "$5"
|
||||
"""
|
||||
with tempfile.TemporaryFile() as bundle:
|
||||
with tarfile.open(fileobj=bundle, mode="w") as package:
|
||||
package.add(worker, arcname="build.py")
|
||||
package.add(archive, arcname="source.tar.gz")
|
||||
bundle.seek(0)
|
||||
command = shlex.join(["sh", "-c", shell, "build", *checksums, revision, str(jobs)])
|
||||
command = shlex.join(["sh", "-c", shell, "build", *checksums, revision, str(jobs), target])
|
||||
result = subprocess.run([*ssh_prefix("server"), command], stdin=bundle)
|
||||
if result.returncode:
|
||||
raise SystemExit(f"ARM64 build via SSH failed (exit {result.returncode}).")
|
||||
@@ -176,13 +183,13 @@ def main():
|
||||
parser.add_argument("target", choices=TARGETS)
|
||||
parser.add_argument("--ref", default="HEAD", help="Git commit or ref (default: HEAD). Uncommitted edits are excluded.")
|
||||
parser.add_argument("--jobs", type=int, default=2, help="Maximum parallel Cargo jobs (default: 2).")
|
||||
parser.add_argument("--ssh", action="store_true", help="Build server-arm64 on the configured server, in ~/rmm-dev-build/.")
|
||||
parser.add_argument("--ssh", action="store_true", help="Build ARM64 binaries on the configured server, in ~/rmm-dev-build/.")
|
||||
parser.add_argument("--plan", action="store_true", help="Show the build plan without connecting, writing or building.")
|
||||
args = parser.parse_args()
|
||||
if args.jobs < 1:
|
||||
parser.error("--jobs must be positive")
|
||||
if args.ssh and args.target != "server-arm64":
|
||||
parser.error("--ssh applies to server-arm64")
|
||||
if args.ssh and args.target not in REMOTE_TARGETS:
|
||||
parser.error("--ssh applies to the ARM64 targets")
|
||||
revision = git("rev-parse", "--verify", "--end-of-options", args.ref + "^{commit}")
|
||||
windows_updater = args.target == "windows-gnu-x64" and git(
|
||||
"ls-tree", "--name-only", revision, "crates/agent-windows/src/bin/rmm-updater-windows.rs")
|
||||
@@ -196,7 +203,7 @@ def main():
|
||||
archive = Path(temporary) / "source.tar.gz"
|
||||
subprocess.run(["git", "archive", "-o", archive, revision, "--", *SOURCE_PATHS], cwd=ROOT, check=True)
|
||||
if args.ssh:
|
||||
remote_build(archive, revision, args.jobs)
|
||||
remote_build(archive, revision, args.jobs, args.target)
|
||||
else:
|
||||
build_archive(ROOT / "devstate" / "build" / args.target, archive, revision, plan)
|
||||
|
||||
@@ -204,12 +211,12 @@ def main():
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
if sys.argv[1:2] == ["_server_worker"]:
|
||||
revision, jobs_arg = sys.argv[2:]
|
||||
if (len(revision) not in (40, 64) or any(c not in "0123456789abcdef" for c in revision)
|
||||
revision, jobs_arg, target = sys.argv[2:]
|
||||
if (target not in REMOTE_TARGETS or len(revision) not in (40, 64) or any(c not in "0123456789abcdef" for c in revision)
|
||||
or not jobs_arg.isascii() or not jobs_arg.isdecimal() or int(jobs_arg) < 1):
|
||||
raise SystemExit("Invalid packed build request.")
|
||||
work = Path.home() / "rmm-dev-build" / "server-arm64"
|
||||
build_archive(work, Path("source.tar.gz").resolve(), revision, prepare("server-arm64", int(jobs_arg)))
|
||||
work = Path.home() / "rmm-dev-build" / target
|
||||
build_archive(work, Path("source.tar.gz").resolve(), revision, prepare(target, int(jobs_arg)))
|
||||
else:
|
||||
main()
|
||||
except (OSError, subprocess.CalledProcessError) as error:
|
||||
|
||||
@@ -17,7 +17,8 @@ from dev_stage import ssh_prefix
|
||||
|
||||
def publish(tenant, platform, release, official_windows=False, *, root=Path('/opt/rust-discovery/devstate/mvp-releases'),
|
||||
database_container='rust-discovery-server-postgres-1', service_uid=10001):
|
||||
labels = {'x86_64-pc-windows-gnu': 'windows-gnu', 'x86_64-unknown-linux-gnu': 'linux'}
|
||||
labels = {'x86_64-pc-windows-gnu': 'windows-gnu', 'x86_64-unknown-linux-gnu': 'linux',
|
||||
'aarch64-unknown-linux-gnu': 'linux-arm64'}
|
||||
label = labels[platform]
|
||||
if official_windows:
|
||||
if platform != 'x86_64-pc-windows-gnu':
|
||||
@@ -88,7 +89,7 @@ def publish(tenant, platform, release, official_windows=False, *, root=Path('/op
|
||||
def main():
|
||||
parser=argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--tenant',required=True,type=uuid.UUID)
|
||||
parser.add_argument('--platform',required=True,choices=['x86_64-unknown-linux-gnu','x86_64-pc-windows-gnu'])
|
||||
parser.add_argument('--platform',required=True,choices=['x86_64-unknown-linux-gnu','aarch64-unknown-linux-gnu','x86_64-pc-windows-gnu'])
|
||||
parser.add_argument('--official-windows',action='store_true')
|
||||
parser.add_argument('--release',required=True,type=uuid.UUID)
|
||||
args=parser.parse_args()
|
||||
|
||||
Reference in New Issue
Block a user