stalwartlabs / mail-server

Secure & Modern All-in-One Mail Server (IMAP, JMAP, POP3, SMTP)
https://stalw.art
4.81k stars 194 forks source link

[bug]: Stalwart docker image build failed with FoundationDB client support using Dockerfile.fdb #413

Closed AshanCG closed 4 months ago

AshanCG commented 4 months ago

What happened?

Hi team,

We tried build stalwart with foundationdb support using https://github.com/stalwartlabs/mail-server/blob/v0.7.3/resources/docker/Dockerfile.fdb file and we get following error when starting container;

/usr/local/bin/stalwart-mail: error while loading shared libraries: libfdb_c.so: cannot open shared object file: No such file or directory

After further looking into issue, we found out that there is c library to be import in order to FoundationDB client to work correctly, thus getting above issue. Reference

There is also separately an fdb_c dependency that you’ll need to include. There is no way to run the FoundationDB client without having the dependency around. 
    You can download the C library from our website:
       https://www.foundationdb.org/downloads/${version}/${os}/libfdb_c_${version}.${ext}
       github : https://github.com/apple/foundationdb/releases/download/7.3.27/libfdb_c.x86_64.so

We have used sample modified Dockerfile.fdb to complie but failed with below error;

Dockerfile.fdb

FROM debian:buster-slim AS chef
RUN apt-get update && \
    export DEBIAN_FRONTEND=noninteractive && \
    apt-get install -yq \
    build-essential \
    cmake \
    clang \
    curl \
    protobuf-compiler wget
ENV RUSTUP_HOME=/opt/rust/rustup \
    PATH=/home/root/.cargo/bin:/opt/rust/cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
RUN curl https://sh.rustup.rs -sSf | \
    env CARGO_HOME=/opt/rust/cargo \
    sh -s -- -y --default-toolchain stable --profile minimal --no-modify-path && \
    env CARGO_HOME=/opt/rust/cargo \
    rustup component add rustfmt
RUN wget https://github.com/apple/foundationdb/releases/download/7.3.27/foundationdb-clients_7.3.27-1_amd64.deb && \
    dpkg -i foundationdb-clients_7.3.27-1_amd64.deb
#add foundationdb missing dependency
RUN wget https://github.com/apple/foundationdb/releases/download/7.3.27/libfdb_c.x86_64.so -o /usr/lib/libfdb_c.so
# Ensure the library path is included in the library search path
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/

RUN env CARGO_HOME=/opt/rust/cargo cargo install cargo-chef && \
    rm -rf /opt/rust/cargo/registry/
WORKDIR /app

FROM chef AS planner
COPY Cargo.toml .
COPY Cargo.lock .
COPY crates/ crates/
COPY resources/ resources/
COPY tests/ tests/
RUN cargo chef prepare --recipe-path recipe.json

FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json
COPY Cargo.toml .
COPY Cargo.lock .
COPY crates/ crates/
COPY resources/ resources/
COPY tests/ tests/
RUN cargo build --manifest-path=crates/main/Cargo.toml --no-default-features --features foundationdb --release

FROM debian:buster-slim AS runtime

COPY --from=builder /app/target/release/stalwart-mail /usr/local/bin/stalwart-mail
RUN apt-get update -y && apt-get install -yq ca-certificates
RUN useradd stalwart-mail -s /sbin/nologin -M
RUN mkdir -p /opt/stalwart-mail
RUN chown stalwart-mail:stalwart-mail /opt/stalwart-mail

ENTRYPOINT ["/usr/local/bin/stalwart-mail", "--config", "/opt/stalwart-mail/etc/config.toml"]
92.49    Compiling rasn-cms v0.10.6
92.82 warning: trait `IntoBool` is never used
92.82    --> crates/common/src/expr/eval.rs:579:7
92.82     |
92.82 579 | trait IntoBool {
92.82     |       ^^^^^^^^
92.82     |
92.82     = note: `#[warn(dead_code)]` on by default
92.82
94.01    Compiling smtp v0.7.3 (/app/crates/smtp)
95.82    Compiling tokio-tungstenite v0.21.0
96.07    Compiling form-data v0.5.4
96.52    Compiling imap_proto v0.1.0 (/app/crates/imap-proto)
104.7    Compiling jmap v0.7.3 (/app/crates/jmap)
129.3    Compiling imap v0.7.3 (/app/crates/imap)
133.6    Compiling managesieve v0.7.3 (/app/crates/managesieve)
134.3 warning: `common` (lib) generated 1 warning
189.2    Compiling mail-server v0.7.3 (/app/crates/main)
813.2 error: linking with `cc` failed: exit status: 1
813.2   |
813.2   = note: LC_ALL="C" PATH="/opt/rust/rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/root/.cargo/bin:/home/root/.cargo/bin:/opt/rust/cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" VSLANG="1033" "cc" "-m64" "/tmp/rustciQL7kN/symbols.o" "/app/target/release/deps/stalwart_mail-9eefa014788ab2f6.stalwart_mail.31eca6de72de5bfa-cgu.0.rcgu.o" "-Wl,--as-needed" "-L" "/app/target/release/deps" "-L" "/app/target/release/build/blake3-c19fff417a24b4bf/out" "-L" "/app/target/release/build/blake3-c19fff417a24b4bf/out" "-L" "/app/target/release/build/ring-19b54f1b7051e03d/out" "-L" "/app/target/release/build/ring-8606ba2dc89da1a7/out" "-L" "/app/target/release/build/bzip2-sys-68f88257d268ab35/out/lib" "-L" "/app/target/release/build/zstd-sys-51342f20837bd3e2/out" "-L" "/app/target/release/build/libsqlite3-sys-e621220524791723/out" "-L" "/app/target/release/build/jemalloc-sys-17414176d5239a56/out/build/lib" "-L" "/opt/rust/rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/tmp/rustciQL7kN/libjemalloc_sys-4c375f92d298a00d.rlib" "/tmp/rustciQL7kN/liblibsqlite3_sys-9475ee28e5ab4579.rlib" "/tmp/rustciQL7kN/libblake3-ef784643107dd47f.rlib" "/tmp/rustciQL7kN/libzstd_sys-acd6ebbd21cd3e5e.rlib" "/tmp/rustciQL7kN/libbzip2_sys-4f445bd866f7e974.rlib" "/tmp/rustciQL7kN/libring-cc0553e6e8fbfd1f.rlib" "/tmp/rustciQL7kN/libring-eafc885cac5ad2b1.rlib" "/opt/rust/rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-d700583125da6701.rlib" "-Wl,-Bdynamic" "-lfdb_c" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/opt/rust/rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/app/target/release/deps/stalwart_mail-9eefa014788ab2f6" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-Wl,-O1" "-Wl,--strip-debug" "-nodefaultlibs"
813.2   = note: /usr/lib/gcc/x86_64-linux-gnu/8/../../../../lib/libfdb_c.so: file not recognized: file format not recognized
813.2           collect2: error: ld returned 1 exit status
813.2
813.2
813.3 error: could not compile `mail-server` (bin "stalwart-mail") due to 1 previous error
------
Dockerfile.fdb:45
--------------------
  43 |     COPY resources/ resources/
  44 |     COPY tests/ tests/
  45 | >>> RUN cargo build --manifest-path=crates/main/Cargo.toml --no-default-features --features foundationdb --release
  46 |
  47 |     FROM debian:buster-slim AS runtime
--------------------
ERROR: failed to solve: process "/bin/sh -c cargo build --manifest-path=crates/main/Cargo.toml --no-default-features --features foundationdb --release" did not complete successfully: exit code: 101

How can we reproduce the problem?

I can reproduce the problem by doing the following steps:

Version

v0.7.x

What database are you using?

FoundationDB

What blob storage are you using?

None

Where is your directory located?

None

What operating system are you using?

Docker

Relevant log output

/usr/local/bin/stalwart-mail: error while loading shared libraries: libfdb_c.so: cannot open shared object file: No such file or directory```

Code of Conduct

mdecimus commented 4 months ago

I'm closing this as it is a compilation issue, not a bug. You have modified the Dockerfile and changed the FDB version from 7.1. to 7.3. If you do this you'll also have to modify the crates/store/Cargo.toml file and change:

`foundationdb = { version = "0.9.0", features = ["embedded-fdb-include", "fdb-7_1"], optional = true }

to:

foundationdb = { version = "0.9.0", features = ["embedded-fdb-include", "fdb-7_3"], optional = true }

Also make sure you are using the right client libraries for your platform architecture.

AshanCG commented 4 months ago

The solution was;

Add the foundationDB client library inside runtime image (final image) ;

- in Dockerfile.fdb 
    .....

    FROM debian:buster-slim AS runtime

    COPY --from=builder /app/target/release/stalwart-mail /usr/local/bin/stalwart-mail
    RUN apt-get update -y && apt-get install -yq ca-certificates build-essential curl
    RUN curl -LO https://github.com/apple/foundationdb/releases/download/7.1.0/foundationdb-clients_7.1.0-1_amd64.deb && \
        dpkg -i foundationdb-clients_7.1.0-1_amd64.deb
    ....    

Thank you @mdecimus for the confirmation revert feedback.