mirror of https://github.com/mongodb/mongo
SERVER-111813: Add multi-platform support for toolchain installation … (#42084)
GitOrigin-RevId: e950c1ed41b4c30884b5068692729a5b5b8ea3b7
This commit is contained in:
parent
33caaae466
commit
2a6634bb63
|
|
@ -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; \
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Reference in New Issue