redwoodjs / redwood

The App Framework for Startups
https://redwoodjs.com
MIT License
17.13k stars 979 forks source link

[Bug?]: can't prerender using Coherence deploy #8333

Open jtoar opened 1 year ago

jtoar commented 1 year ago

What's not working?

When deploying to Coherence, the web's build string has to be: build: ["yarn", "rw", "build", "web", "--no-prerender"]. We can't prerender because the DATABASE_URL env var isn't supplied to the web's build container. When the web side prerenders, it doesn't actually make a call to the api server over the network. Instead it imports the GraphQL handler directly from the api side and runs it programmatically. This means it needs access to the database for the underlying prisma calls. This also means the build container for the web side can't just contain web-side code—it needs the whole project more or less.

How do we reproduce the bug?

Setup up coherence deploy:

build: ["/bin/bash", "-c", "\"(curl -o /dev/null -s -w \"%{http_code}\" $COHERENCE_ENVIRONMENT_DOMAIN/api/graphql | grep -q \"200\") && ARG=\"\" || ARG=\"--no-prerender\"; yarn rw build web $ARG\""]

What's your environment? (If it applies)

n/a

Are you interested in working on this?

thedavidprice commented 1 year ago

@jtoar I think we can use Docker Multi-stage builds to solve this (for now): https://docs.docker.com/build/building/multi-stage/

With multi-stage builds, you use multiple FROM statements in your Dockerfile. Each FROM instruction can use a different base, and each of them begins a new stage of the build. You can selectively copy artifacts from one stage to another, leaving behind everything you don’t want in the final image.

For the Web Dockerfile, we can start with both API and Web, run through the steps, then remove API.

Note: We need to make API Build, Prisma Migrate, and Data-migrate have completed successfully before Building Web and running prerender.

TBD

karthiksrinivasan commented 1 month ago

Thanks for looking into this issue, any update on this issue? Also does the Coherence deployment(https://docs.redwoodjs.com/docs/deploy/coherence/) support both serverless and serverful deployment?

I see that Coherence has removed their write-up about Redwood-JS setup from their docs https://docs.withcoherence.com/configuration/frameworks/#redwood-js , does it mean it's not supported any more? In general, can you comment on the state of the Coherence deployment support for RWJS?