diff --git a/docker/Dockerfile.foundationdb_large b/docker/Dockerfile.foundationdb_large index d5b1b59a0..8a79498f7 100644 --- a/docker/Dockerfile.foundationdb_large +++ b/docker/Dockerfile.foundationdb_large @@ -53,18 +53,17 @@ ENV CGO_LDFLAGS="-lfdb_c" # build SeaweedFS sources; prefer local context but fall back to git clone if context only has docker files ARG SOURCE_REF=master WORKDIR /go/src/github.com/seaweedfs/seaweedfs -COPY . /tmp/local-context +COPY . . RUN set -euo pipefail && \ - if [ -d /tmp/local-context/weed ]; then \ - cp -a /tmp/local-context/. .; \ - else \ + if [ ! -d weed ]; then \ echo "Local build context does not include SeaweedFS sources; cloning ${SOURCE_REF}" >&2; \ - git clone --depth 1 --branch ${SOURCE_REF} https://github.com/seaweedfs/seaweedfs /tmp/upstream && \ - cp -a /tmp/upstream/. . && \ - cp -a /tmp/local-context/. ./docker/ && \ - rm -rf /tmp/upstream; \ + mkdir -p /tmp/local-context && cp -a /go/src/github.com/seaweedfs/seaweedfs/. /tmp/local-context && \ + cd / && rm -rf /go/src/github.com/seaweedfs/seaweedfs && \ + git clone --depth 1 --branch ${SOURCE_REF} https://github.com/seaweedfs/seaweedfs /go/src/github.com/seaweedfs/seaweedfs && \ + cp -a /tmp/local-context/. /go/src/github.com/seaweedfs/seaweedfs/docker/ && \ + rm -rf /tmp/local-context && \ + cd /go/src/github.com/seaweedfs/seaweedfs; \ fi && \ - rm -rf /tmp/local-context && \ cd weed \ && COMMIT_SHA=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown") \ && export LDFLAGS="-X github.com/seaweedfs/seaweedfs/weed/util/version.COMMIT=${COMMIT_SHA}" \ @@ -82,37 +81,11 @@ RUN apt-get update && \ wget && \ rm -rf /var/lib/apt/lists/* -# Install FoundationDB client library in runtime image with SHA256 checksum verification -ARG FDB_VERSION=7.4.5 -ARG TARGETARCH -RUN cd /tmp && \ - case "${TARGETARCH}" in \ - "amd64") FDB_ARCH="amd64"; PACKAGE_ARCH="amd64" ;; \ - "arm64") FDB_ARCH="arm64"; PACKAGE_ARCH="aarch64" ;; \ - *) echo "Unsupported architecture: ${TARGETARCH}" >&2; exit 1 ;; \ - esac && \ - case "${FDB_VERSION}_${FDB_ARCH}" in \ - "7.4.5_amd64") \ - EXPECTED_SHA256="eea6b98cf386a0848655b2e196d18633662a7440a7ee061c10e32153c7e7e112" ;; \ - "7.4.5_arm64") \ - EXPECTED_SHA256="f2176b86b7e1b561c3632b4e6e7efb82e3b8f57c2ff0d0ac4671e742867508aa" ;; \ - "7.3.43_amd64") \ - EXPECTED_SHA256="c3fa0a59c7355b914a1455dac909238d5ea3b6c6bc7b530af8597e6487c1651a" ;; \ - "7.3.43_arm64") \ - echo "ERROR: FoundationDB ${FDB_VERSION} does not publish arm64 client packages." >&2; \ - echo "Please upgrade to 7.4.5+ when targeting arm64." >&2; \ - exit 1 ;; \ - *) \ - echo "ERROR: No checksum available for FDB version ${FDB_VERSION} on ${FDB_ARCH}" >&2; \ - echo "Run docker/get_fdb_checksum.sh ${FDB_VERSION} ${FDB_ARCH} to get the checksum" >&2; \ - exit 1 ;; \ - esac && \ - PACKAGE="foundationdb-clients_${FDB_VERSION}-1_${PACKAGE_ARCH}.deb" && \ - wget --timeout=30 --tries=3 https://github.com/apple/foundationdb/releases/download/${FDB_VERSION}/${PACKAGE} && \ - echo "${EXPECTED_SHA256} ${PACKAGE}" | sha256sum -c - || \ - (echo "ERROR: Checksum verification failed for FoundationDB ${FDB_VERSION} (${FDB_ARCH})" >&2; exit 1) && \ - dpkg -i ${PACKAGE} && \ - rm ${PACKAGE} +# Reuse FoundationDB artifacts installed during the build stage +COPY --from=builder /usr/lib/libfdb_c* /usr/lib/ +COPY --from=builder /usr/lib/foundationdb /usr/lib/foundationdb +COPY --from=builder /usr/bin/fdb* /usr/bin/ +RUN ldconfig # Copy SeaweedFS binary and configuration COPY --from=builder /go/bin/weed /usr/bin/ diff --git a/docker/filer_foundationdb.toml b/docker/filer_foundationdb.toml index c7a7e3d28..6b8a00ce3 100644 --- a/docker/filer_foundationdb.toml +++ b/docker/filer_foundationdb.toml @@ -9,7 +9,7 @@ recursive_delete = false [foundationdb] enabled = true cluster_file = "/etc/foundationdb/fdb.cluster" -api_version = 730 +api_version = 740 # Optional: timeout for FDB operations (default: 10s) # timeout = "10s" # Optional: max retry delay for retryable errors (default: 1s) diff --git a/test/foundationdb/Dockerfile.build.arm64 b/test/foundationdb/Dockerfile.build.arm64 index 1afbcd369..f67e59b17 100644 --- a/test/foundationdb/Dockerfile.build.arm64 +++ b/test/foundationdb/Dockerfile.build.arm64 @@ -1,49 +1,28 @@ # Multi-stage Dockerfile to build SeaweedFS with FoundationDB support for ARM64 FROM --platform=linux/arm64 golang:1.24-bookworm AS builder -ARG FOUNDATIONDB_VERSION=7.1.0 +ARG FOUNDATIONDB_VERSION=7.4.5 ENV FOUNDATIONDB_VERSION=${FOUNDATIONDB_VERSION} -# Install build dependencies +# Install build dependencies and download prebuilt FoundationDB clients RUN apt-get update && apt-get install -y \ build-essential \ - cmake \ git \ - python3 \ wget \ - ninja-build \ - libboost-dev \ - libboost-system-dev \ - libboost-filesystem-dev \ - libssl-dev \ ca-certificates \ - && rm -rf /var/lib/apt/lists/* - -# Build FoundationDB client libraries from source (ARM64) -WORKDIR /tmp -RUN git clone https://github.com/apple/foundationdb.git && \ - cd foundationdb && \ - git checkout release-7.1 && \ - mkdir build && \ - cd build && \ - cmake -G Ninja -DCMAKE_BUILD_TYPE=Release \ - -DBUILD_JAVA_BINDING=OFF \ - -DBUILD_CSHARP_BINDING=OFF \ - -DBUILD_PYTHON_BINDING=OFF \ - -DBUILD_RUBY_BINDING=OFF \ - .. && \ - ninja -j$(nproc) fdb_c && \ - echo "🔍 Verifying FoundationDB build..." && \ - ls -la lib/ && \ - ls -la bindings/c/ - -# Install FoundationDB client libraries -RUN cp /tmp/foundationdb/build/lib/libfdb_c.so /usr/lib/ && \ - cp /tmp/foundationdb/bindings/c/foundationdb/fdb_c.h /usr/include/ && \ - mkdir -p /usr/include/foundationdb && \ - cp /tmp/foundationdb/bindings/c/foundationdb/fdb_c_options.g.h /usr/include/foundationdb/ && \ + && rm -rf /var/lib/apt/lists/* && \ + set -euo pipefail && \ + case "${FOUNDATIONDB_VERSION}" in \ + "7.4.5") EXPECTED_SHA256="f2176b86b7e1b561c3632b4e6e7efb82e3b8f57c2ff0d0ac4671e742867508aa" ;; \ + *) echo "ERROR: No known ARM64 client checksum for FoundationDB ${FOUNDATIONDB_VERSION}. Please update this Dockerfile." >&2; exit 1 ;; \ + esac && \ + PACKAGE="foundationdb-clients_${FOUNDATIONDB_VERSION}-1_aarch64.deb" && \ + wget --timeout=30 --tries=3 https://github.com/apple/foundationdb/releases/download/${FOUNDATIONDB_VERSION}/${PACKAGE} && \ + echo "${EXPECTED_SHA256} ${PACKAGE}" | sha256sum -c - && \ + dpkg -i ${PACKAGE} && \ + rm ${PACKAGE} && \ ldconfig && \ - echo "✅ FoundationDB client libraries installed" + echo "✅ FoundationDB client libraries installed (prebuilt ${FOUNDATIONDB_VERSION})" # Set up Go environment for CGO ENV CGO_ENABLED=1 @@ -83,8 +62,9 @@ RUN apt-get update && apt-get install -y \ libssl3 \ && rm -rf /var/lib/apt/lists/* -# Copy FoundationDB client library from builder -COPY --from=builder /usr/lib/libfdb_c.so /usr/lib/ +# Copy FoundationDB client library and headers from builder +COPY --from=builder /usr/lib/libfdb_c* /usr/lib/ +COPY --from=builder /usr/include/foundationdb /usr/include/foundationdb RUN ldconfig # Copy SeaweedFS binary diff --git a/test/foundationdb/Dockerfile.fdb-arm64 b/test/foundationdb/Dockerfile.fdb-arm64 index 0aeef0e83..7a09f726e 100644 --- a/test/foundationdb/Dockerfile.fdb-arm64 +++ b/test/foundationdb/Dockerfile.fdb-arm64 @@ -1,80 +1,51 @@ -# Multi-stage Dockerfile to build FoundationDB for ARM64 -FROM --platform=linux/arm64 ubuntu:22.04 as builder - -# Install dependencies for building FoundationDB -RUN apt-get update && apt-get install -y \ - build-essential \ - cmake \ - git \ - python3 \ - python3-pip \ - wget \ - curl \ - ninja-build \ - libboost-dev \ - libboost-system-dev \ - libboost-filesystem-dev \ - libssl-dev \ - openjdk-8-jdk \ - mono-complete \ - && rm -rf /var/lib/apt/lists/* - -# Clone FoundationDB source -WORKDIR /tmp -RUN git clone https://github.com/apple/foundationdb.git -WORKDIR /tmp/foundationdb - -# Checkout a stable release version (ARM64 build from source) -# Using 7.1 branch as 7.4.5 ARM64 builds are not available pre-built -RUN git checkout release-7.1 - -# Build FoundationDB (disable bindings that cause issues) -RUN mkdir build -WORKDIR /tmp/foundationdb/build -RUN cmake -G Ninja -DCMAKE_BUILD_TYPE=Release \ - -DBUILD_JAVA_BINDING=OFF \ - -DBUILD_CSHARP_BINDING=OFF \ - -DBUILD_PYTHON_BINDING=OFF \ - -DBUILD_RUBY_BINDING=OFF \ - .. -RUN ninja -j$(nproc) fdbserver fdbcli - -# Runtime stage +# FoundationDB server image for ARM64 using official prebuilt packages FROM --platform=linux/arm64 ubuntu:22.04 -# Install runtime dependencies +ARG FOUNDATIONDB_VERSION=7.4.5 +ENV FOUNDATIONDB_VERSION=${FOUNDATIONDB_VERSION} + +# Install prerequisites RUN apt-get update && apt-get install -y \ + ca-certificates \ + wget \ python3 \ libssl3 \ libboost-system1.74.0 \ libboost-filesystem1.74.0 \ && rm -rf /var/lib/apt/lists/* -# Copy built binaries from builder stage -COPY --from=builder /tmp/foundationdb/build/bin/fdbserver /usr/bin/ -COPY --from=builder /tmp/foundationdb/build/bin/fdbcli /usr/bin/ -COPY --from=builder /tmp/foundationdb/build/lib/libfdb_c.so /usr/lib/ - -# Create FDB directories -RUN mkdir -p /var/fdb/{logs,data,config} && \ - mkdir -p /usr/lib/foundationdb && \ - mkdir -p /var/fdb/scripts - -# Create basic startup script -COPY --from=builder /tmp/foundationdb/packaging/docker/scripts/* /var/fdb/scripts/ -RUN chmod +x /var/fdb/scripts/* - -# Set environment variables -# NOTE: These defaults are for single-node testing only. -# For multi-node Docker Compose clusters, override PUBLIC_IP with the container's -# network-resolvable hostname/IP via docker-compose environment settings. -ENV FDB_NETWORKING_MODE=container -ENV FDB_COORDINATOR_PORT=4500 -ENV FDB_PORT=4501 -ENV PUBLIC_IP=auto - -# Expose ports -EXPOSE 4500 4501 - -# Default command -CMD ["/var/fdb/scripts/fdb.bash"] +# Install FoundationDB server + client debs with checksum verification +RUN set -euo pipefail && \ + apt-get update && \ + case "${FOUNDATIONDB_VERSION}" in \ + "7.4.5") \ + CLIENT_SHA="f2176b86b7e1b561c3632b4e6e7efb82e3b8f57c2ff0d0ac4671e742867508aa"; \ + SERVER_SHA="d7b081afbbabfdf2452cfbdc5c7c895165457ae32d91fc7f9489da921ab02e26"; \ + ;; \ + *) \ + echo "Unsupported FoundationDB version ${FOUNDATIONDB_VERSION} for ARM64 runtime" >&2; \ + exit 1 ;; \ + esac && \ + for component in clients server; do \ + if [ "${component}" = "clients" ]; then \ + EXPECTED_SHA="${CLIENT_SHA}"; \ + else \ + EXPECTED_SHA="${SERVER_SHA}"; \ + fi && \ + PACKAGE="foundationdb-${component}_${FOUNDATIONDB_VERSION}-1_aarch64.deb" && \ + PACKAGE_PATH="/tmp/${PACKAGE}" && \ + wget --timeout=30 --tries=3 -O "${PACKAGE_PATH}" \ + "https://github.com/apple/foundationdb/releases/download/${FOUNDATIONDB_VERSION}/${PACKAGE}" && \ + echo "${EXPECTED_SHA} ${PACKAGE_PATH}" | sha256sum -c - && \ + apt-get install -y "${PACKAGE_PATH}" && \ + rm "${PACKAGE_PATH}"; \ + done && \ + rm -rf /var/lib/apt/lists/* && \ + ldconfig && \ + echo "✅ Installed FoundationDB ${FOUNDATIONDB_VERSION} (server + clients)" + +# Prepare directories commonly bind-mounted by docker-compose +RUN mkdir -p /var/fdb/{logs,data,config} /usr/lib/foundationdb + +# Provide a simple default command (docker-compose overrides this) +CMD ["/bin/bash"] diff --git a/test/foundationdb/README.ARM64.md b/test/foundationdb/README.ARM64.md index 72bddd630..88ca292dd 100644 --- a/test/foundationdb/README.ARM64.md +++ b/test/foundationdb/README.ARM64.md @@ -4,7 +4,7 @@ This document explains how to run FoundationDB integration tests on ARM64 system ## Problem -The official FoundationDB Docker images (`foundationdb/foundationdb:7.1.61`) are only available for `linux/amd64` architecture. When running on ARM64 systems, you'll encounter "Illegal instruction" errors. +The official FoundationDB Docker images (`foundationdb/foundationdb:7.1.61`) are only available for `linux/amd64` architecture. When running on ARM64 systems, you'll encounter "Illegal instruction" errors. Apple now publishes official ARM64 Debian packages (starting with 7.4.5), which this repo downloads directly for native workflows. ## Solutions @@ -13,7 +13,7 @@ We provide **three different approaches** to run FoundationDB on ARM64: ### 1. 🚀 ARM64 Native (Recommended for Development) **Pros:** Native performance, no emulation overhead -**Cons:** Longer initial setup time (10-15 minutes to build) +**Cons:** Requires downloading ~100MB of FoundationDB packages on first run ```bash # Build and run ARM64-native FoundationDB from source @@ -22,8 +22,8 @@ make test-arm64 ``` This approach: -- Builds FoundationDB from source for ARM64 -- Takes 10-15 minutes on first run +- Downloads the official FoundationDB 7.4.5 ARM64 packages +- Takes ~2-3 minutes on first run (no source compilation) - Provides native performance - Uses `docker-compose.arm64.yml` @@ -68,7 +68,7 @@ make test-reliable | Approach | Setup Time | Runtime Performance | Compatibility | |----------|------------|-------------------|---------------| -| ARM64 Native | 10-15 min | ⭐⭐⭐⭐⭐ | ARM64 only | +| ARM64 Native | 2-3 min | ⭐⭐⭐⭐⭐ | ARM64 only | | x86 Emulation | 2-3 min | ⭐⭐⭐ | ARM64 + x86 | | Mock Testing | < 1 min | ⭐⭐⭐⭐⭐ | Any platform | @@ -121,16 +121,14 @@ uname -m # Should show arm64 ## Architecture Details -The ARM64 solution uses a multi-stage Docker build: +The ARM64 solution now uses the official FoundationDB 7.4.5 aarch64 packages: -1. **Builder Stage**: Compiles FoundationDB from source - - Uses Ubuntu 22.04 ARM64 base - - Installs build dependencies (cmake, ninja, etc.) - - Clones and builds FoundationDB release-7.1 +1. **Builder Stage**: Downloads prebuilt FoundationDB client libraries + - Uses Debian-based Go image for compiling SeaweedFS + - Verifies SHA256 checksums before installing the deb package -2. **Runtime Stage**: Creates minimal runtime image - - Copies compiled binaries from builder - - Installs only runtime dependencies - - Maintains compatibility with existing scripts +2. **Runtime Stage**: Copies the already-installed artifacts + - SeaweedFS runtime layers reuse the validated libraries + - FoundationDB server containers install the prebuilt server + client packages with checksum verification -This approach ensures we get native ARM64 binaries while maintaining compatibility with the existing test infrastructure. +This keeps the setup time short while preserving native ARM64 performance and strong supply-chain guarantees. diff --git a/weed/filer/foundationdb/foundationdb_store_test.go b/weed/filer/foundationdb/foundationdb_store_test.go index 6295f6846..215c98c76 100644 --- a/weed/filer/foundationdb/foundationdb_store_test.go +++ b/weed/filer/foundationdb/foundationdb_store_test.go @@ -349,6 +349,22 @@ func createBenchmarkStore(b *testing.B) *FoundationDBStore { return store } +func getTestStore(t *testing.T) *FoundationDBStore { + t.Helper() + + clusterFile := getTestClusterFile() + if _, err := os.Stat(clusterFile); os.IsNotExist(err) { + t.Skip("FoundationDB cluster file not found, skipping test") + } + + store := &FoundationDBStore{} + if err := store.initialize(clusterFile, 740); err != nil { + t.Skipf("Failed to initialize FoundationDB store: %v", err) + } + + return store +} + func containsString(s, substr string) bool { return strings.Contains(s, substr) }