You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by do...@apache.org on 2026/03/25 07:13:53 UTC

(spark-connect-swift) branch main updated: [SPARK-56197] Use `musl` Static Linux SDK for `Examples` Docker images

This is an automated email from the ASF dual-hosted git repository.

dongjoon pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/spark-connect-swift.git


The following commit(s) were added to refs/heads/main by this push:
     new 6b88929  [SPARK-56197] Use `musl` Static Linux SDK for `Examples` Docker images
6b88929 is described below

commit 6b88929c627eabd594a966891d26243b5e8958dc
Author: Dongjoon Hyun <do...@apache.org>
AuthorDate: Wed Mar 25 00:13:46 2026 -0700

    [SPARK-56197] Use `musl` Static Linux SDK for `Examples` Docker images
    
    ### What changes were proposed in this pull request?
    
    This PR migrates all 5 Swift example Dockerfiles to use the Swift Static Linux SDK with `musl`, replacing the previous `--static-swift-stdlib` (glibc) approach in order to minimize the docker image, **50% (67.2MB -> 33.4MB)**.
    
    ```diff
    $ docker images apache/spark-connect-swift:pi
    IMAGE                           ID             DISK USAGE   CONTENT SIZE   EXTRA
    -apache/spark-connect-swift:pi   b9bf9cb20548        287MB         67.2MB
    +apache/spark-connect-swift:pi   124469e785c6        116MB         33.4MB
    ```
    
    Changes per Dockerfile:
    - Install Swift 6.2.4 Static Linux SDK via `ADD` + `swift sdk install`
    - Build with `--swift-sdk ${arch}-swift-linux-musl` instead of `--static-swift-stdlib`
    - Strip binaries to reduce image size
    - Use `gcr.io/distroless/static-debian12:nonroot` instead of `gcr.io/distroless/cc-debian13:nonroot`
    - Update binary path glob from `*-unknown-linux-gnu` to `*-swift-linux-musl`
    
    ### Why are the changes needed?
    
    The previous approach (`--static-swift-stdlib`) only statically linked the Swift standard library while still dynamically linking glibc. With the `musl` Static Linux SDK, binaries are fully statically linked with no external dependencies, enabling the use of a smaller `distroless/static` runtime image instead of `distroless/cc`.
    
    Since the difference of the base distroless images is 11MB, the `musl` reduces the app size roughly 23MB.
    ```
    $ docker images
    IMAGE                                       ID             DISK USAGE   CONTENT SIZE   EXTRA
    gcr.io/distroless/cc-debian13:nonroot       9c4fe2381c2e       53.5MB         10.9MB
    gcr.io/distroless/static-debian12:nonroot   a9329520abc4       5.54MB          139kB
    ```
    
    ### Does this PR introduce _any_ user-facing change?
    
    No.
    
    ### How was this patch tested?
    
    Manual Docker build and verification.
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    Generated-by: Claude Code (claude-opus-4-6)
    
    Closes #339 from dongjoon-hyun/SPARK-56197.
    
    Authored-by: Dongjoon Hyun <do...@apache.org>
    Signed-off-by: Dongjoon Hyun <do...@apache.org>
---
 Examples/app/Dockerfile       | 12 +++++++++---
 Examples/pi/Dockerfile        | 12 +++++++++---
 Examples/spark-sql/Dockerfile | 12 +++++++++---
 Examples/stream/Dockerfile    | 12 +++++++++---
 Examples/web/Dockerfile       | 12 +++++++++---
 5 files changed, 45 insertions(+), 15 deletions(-)

diff --git a/Examples/app/Dockerfile b/Examples/app/Dockerfile
index bf2b0d1..b36504b 100644
--- a/Examples/app/Dockerfile
+++ b/Examples/app/Dockerfile
@@ -18,16 +18,22 @@ FROM swift:6.2 AS builder
 
 WORKDIR /app
 
+ADD https://download.swift.org/swift-6.2.4-release/static-sdk/swift-6.2.4-RELEASE/swift-6.2.4-RELEASE_static-linux-0.1.0.artifactbundle.tar.gz /tmp/swift-static-sdk.tar.gz
+RUN swift sdk install /tmp/swift-static-sdk.tar.gz && \
+    rm /tmp/swift-static-sdk.tar.gz
+
 COPY . .
 
-RUN swift build -c release --static-swift-stdlib
+RUN arch=$(uname -m) && \
+    swift build -c release --swift-sdk ${arch}-swift-linux-musl && \
+    strip .build/*-swift-linux-musl/release/SparkConnectSwiftApp
 
-FROM gcr.io/distroless/cc-debian13:nonroot
+FROM gcr.io/distroless/static-debian12:nonroot
 
 LABEL org.opencontainers.image.authors="Apache Spark project <de...@spark.apache.org>"
 LABEL org.opencontainers.image.licenses="Apache-2.0"
 LABEL org.opencontainers.image.ref.name="Apache Spark Connect for Swift"
 
-COPY --from=builder --chown=65532:65532 /app/.build/*-unknown-linux-gnu/release/SparkConnectSwiftApp /opt/spark-app/
+COPY --from=builder --chown=65532:65532 /app/.build/*-swift-linux-musl/release/SparkConnectSwiftApp /opt/spark-app/
 
 ENTRYPOINT ["/opt/spark-app/SparkConnectSwiftApp"]
diff --git a/Examples/pi/Dockerfile b/Examples/pi/Dockerfile
index 811b431..5dca5fe 100644
--- a/Examples/pi/Dockerfile
+++ b/Examples/pi/Dockerfile
@@ -18,16 +18,22 @@ FROM swift:6.2 AS builder
 
 WORKDIR /app
 
+ADD https://download.swift.org/swift-6.2.4-release/static-sdk/swift-6.2.4-RELEASE/swift-6.2.4-RELEASE_static-linux-0.1.0.artifactbundle.tar.gz /tmp/swift-static-sdk.tar.gz
+RUN swift sdk install /tmp/swift-static-sdk.tar.gz && \
+    rm /tmp/swift-static-sdk.tar.gz
+
 COPY . .
 
-RUN swift build -c release --static-swift-stdlib
+RUN arch=$(uname -m) && \
+    swift build -c release --swift-sdk ${arch}-swift-linux-musl && \
+    strip .build/*-swift-linux-musl/release/SparkConnectSwiftPi
 
-FROM gcr.io/distroless/cc-debian13:nonroot
+FROM gcr.io/distroless/static-debian12:nonroot
 
 LABEL org.opencontainers.image.authors="Apache Spark project <de...@spark.apache.org>"
 LABEL org.opencontainers.image.licenses="Apache-2.0"
 LABEL org.opencontainers.image.ref.name="Apache Spark Connect for Swift"
 
-COPY --from=builder --chown=65532:65532 /app/.build/*-unknown-linux-gnu/release/SparkConnectSwiftPi /opt/spark-app/
+COPY --from=builder --chown=65532:65532 /app/.build/*-swift-linux-musl/release/SparkConnectSwiftPi /opt/spark-app/
 
 ENTRYPOINT ["/opt/spark-app/SparkConnectSwiftPi"]
diff --git a/Examples/spark-sql/Dockerfile b/Examples/spark-sql/Dockerfile
index e15a713..a44ff63 100644
--- a/Examples/spark-sql/Dockerfile
+++ b/Examples/spark-sql/Dockerfile
@@ -18,16 +18,22 @@ FROM swift:6.2 AS builder
 
 WORKDIR /app
 
+ADD https://download.swift.org/swift-6.2.4-release/static-sdk/swift-6.2.4-RELEASE/swift-6.2.4-RELEASE_static-linux-0.1.0.artifactbundle.tar.gz /tmp/swift-static-sdk.tar.gz
+RUN swift sdk install /tmp/swift-static-sdk.tar.gz && \
+    rm /tmp/swift-static-sdk.tar.gz
+
 COPY . .
 
-RUN swift build -c release --static-swift-stdlib
+RUN arch=$(uname -m) && \
+    swift build -c release --swift-sdk ${arch}-swift-linux-musl && \
+    strip .build/*-swift-linux-musl/release/SparkConnectSwiftSQLRepl
 
-FROM gcr.io/distroless/cc-debian13:nonroot
+FROM gcr.io/distroless/static-debian12:nonroot
 
 LABEL org.opencontainers.image.authors="Apache Spark project <de...@spark.apache.org>"
 LABEL org.opencontainers.image.licenses="Apache-2.0"
 LABEL org.opencontainers.image.ref.name="Apache Spark Connect for Swift"
 
-COPY --from=builder --chown=65532:65532 /app/.build/*-unknown-linux-gnu/release/SparkConnectSwiftSQLRepl /opt/spark-app/
+COPY --from=builder --chown=65532:65532 /app/.build/*-swift-linux-musl/release/SparkConnectSwiftSQLRepl /opt/spark-app/
 
 ENTRYPOINT ["/opt/spark-app/SparkConnectSwiftSQLRepl"]
diff --git a/Examples/stream/Dockerfile b/Examples/stream/Dockerfile
index 8750b94..299ad19 100644
--- a/Examples/stream/Dockerfile
+++ b/Examples/stream/Dockerfile
@@ -18,16 +18,22 @@ FROM swift:6.2 AS builder
 
 WORKDIR /app
 
+ADD https://download.swift.org/swift-6.2.4-release/static-sdk/swift-6.2.4-RELEASE/swift-6.2.4-RELEASE_static-linux-0.1.0.artifactbundle.tar.gz /tmp/swift-static-sdk.tar.gz
+RUN swift sdk install /tmp/swift-static-sdk.tar.gz && \
+    rm /tmp/swift-static-sdk.tar.gz
+
 COPY . .
 
-RUN swift build -c release --static-swift-stdlib
+RUN arch=$(uname -m) && \
+    swift build -c release --swift-sdk ${arch}-swift-linux-musl && \
+    strip .build/*-swift-linux-musl/release/SparkConnectSwiftNetworkWordCount
 
-FROM gcr.io/distroless/cc-debian13:nonroot
+FROM gcr.io/distroless/static-debian12:nonroot
 
 LABEL org.opencontainers.image.authors="Apache Spark project <de...@spark.apache.org>"
 LABEL org.opencontainers.image.licenses="Apache-2.0"
 LABEL org.opencontainers.image.ref.name="Apache Spark Connect for Swift"
 
-COPY --from=builder --chown=65532:65532 /app/.build/*-unknown-linux-gnu/release/SparkConnectSwiftNetworkWordCount /opt/spark-app/
+COPY --from=builder --chown=65532:65532 /app/.build/*-swift-linux-musl/release/SparkConnectSwiftNetworkWordCount /opt/spark-app/
 
 ENTRYPOINT ["/opt/spark-app/SparkConnectSwiftNetworkWordCount"]
diff --git a/Examples/web/Dockerfile b/Examples/web/Dockerfile
index 2dd09c9..845d230 100644
--- a/Examples/web/Dockerfile
+++ b/Examples/web/Dockerfile
@@ -18,17 +18,23 @@ FROM swift:6.2 AS builder
 
 WORKDIR /app
 
+ADD https://download.swift.org/swift-6.2.4-release/static-sdk/swift-6.2.4-RELEASE/swift-6.2.4-RELEASE_static-linux-0.1.0.artifactbundle.tar.gz /tmp/swift-static-sdk.tar.gz
+RUN swift sdk install /tmp/swift-static-sdk.tar.gz && \
+    rm /tmp/swift-static-sdk.tar.gz
+
 COPY . .
 
-RUN swift build -c release --static-swift-stdlib
+RUN arch=$(uname -m) && \
+    swift build -c release --swift-sdk ${arch}-swift-linux-musl && \
+    strip .build/*-swift-linux-musl/release/SparkConnectSwiftWeb
 
-FROM gcr.io/distroless/cc-debian13:nonroot
+FROM gcr.io/distroless/static-debian12:nonroot
 
 LABEL org.opencontainers.image.authors="Apache Spark project <de...@spark.apache.org>"
 LABEL org.opencontainers.image.licenses="Apache-2.0"
 LABEL org.opencontainers.image.ref.name="Apache Spark Connect for Swift"
 
-COPY --from=builder --chown=65532:65532 /app/.build/*-unknown-linux-gnu/release/SparkConnectSwiftWeb /opt/spark-app/
+COPY --from=builder --chown=65532:65532 /app/.build/*-swift-linux-musl/release/SparkConnectSwiftWeb /opt/spark-app/
 
 EXPOSE 8080
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org