Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prisma generate panics when building docker image on alpine base #466

Open
StoicDeveloper opened this issue Aug 16, 2024 · 2 comments
Open

Comments

@StoicDeveloper
Copy link

StoicDeveloper commented Aug 16, 2024

When attempting to generate prisma.rs while building an alpine-based image, the binary panics with an OS "No such file or directory" error, which occurs on the prisma_cli.rs cmd.output().unwrap() call, as detailed in the stack trace below.

The build works fine when using a debian base image, but I wanted to use alpine since the resulting image size is 10x larger with debian.

Here is the relevant dockerfile stage:

FROM rust:alpine AS builder-alpine
RUN rustup default nightly
RUN apk add --update musl-dev libressl-dev
WORKDIR /app
COPY ./src-server .
RUN RUST_BACKTRACE=1 cargo prisma generate
RUN cargo build --release

The build output indicating the failing line:

------                                         
Dockerfile:28                                  
--------------------                           
  26 |     WORKDIR /app
  27 |     COPY ./src-server .
  28 | >>> RUN RUST_BACKTRACE=1 cargo prisma generate                                          
  29 |     RUN cargo build --release 
  30 |     # RUN apk add bash curl
--------------------                           
ERROR: failed to solve: process "/bin/sh -c RUST_BACKTRACE=1 cargo prisma generate" did not complete successfully: exit code: 101

@StoicDeveloper
Copy link
Author

Build output including stack trace:

602.7     Finished `dev` profile [unoptimized + debuginfo] target(s) in 10m 01s                                                                                                               
603.4      Running `/target/debug/prisma generate`                                                                                                                                            
603.4 Downloading https://prisma-photongo.s3-eu-west-1.amazonaws.com/prisma-cli-4.8.0-linux-x64.gz to /root/.cache/prisma/binaries/cli/4.8.0/prisma-cli-linux-x64                             
736.9 Downloading https://binaries.prisma.sh/all_commits/d6e67a83f971b175a593ccc12e15c4a757f93ffe/linux-musl/query-engine.gz to /root/.cache/prisma/binaries/cli/4.8.0/d6e67a83f971b175a593ccc
12e15c4a757f93ffe/prisma-query-engine-linux-musl                                                                                                                                              
738.6 Downloading https://binaries.prisma.sh/all_commits/d6e67a83f971b175a593ccc12e15c4a757f93ffe/linux-musl/migration-engine.gz to /root/.cache/prisma/binaries/cli/4.8.0/d6e67a83f971b175a59
3ccc12e15c4a757f93ffe/prisma-migration-engine-linux-musl                                                                                                                                      
740.1 Downloading https://binaries.prisma.sh/all_commits/d6e67a83f971b175a593ccc12e15c4a757f93ffe/linux-musl/introspection-engine.gz to /root/.cache/prisma/binaries/cli/4.8.0/d6e67a83f971b17
5a593ccc12e15c4a757f93ffe/prisma-introspection-engine-linux-musl                                                                                                                              
741.9 Downloading https://binaries.prisma.sh/all_commits/d6e67a83f971b175a593ccc12e15c4a757f93ffe/linux-musl/prisma-fmt.gz to /root/.cache/prisma/binaries/cli/4.8.0/d6e67a83f971b175a593ccc12
e15c4a757f93ffe/prisma-prisma-fmt-linux-musl                                                                                                                                                  
742.5 thread 'main' panicked at /cargo/git/checkouts/prisma-client-rust-fa967aa5ad0ec391/3ac68d0/cli/src/prisma_cli.rs:40:18:                                                                 
742.5 called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }                                                                       
742.5 stack backtrace:                                                                                                                                                                        
743.0    0: rust_begin_unwind                                                                                                                                                                 
743.0              at /rustc/13a52890dde8cfeb95069d77c223ac37c0cf3a46/library/std/src/panicking.rs:662:5                                                                                      
743.0    1: core::panicking::panic_fmt                                                                                                                                                        
743.0              at /rustc/13a52890dde8cfeb95069d77c223ac37c0cf3a46/library/core/src/panicking.rs:74:14                                                                                     
743.0    2: core::result::unwrap_failed                                                                                                                                                       
743.0              at /rustc/13a52890dde8cfeb95069d77c223ac37c0cf3a46/library/core/src/result.rs:1679:5
743.0    3: core::result::Result<T,E>::unwrap
743.0              at /rustc/13a52890dde8cfeb95069d77c223ac37c0cf3a46/library/core/src/result.rs:1102:23
743.0    4: prisma_client_rust_cli::prisma_cli::main                                           
743.0              at /cargo/git/checkouts/prisma-client-rust-fa967aa5ad0ec391/3ac68d0/cli/src/prisma_cli.rs:40:5
743.0    5: prisma_client_rust_cli::run
743.0              at /cargo/git/checkouts/prisma-client-rust-fa967aa5ad0ec391/3ac68d0/cli/src/lib.rs:16:9
743.0    6: prisma::main
743.0              at ./src/bin/prisma.rs:2:5
743.0    7: core::ops::function::FnOnce::call_once                                             
743.0              at /rustc/13a52890dde8cfeb95069d77c223ac37c0cf3a46/library/core/src/ops/function.rs:250:5
743.0 note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.  

@delsehi
Copy link

delsehi commented Aug 23, 2024

I've also played around with alpine containerfiles.

Containerfile

ARG RUST_VERSION=1.80.1
ARG APP_NAME=my_app
FROM rust:${RUST_VERSION}-alpine AS build
ARG APP_NAME
WORKDIR /app
RUN apk update && \
    apk add openssl musl-dev openssl-dev pkgconf && \
    cargo install cargo-chef
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
RUN cargo chef cook --release --recipe-path recipe.json
RUN cargo prisma generate && cargo build --locked --release 

FROM alpine:latest AS final 

RUN apk update && apk upgrade openssl
COPY --from=build "/app/target/release/my_app" /usr/local/bin
EXPOSE 3000
ENTRYPOINT ["/usr/local/bin/my_app"]

Cargo.toml

[package]
name = "my_app"
version = "0.1.0"
edition = "2021"

[dependencies]
anyhow = "1.0.86"
askama = { version = "0.12.1", features = ["with-axum"] }
askama_axum = "0.4.0"
axum = "0.7.5"
axum-extra = { version = "0.9.3", features = ["cookie-private"] }   
dotenvy = "0.15.7"
openidconnect = "3.5.0"
reqwest = { version = "0.12.5", features = ["json"] }
serde = { version = "1.0.206", features = ["derive"] }
serde_json = "1.0.124"
tokio = { version = "1.39.2", features = ["full"] }
tower = "0.4.13"
tower-http = { version = "0.5.2", features = ["fs", "trace"] }
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
prisma-client-rust = { git = "https://github.com/Brendonovich/prisma-client-rust", tag = "0.6.11", default-features = false, features = [
    "mssql",
] }

[workspace]

members = ["prisma-cli"]

resolver = "2"

My container won't run but it builds, so hopefully it helps you past that at least? 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants