From 2a6634bb63424f529bdbb77dda271f1966104361 Mon Sep 17 00:00:00 2001 From: Eric Lavigne Date: Wed, 1 Oct 2025 18:20:10 -0600 Subject: [PATCH] =?UTF-8?q?SERVER-111813:=20Add=20multi-platform=20support?= =?UTF-8?q?=20for=20toolchain=20installation=20=E2=80=A6=20(#42084)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GitOrigin-RevId: e950c1ed41b4c30884b5068692729a5b5b8ea3b7 --- .devcontainer/Dockerfile | 15 ++++++++ .devcontainer/toolchain.py | 60 ++++++++++++++++++++++++------ .devcontainer/toolchain_config.env | 19 +++++++--- 3 files changed, 78 insertions(+), 16 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 45a4c1020ce..419b7ba8896 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -24,9 +24,24 @@ RUN SNIPPET="export PROMPT_COMMAND='history -a' && export HISTFILE=/commandhisto # Toolchain installation with SHA256 verification # Run "python3 toolchain.py generate" to update toolchain_config.env +ARG TARGETPLATFORM COPY .devcontainer/toolchain_config.env /tmp/toolchain_config.env RUN set -e; \ . /tmp/toolchain_config.env; \ + if [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ + TOOLCHAIN_URL="$TOOLCHAIN_ARM64_URL"; \ + TOOLCHAIN_SHA256="$TOOLCHAIN_ARM64_SHA256"; \ + ARCH="arm64"; \ + elif [ "$TARGETPLATFORM" = "linux/amd64" ]; then \ + TOOLCHAIN_URL="$TOOLCHAIN_AMD64_URL"; \ + TOOLCHAIN_SHA256="$TOOLCHAIN_AMD64_SHA256"; \ + ARCH="amd64"; \ + else \ + echo "Unsupported platform: $TARGETPLATFORM"; \ + exit 1; \ + fi; \ + echo "Target platform: $TARGETPLATFORM"; \ + echo "Architecture: $ARCH"; \ echo "Installing toolchain from: $TOOLCHAIN_URL"; \ echo "Expected SHA256: $TOOLCHAIN_SHA256"; \ curl -fSL "$TOOLCHAIN_URL" -o /tmp/toolchain.tar.gz; \ diff --git a/.devcontainer/toolchain.py b/.devcontainer/toolchain.py index edd4b0d1b15..cf5b48f19eb 100755 --- a/.devcontainer/toolchain.py +++ b/.devcontainer/toolchain.py @@ -51,10 +51,16 @@ def list_s3_objects(bucket: str, prefix: str) -> list[dict]: sys.exit(1) -def find_latest(bucket: str, prefix: str) -> tuple[str, str, datetime]: +def find_latest( + bucket: str, prefix: str, exclude_pattern: Optional[str] = None +) -> tuple[str, str, datetime]: """Find most recently modified artifact.""" objects = list_s3_objects(bucket, prefix) + # Filter out excluded patterns + if exclude_pattern: + objects = [obj for obj in objects if exclude_pattern not in obj["Key"]] + if not objects: print(f"No artifacts found with prefix: {prefix}", file=sys.stderr) sys.exit(1) @@ -88,9 +94,17 @@ def calculate_sha256(file_path: str) -> str: return sha256_hash.hexdigest() -def generate_config(bucket: str, prefix: str, output_file: str) -> None: - """Generate locked toolchain configuration with SHA256.""" - url, key, last_modified = find_latest(bucket, prefix) +def fetch_toolchain_info(bucket: str, prefix: str, arch: str) -> dict: + """Fetch toolchain info for a specific architecture.""" + print(f"\nšŸ” Fetching {arch} toolchain...", file=sys.stderr) + # amd64 toolchains don't have an architecture suffix, so we need to exclude arm64 + if arch == "amd64": + arch_prefix = prefix + exclude_pattern = "-arm64-" + else: + arch_prefix = f"{prefix}-{arch}" + exclude_pattern = None + url, key, last_modified = find_latest(bucket, arch_prefix, exclude_pattern) # Download to temp location to calculate checksum import tempfile @@ -105,21 +119,45 @@ def generate_config(bucket: str, prefix: str, output_file: str) -> None: finally: os.unlink(tmp_path) - # Write config file toolchain_id = os.path.basename(key).replace(".tar.gz", "") + return { + "url": url, + "sha256": sha256, + "key": key, + "last_modified": last_modified, + "toolchain_id": toolchain_id, + } + + +def generate_config(bucket: str, prefix: str, output_file: str) -> None: + """Generate locked toolchain configuration with SHA256 for both arm64 and amd64.""" + # Fetch both architectures + arm64_info = fetch_toolchain_info(bucket, prefix, "arm64") + amd64_info = fetch_toolchain_info(bucket, prefix, "amd64") + + # Write config file with both architectures with open(output_file, "w") as f: f.write("# Generated by toolchain.py\n") f.write("# DO NOT EDIT MANUALLY - run: python3 toolchain.py generate\n") f.write("#\n") f.write(f"# Generated: {datetime.now().isoformat()}\n") - f.write(f"# Last Modified: {last_modified.isoformat()}\n") - f.write(f"# Toolchain ID: {toolchain_id}\n") f.write("\n") - f.write(f'TOOLCHAIN_URL="{url}"\n') - f.write(f'TOOLCHAIN_SHA256="{sha256}"\n') - f.write(f'TOOLCHAIN_KEY="{key}"\n') - f.write(f'TOOLCHAIN_LAST_MODIFIED="{last_modified.isoformat()}"\n') + f.write("# ARM64 Toolchain\n") + f.write(f"# Last Modified: {arm64_info['last_modified'].isoformat()}\n") + f.write(f"# Toolchain ID: {arm64_info['toolchain_id']}\n") + f.write(f'TOOLCHAIN_ARM64_URL="{arm64_info["url"]}"\n') + f.write(f'TOOLCHAIN_ARM64_SHA256="{arm64_info["sha256"]}"\n') + f.write(f'TOOLCHAIN_ARM64_KEY="{arm64_info["key"]}"\n') + f.write(f'TOOLCHAIN_ARM64_LAST_MODIFIED="{arm64_info["last_modified"].isoformat()}"\n') + f.write("\n") + f.write("# AMD64 Toolchain\n") + f.write(f"# Last Modified: {amd64_info['last_modified'].isoformat()}\n") + f.write(f"# Toolchain ID: {amd64_info['toolchain_id']}\n") + f.write(f'TOOLCHAIN_AMD64_URL="{amd64_info["url"]}"\n') + f.write(f'TOOLCHAIN_AMD64_SHA256="{amd64_info["sha256"]}"\n') + f.write(f'TOOLCHAIN_AMD64_KEY="{amd64_info["key"]}"\n') + f.write(f'TOOLCHAIN_AMD64_LAST_MODIFIED="{amd64_info["last_modified"].isoformat()}"\n') print(f"\nāœ… Configuration written to: {output_file}", file=sys.stderr) print(f"\nContents:", file=sys.stderr) diff --git a/.devcontainer/toolchain_config.env b/.devcontainer/toolchain_config.env index 7d24829a1a8..0bdfe917d28 100644 --- a/.devcontainer/toolchain_config.env +++ b/.devcontainer/toolchain_config.env @@ -1,11 +1,20 @@ # Generated by toolchain.py # DO NOT EDIT MANUALLY - run: python3 toolchain.py generate # -# Generated: 2025-09-29T13:23:13.132683 +# Generated: 2025-10-01T12:25:08.235721 + +# ARM64 Toolchain # Last Modified: 2025-07-21T20:49:55+00:00 # Toolchain ID: mongodbtoolchain-ubuntu2404-arm64-c36013b8bab41fcd3cbfd5e4b4590cd0c10ea6ce +TOOLCHAIN_ARM64_URL="https://s3.amazonaws.com/boxes.10gen.com/build/toolchain/mongodbtoolchain-ubuntu2404-arm64-c36013b8bab41fcd3cbfd5e4b4590cd0c10ea6ce.tar.gz" +TOOLCHAIN_ARM64_SHA256="cdd2a58ed4a67dfa1be237d6042b7523552b543bb104c20db8f29068f3899fd6" +TOOLCHAIN_ARM64_KEY="build/toolchain/mongodbtoolchain-ubuntu2404-arm64-c36013b8bab41fcd3cbfd5e4b4590cd0c10ea6ce.tar.gz" +TOOLCHAIN_ARM64_LAST_MODIFIED="2025-07-21T20:49:55+00:00" -TOOLCHAIN_URL="https://s3.amazonaws.com/boxes.10gen.com/build/toolchain/mongodbtoolchain-ubuntu2404-arm64-c36013b8bab41fcd3cbfd5e4b4590cd0c10ea6ce.tar.gz" -TOOLCHAIN_SHA256="cdd2a58ed4a67dfa1be237d6042b7523552b543bb104c20db8f29068f3899fd6" -TOOLCHAIN_KEY="build/toolchain/mongodbtoolchain-ubuntu2404-arm64-c36013b8bab41fcd3cbfd5e4b4590cd0c10ea6ce.tar.gz" -TOOLCHAIN_LAST_MODIFIED="2025-07-21T20:49:55+00:00" +# AMD64 Toolchain +# Last Modified: 2025-07-21T19:57:00+00:00 +# Toolchain ID: mongodbtoolchain-ubuntu2404-c36013b8bab41fcd3cbfd5e4b4590cd0c10ea6ce +TOOLCHAIN_AMD64_URL="https://s3.amazonaws.com/boxes.10gen.com/build/toolchain/mongodbtoolchain-ubuntu2404-c36013b8bab41fcd3cbfd5e4b4590cd0c10ea6ce.tar.gz" +TOOLCHAIN_AMD64_SHA256="55b927124ffbf040b0caf19cb7b440679d71e57ae29c1c40df0891b884dcd2cd" +TOOLCHAIN_AMD64_KEY="build/toolchain/mongodbtoolchain-ubuntu2404-c36013b8bab41fcd3cbfd5e4b4590cd0c10ea6ce.tar.gz" +TOOLCHAIN_AMD64_LAST_MODIFIED="2025-07-21T19:57:00+00:00"