mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 20:29:23 +00:00
Remove workaround for lack of musl-dev now that musl-dev is provided in Rust Alpine images
Additionally, optimizes the build process a bit via leaving only the runtime (and `busybox`) in the final image, and additionally building the runtime without `std` (as we solely need the WASM blob from this process).
This commit is contained in:
@@ -1,28 +1,8 @@
|
||||
#check=skip=FromPlatformFlagConstDisallowed
|
||||
# We want to explicitly set the platform to ensure a constant host environment
|
||||
|
||||
# rust:1.91.1-alpine as of November 11th, 2025 (GMT)
|
||||
FROM --platform=linux/amd64 rust@sha256:700c0959b23445f69c82676b72caa97ca4359decd075dca55b13339df27dc4d3
|
||||
|
||||
# In order to compile the runtime, including the `proc-macro`s and build scripts, we need the
|
||||
# required development libraries. These are traditionally provided by `musl-dev` which is not
|
||||
# inherently included with this image (https://github.com/rust-lang/docker-rust/issues/68). While we
|
||||
# could install it here, we'd be unable to pin the installed package by its hash as desired.
|
||||
#
|
||||
# Rust does have self-contained libraries, intended to be used when the desired development files
|
||||
# are not otherwise available. These can be enabled with `link-self-contained=yes`. Unfortunately,
|
||||
# this doesn't work here (https://github.com/rust-lang/rust/issues/149371).
|
||||
#
|
||||
# While we can't set `link-self-contained=yes`, we can install Rust's self-contained libraries onto
|
||||
# our system so they're generally available.
|
||||
RUN echo '#!/bin/sh' > libs.sh
|
||||
RUN echo 'set -e' >> libs.sh
|
||||
RUN echo 'SYSROOT=$(rustc --print sysroot)' >> libs.sh
|
||||
RUN echo 'LIBS=$SYSROOT/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained' >> libs.sh
|
||||
RUN echo 'ln -s $LIBS/Scrt1.o $LIBS/crti.o $LIBS/crtn.o /usr/lib' >> libs.sh
|
||||
# We also need `libc.so` which is already present on the system, just not under that name
|
||||
RUN echo 'ln -s /lib/libc.musl-x86_64.so.1 /usr/lib/libc.so' >> libs.sh
|
||||
RUN /bin/sh ./libs.sh
|
||||
# rust:1.91.1-alpine as of December 4th, 2025 (GMT)
|
||||
FROM --platform=linux/amd64 rust@sha256:84f263251b0ada72c1913d82a824d47be15a607f3faf015d8bdae48db544cdf2 AS builder
|
||||
|
||||
# Add the WASM toolchain
|
||||
RUN rustup target add wasm32v1-none
|
||||
@@ -47,11 +27,16 @@ ADD AGPL-3.0 /serai
|
||||
WORKDIR /serai
|
||||
|
||||
# Build the runtime
|
||||
RUN cargo build --release -p serai-runtime
|
||||
# Copy the artifact
|
||||
RUN cp /serai/target/release/wbuild/serai-runtime/serai_runtime.wasm /serai/serai.wasm
|
||||
# Clean up the build directory
|
||||
RUN cargo clean
|
||||
RUN cargo build --release -p serai-runtime --no-default-features
|
||||
|
||||
# Copy the runtime to the provided volume
|
||||
CMD ["cp", "/serai/serai.wasm", "/volume/serai.wasm"]
|
||||
# Copy the artifact to its own image which solely exists to further export it
|
||||
FROM scratch
|
||||
# Copy `busybox`, including the necessary shared libraries, from the builder for a functioning `cp`
|
||||
COPY --from=builder /lib/ld-musl-x86_64.so.1 /lib/libc.musl-x86_64.so.1 /lib/
|
||||
COPY --from=builder /bin/busybox /bin/
|
||||
ENV LD_LIBRARY_PATH=/lib/
|
||||
ENV PATH=/bin
|
||||
# Copy the artifact itself
|
||||
COPY --from=builder /serai/target/release/wbuild/serai-runtime/serai_runtime.wasm /serai.wasm
|
||||
# By default, copy the artifact to `/volume`, presumably a provided volume
|
||||
CMD ["busybox", "cp", "/serai.wasm", "/volume/serai.wasm"]
|
||||
|
||||
Reference in New Issue
Block a user