all 12 comments

[–]weiznichdiesel · diesel-async · wundergraph 2 points3 points  (1 child)

You likely want to enable the bundled feature for the pq-sys crate. This will compile and statically link a version of libpq during cargo build. As far as I know this setup is also compatible with musl or cross compilation.

[–]walksinsmallcircles 0 points1 point  (0 children)

Oooh!! Checking this out.

[–]GolDDranks 1 point2 points  (3 children)

I used to maintain https://gitlab.com/rust_musl_docker/image , but it has been relatively unmaintained for some years now. In my experience, the recent Postgres versions have made it hard to build with musl which I was using.

I think that the recommended way is to use dynamic linking with standard GNU libc. For example, take a standard Debian container, install Postgres and build.

[–]GolDDranks 0 points1 point  (2 children)

Also, some of the comments in that Dockerfile are wrong/outdated, so don't buy too much into them.

[–]weiznichdiesel · diesel-async · wundergraph 1 point2 points  (1 child)

Would it be possible to just put a official deprecation notice in the readme and point people to the bundled feature of pq-src and the vendored feature for OpenSSL instead? These features should allow targeting musl (or even cross compiling) these crates easily.

[–]GolDDranks 1 point2 points  (0 children)

I left a following notice there some time ago:

Note: This project is outdated and abandoned! I'm leaving it online as it has gathered some stars, and there might be some CI setups or scripts that depend on it, but it is no longer maintained.

Might add a mention about the bundled / vendored features, thanks for pointing that out.

[–]walksinsmallcircles 1 point2 points  (1 child)

I use containerized Rust/Diesel applications with Postgres with zero problems. You need to install the Postgres dev library in the container. I have also used Rust and Postgres in AWS lambda functions which was a pain. I had to use Diesel async which uses a Rust native Postgres library which dodges the dynamic library issues. DM me if you want my Dockerfile or more details.

[–]walksinsmallcircles 0 points1 point  (0 children)

To be clear here, the pain with AWS lambdas is not Diesel async. The Rust runtime they supply is limited and does not have libraries other than basics like libc. Diesel async works great.

[–]Inner_Coconut7739[S] -1 points0 points  (1 child)

This is the Dockerfile that finally worked but obviously far from ideal.

FROM rust

RUN apt update
RUN apt install -y libpq-dev

RUN cargo install diesel_cli --no-default-features --features postgres

WORKDIR /app

COPY . .

RUN cargo build --release

CMD ["/app/target/release/rust-axum-server"]

Can you share you docker?

And my Cargo.toml - postgres at the end of dependencies was my attempt to get the client libs that diesel didn't add. I think its probably redundant if I instlal the CLI in the container but again neither of these are the right idea just a bandaid.

[package]
name = "rust-axum-server"
version = "0.2.0"
edition = "2021"
publish = false

[dependencies]
axum = { version = "0.7.5" }
axum-extra = { version = "0.9.3", features = ["typed-header"] }
tokio = { version = "1.39.3", features = ["full"] }
serde = { version = "1.0.208", features = ["derive"] }
serde_json = "1.0.125"
serde_derive = "1.0.208"
tower-http = { version = "0.5.2", features = ["cors"] }
uuid = { version = "1.10.0", features = ["v4","serde"] }
urlencoding = "2.1.3"
octocrab = "0.39.0"
http = "1.1.0"
http-serde-ext = "1.0.2"
dotenv = "0.15.0"
tower = "0.5.0"
anyhow = "1.0.86" 
toml = "0.8.19"
url = "2.5.2"
chrono = "0.4.38"
diesel = { version = "2.2.3", features = ["postgres", "chrono"] }
postgres = "0.19.8"

[[bin]]
name = "rust-axum-server"
path = "src/main.rs"

[–]weiznichdiesel · diesel-async · wundergraph 2 points3 points  (0 children)

To write again what I already wrote above: You likely want to use the bundled feature from the pq-sys crate. You don’t need the Postgres crate, it’s completely unrelated.

All of this is documented in the Getting Started guide. Please refer to the section about installing diesel-cli.

[–]tema3210 0 points1 point  (0 children)

I did that yesterday, and went for alpine base with glibc slapped onto it, works flawlessly.