diff --git a/wish/cpp/Dockerfile.benchmark b/wish/cpp/Dockerfile.benchmark index ab929f8..d238e12 100644 --- a/wish/cpp/Dockerfile.benchmark +++ b/wish/cpp/Dockerfile.benchmark @@ -24,16 +24,27 @@ COPY patches/ patches/ COPY src/ src/ COPY benchmark/ benchmark/ -# Configure: triggers FetchContent downloads (cached as a Docker layer). -RUN cmake -B build -G Ninja \ - -DCMAKE_BUILD_TYPE=Release \ - -DWISH_BUILD_TESTS=OFF \ - -DWISH_BUILD_BENCHMARKS=ON \ - -DWISH_BUILD_EXAMPLES=OFF - -RUN cmake --build build \ - --target benchmark_client tls_benchmark_client high_qps_benchmark_client \ - -- -j"$(nproc)" +# Two persistent BuildKit cache volumes: +# /cmake-cache – FetchContent downloads (git repos, tarballs) +# /cmake-build – full cmake build tree (object files, compiled libs) +# Both survive Docker layer invalidations; only changed sources are +# recompiled on subsequent builds. +# The binary is copied into the image layer at the end of the step. +RUN --mount=type=cache,target=/cmake-cache,sharing=locked \ + --mount=type=cache,target=/cmake-build,sharing=locked \ + cmake -S . -B /cmake-build -G Ninja \ + -DFETCHCONTENT_BASE_DIR=/cmake-cache \ + -DCMAKE_BUILD_TYPE=Release \ + -DWISH_BUILD_TESTS=OFF \ + -DWISH_BUILD_BENCHMARKS=ON \ + -DWISH_BUILD_EXAMPLES=OFF \ + && cmake --build /cmake-build \ + --target benchmark_client tls_benchmark_client high_qps_benchmark_client \ + -- -j"$(nproc)" \ + && mkdir -p build \ + && cp /cmake-build/benchmark/benchmark_client build/benchmark_client \ + && cp /cmake-build/benchmark/tls_benchmark_client build/tls_benchmark_client \ + && cp /cmake-build/benchmark/high_qps_benchmark_client build/high_qps_benchmark_client # --------------------------------------------------------------------------- # Stage 2: Runtime @@ -44,9 +55,9 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ libstdc++6 \ && rm -rf /var/lib/apt/lists/* -COPY --from=builder /src/build/benchmark/benchmark_client /usr/local/bin/benchmark_client -COPY --from=builder /src/build/benchmark/tls_benchmark_client /usr/local/bin/tls_benchmark_client -COPY --from=builder /src/build/benchmark/high_qps_benchmark_client /usr/local/bin/high_qps_benchmark_client +COPY --from=builder /src/build/benchmark_client /usr/local/bin/benchmark_client +COPY --from=builder /src/build/tls_benchmark_client /usr/local/bin/tls_benchmark_client +COPY --from=builder /src/build/high_qps_benchmark_client /usr/local/bin/high_qps_benchmark_client # Default: latency benchmark client. # Override the ENTRYPOINT or CMD in the Job spec to switch clients. diff --git a/wish/cpp/Dockerfile.echo_server b/wish/cpp/Dockerfile.echo_server index 852483d..329188c 100644 --- a/wish/cpp/Dockerfile.echo_server +++ b/wish/cpp/Dockerfile.echo_server @@ -24,16 +24,26 @@ COPY patches/ patches/ COPY src/ src/ COPY examples/ examples/ -# Configure: triggers FetchContent downloads (cached as a Docker layer). -RUN cmake -B build -G Ninja \ - -DCMAKE_BUILD_TYPE=Release \ - -DWISH_BUILD_TESTS=OFF \ - -DWISH_BUILD_BENCHMARKS=OFF \ - -DWISH_BUILD_EXAMPLES=ON - -RUN cmake --build build \ - --target echo_server tls_echo_server \ - -- -j"$(nproc)" +# Two persistent BuildKit cache volumes: +# /cmake-cache – FetchContent downloads (git repos, tarballs) +# /cmake-build – full cmake build tree (object files, compiled libs) +# Both survive Docker layer invalidations; only changed sources are +# recompiled on subsequent builds. +# The binary is copied into the image layer at the end of the step. +RUN --mount=type=cache,target=/cmake-cache,sharing=locked \ + --mount=type=cache,target=/cmake-build,sharing=locked \ + cmake -S . -B /cmake-build -G Ninja \ + -DFETCHCONTENT_BASE_DIR=/cmake-cache \ + -DCMAKE_BUILD_TYPE=Release \ + -DWISH_BUILD_TESTS=OFF \ + -DWISH_BUILD_BENCHMARKS=OFF \ + -DWISH_BUILD_EXAMPLES=ON \ + && cmake --build /cmake-build \ + --target echo_server tls_echo_server \ + -- -j"$(nproc)" \ + && mkdir -p build \ + && cp /cmake-build/examples/echo_server build/echo_server \ + && cp /cmake-build/examples/tls_echo_server build/tls_echo_server # --------------------------------------------------------------------------- # Stage 2: Runtime @@ -44,8 +54,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ libstdc++6 \ && rm -rf /var/lib/apt/lists/* -COPY --from=builder /src/build/examples/echo_server /usr/local/bin/echo_server -COPY --from=builder /src/build/examples/tls_echo_server /usr/local/bin/tls_echo_server +COPY --from=builder /src/build/echo_server /usr/local/bin/echo_server +COPY --from=builder /src/build/tls_echo_server /usr/local/bin/tls_echo_server EXPOSE 8080 diff --git a/wish/cpp/scripts/build-and-push.sh b/wish/cpp/scripts/build-and-push.sh index adb576a..42f57f3 100755 --- a/wish/cpp/scripts/build-and-push.sh +++ b/wish/cpp/scripts/build-and-push.sh @@ -7,12 +7,12 @@ # (or: gcloud auth login && gcloud auth application-default login) # # Usage: -# cd wish/cpp # REGION=asia-northeast1 PROJECT=my-gcp-project REPOSITORY=wish ./scripts/build-and-push.sh # # Optional env vars: # TAG – image tag (default: git short SHA or "latest") # PUSH – set to "false" to build only without pushing +# FRESH – set to "true" to bypass all caches (re-downloads FetchContent deps) set -euo pipefail @@ -30,14 +30,16 @@ else fi TAG="${TAG:-${DEFAULT_TAG}}" PUSH="${PUSH:-true}" +FRESH="${FRESH:-false}" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -# The build context is wish/cpp (one level above scripts/). +# The build context is one level above scripts/. CTX="$(cd "${SCRIPT_DIR}/.." && pwd)" echo "==> Build context : ${CTX}" echo "==> Registry : ${REGISTRY}" echo "==> Tag : ${TAG}" +echo "==> Fresh build : ${FRESH}" echo "" build_and_push() { @@ -47,10 +49,13 @@ build_and_push() { local latest_tag="${REGISTRY}/${name}:latest" echo "==> Building ${full_tag} ..." + local extra_flags=() + [[ "${FRESH}" == "true" ]] && extra_flags+=(--no-cache) DOCKER_BUILDKIT=1 docker build \ --file "${CTX}/${dockerfile}" \ --tag "${full_tag}" \ --tag "${latest_tag}" \ + "${extra_flags[@]}" \ "${CTX}" if [[ "${PUSH}" == "true" ]]; then @@ -60,5 +65,5 @@ build_and_push() { fi } -build_and_push "echo-server" "Dockerfile.echo_server" +build_and_push "echo-server" "Dockerfile.echo_server" build_and_push "benchmark" "Dockerfile.benchmark"