LukeMathWalker / cargo-chef

A cargo-subcommand to speed up Rust Docker builds using Docker layer caching.
Apache License 2.0
1.72k stars 113 forks source link

error while loading shared libraries: libssl.so.3 #246

Closed azzamsa closed 11 months ago

azzamsa commented 11 months ago

Hi.

My Previous Dockerfile works fine.

ARG VCS_REVISION

FROM docker.io/lukemathwalker/cargo-chef:latest-rust-1.71.0 as chef
WORKDIR app

FROM chef as planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

FROM chef as builder
RUN apt-get update && apt-get install -y pkg-config libssl-dev
COPY --from=planner /app/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json
COPY . .
ARG VCS_REVISION
RUN VCS_REVISION=$VCS_REVISION cargo build --release

FROM gcr.io/distroless/cc-debian11
COPY --from=builder /app/target/release/tin /
CMD ["./tin"]

But changing it to the newest version gives me ./tin: error while loading shared libraries: libssl.so.3: cannot open shared object file: No such file or directory

- FROM docker.io/lukemathwalker/cargo-chef:latest-rust-1.71.0 as chef
+ FROM docker.io/lukemathwalker/cargo-chef:latest-rust-1 as chef. # doesn't work

I have added these lines, but the error persists.

FROM chef as builder
+ RUN apt-get update && apt-get install -y pkg-config libssl-dev
COPY --from=planner /app/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json
COPY . .
ARG VCS_REVISION
RUN VCS_REVISION=$VCS_REVISION cargo build --release

So, where should I add the pkg-config libssl-dev?

Thank you! :1st_place_medal:

Related:

LukeMathWalker commented 11 months ago

That library is dynamically linked, therefore you need to install it in both your build stage and your runtime stage!

azzamsa commented 11 months ago

Worked.

I removed any code that depends on openssl:

# Database
-sqlx = { version = "0.7.1", features = ["runtime-tokio-native-tls", "postgres", "uuid", "chrono", "migrate"] }
+sqlx = { version = "0.7.1", features = ["runtime-tokio-rustls", "postgres", "uuid", "chrono", "migrate"] }

# Logging
tracing = "0.1.37"
ARG VCS_REVISION

-FROM docker.io/lukemathwalker/cargo-chef:latest-rust-1.71.0 as chef
+FROM docker.io/lukemathwalker/cargo-chef:latest-rust-1 as chef
WORKDIR app

FROM chef as planner
@@ -18,6 +18,6 @@ COPY . .
ARG VCS_REVISION
RUN VCS_REVISION=$VCS_REVISION cargo build --release

-FROM gcr.io/distroless/cc-debian11
+FROM gcr.io/distroless/cc-debian12
COPY --from=builder /app/target/release/tin /
CMD ["./tin"]

By the way, I am still curious why changing the Rust version number on cargo-chef image breaks openssl related things?

LukeMathWalker commented 11 months ago

The underlying Linux image has likely changed since we used a newer Rust base image and they stopped bundling the library.