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

Proper way to cache "prisma generate" command #452

Open
stefanodecillis opened this issue Apr 6, 2024 · 2 comments
Open

Proper way to cache "prisma generate" command #452

stefanodecillis opened this issue Apr 6, 2024 · 2 comments

Comments

@stefanodecillis
Copy link

Trying out prisma-client-rust and I'm currently building a dockerfile.

I'm using Cargo chef to provide a cache layer to avoid compiling dependencies each time and I'm wondering if something similar could be achieved for the command cargo prisma build.

This command should generate the same file if the schema doesn't change (I guess) but it looks like docker is running this command anyway

Does someone encounter this problem and found a solution/workaround?

@Brendonovich
Copy link
Owner

I'm not entirely sure about docker but here's out setup for github actions

@mgrog
Copy link

mgrog commented May 9, 2024

Here's an example Dockerfile that does it, the trick was to create a empty project with the workspace entry in the cargo.toml:

# Leveraging the pre-built Docker images with 
# cargo-chef and the Rust toolchain
FROM lukemathwalker/cargo-chef:latest-rust-1.77.0 AS chef
WORKDIR /app

FROM chef AS prisma-cli
# Build prisma cli
COPY ./prisma-cli ./prisma-cli
RUN cargo init
RUN echo "[workspace]\nmembers = [\"prisma-cli\"]" > Cargo.toml
RUN cargo build --manifest-path prisma-cli/Cargo.toml

FROM prisma-cli as prisma-client-1
COPY prisma/schema.prisma prisma/schema.prisma
COPY .cargo .cargo
RUN cargo prisma generate --schema prisma/schema.prisma

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

FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json
COPY --from=prisma-client-1 /app/src/prisma.rs src/prisma.rs
RUN cargo chef cook --release --recipe-path recipe.json
# Build application
COPY . .
RUN cargo build --release

FROM gcr.io/distroless/cc as runtime
COPY --from=builder /app/target/release/app /usr/local/bin/app
STOPSIGNAL SIGINT
ENTRYPOINT ["./usr/local/bin/app"]

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

3 participants