redwoodjs / redwood

The App Framework for Startups

Home Page:https://redwoodjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug?]: Docker compose errors with graphql fragments

ladderschool opened this issue · comments

What's not working?

Deployment via docker compose results in the error below when fragmens = true in the redwood.toml file.

✖ Generating types needed for GraphQL Fragments support... [FAILED: The "path" argument must be of type string or an instance of Buffer or URL. Received null]
Here's your unique error reference to quote: 'a6e96fa4-d529-43a5-bc74-457412b5d6c4'

Full log:

[COMMAND] docker exec iw80gow bash -c 'SOURCE_COMMIT=68e775fedee4361a0e4fa90b5399a7e5ea086ad3 COOLIFY_BRANCH=main docker compose --env-file /artifacts/iw80gow/.env --project-directory /artifacts/iw80gow -f /artifacts/iw80gow/docker-compose.prod.yml build'
[OUTPUT]
#27 16.53 ✔ Generating Prisma Client...

[2024-Jun-22 05:36:31.989786]

[COMMAND] docker exec iw80gow bash -c 'SOURCE_COMMIT=68e775fedee4361a0e4fa90b5399a7e5ea086ad3 COOLIFY_BRANCH=main docker compose --env-file /artifacts/iw80gow/.env --project-directory /artifacts/iw80gow -f /artifacts/iw80gow/docker-compose.prod.yml build'
[OUTPUT]
#27 16.53 ❯ Generating types needed for GraphQL Fragments support...

[2024-Jun-22 05:36:50.766355]

[COMMAND] docker exec iw80gow bash -c 'SOURCE_COMMIT=68e775fedee4361a0e4fa90b5399a7e5ea086ad3 COOLIFY_BRANCH=main docker compose --env-file /artifacts/iw80gow/.env --project-directory /artifacts/iw80gow -f /artifacts/iw80gow/docker-compose.prod.yml build'
[OUTPUT]
#27 35.45 ✖ Generating types needed for GraphQL Fragments support... [FAILED: The "path" argument must be of type string or an instance of Buffer or URL. Received null]

[2024-Jun-22 05:36:50.920126]

[COMMAND] docker exec iw80gow bash -c 'SOURCE_COMMIT=68e775fedee4361a0e4fa90b5399a7e5ea086ad3 COOLIFY_BRANCH=main docker compose --env-file /artifacts/iw80gow/.env --project-directory /artifacts/iw80gow -f /artifacts/iw80gow/docker-compose.prod.yml build'
[OUTPUT]
#27 35.46 �[?25hTypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received null
#27 35.46 at Object.readFileSync (node:fs:446:42)
#27 35.46 at fileToAst (/app/node_modules/@redwoodjs/internal/dist/ast.js:22:28)
#27 35.46 at generateTypeDefRouterRoutes (/app/node_modules/@redwoodjs/internal/dist/generate/typeDefinitions.js:202:34)
#27 35.46 at generateTypeDefs (/app/node_modules/@redwoodjs/internal/dist/generate/typeDefinitions.js:61:157)
#27 35.46 at async generate (/app/node_modules/@redwoodjs/internal/dist/generate/generate.js:27:7)
#27 35.46 at async _Task.task [as taskFn] (/app/node_modules/@redwoodjs/cli/dist/commands/buildHandler.js:109:9)
#27 35.46 at async _Task.run (/app/node_modules/listr2/dist/index.cjs:2049:11)
#27 35.46
#27 35.46
#27 35.46 Need help?
#27 35.46 - Not sure about something or need advice? Reach out on our Forum (​[https://community.redwoodjs.com/​)](https://community.redwoodjs.com/%E2%80%8B))
#27 35.46 - Think you've found a bug? Open an issue on our GitHub (​[https://github.com/redwoodjs/redwood​)](https://github.com/redwoodjs/redwood%E2%80%8B))
#27 35.46 - Here's your unique error reference to quote: 'a6e96fa4-d529-43a5-bc74-457412b5d6c4'
[2024-Jun-22 05:36:51.043761]

[COMMAND] docker exec iw80gow bash -c 'SOURCE_COMMIT=68e775fedee4361a0e4fa90b5399a7e5ea086ad3 COOLIFY_BRANCH=main docker compose --env-file /artifacts/iw80gow/.env --project-directory /artifacts/iw80gow -f /artifacts/iw80gow/docker-compose.prod.yml build'
[OUTPUT]
#27 ERROR: process "/bin/sh -c yarn rw build api" did not complete successfully: exit code: 1

[2024-Jun-22 05:36:51.091941]

[COMMAND] docker exec iw80gow bash -c 'SOURCE_COMMIT=68e775fedee4361a0e4fa90b5399a7e5ea086ad3 COOLIFY_BRANCH=main docker compose --env-file /artifacts/iw80gow/.env --project-directory /artifacts/iw80gow -f /artifacts/iw80gow/docker-compose.prod.yml build'
[OUTPUT]
------
> [api api_build 2/2] RUN yarn rw build api:
35.46 at generateTypeDefs (/app/node_modules/@redwoodjs/internal/dist/generate/typeDefinitions.js:61:157)
35.46 at async generate (/app/node_modules/@redwoodjs/internal/dist/generate/generate.js:27:7)
35.46 at async _Task.task [as taskFn] (/app/node_modules/@redwoodjs/cli/dist/commands/buildHandler.js:109:9)
35.46 at async _Task.run (/app/node_modules/listr2/dist/index.cjs:2049:11)
35.46
35.46
35.46 Need help?
35.46 - Not sure about something or need advice? Reach out on our Forum (​[https://community.redwoodjs.com/​)](https://community.redwoodjs.com/%E2%80%8B))
35.46 - Think you've found a bug? Open an issue on our GitHub (​[https://github.com/redwoodjs/redwood​)](https://github.com/redwoodjs/redwood%E2%80%8B))
35.46 - Here's your unique error reference to quote: 'a6e96fa4-d529-43a5-bc74-457412b5d6c4'
------

How do we reproduce the bug?

Follow my guide to set up a Coolify server and deploy Redwood. Make sure fragments are enabled.

https://community.redwoodjs.com/t/self-hosted-with-coolify/7245

What's your environment? (If it applies)

System: 
  Docker engine: 24+
  OS: 20.x debian bookworm in docker
  Shell: 
Binaries:
  Node: v20.14.0
  Yarn: 4.3.0
Redwood:
  Version 7.7.1

Are you interested in working on this?

  • I'm interested in working on this

Hi @ladderschool thanks for reporting. Have you been able to reproduce with a minimal docker setup?

Having a repo that I can clone and reproduce this issue would be amazingly helpful.

Btw do you see or have a GraphQL directory? Perhaps the path is failing when generating possible types?

const filename = path.join(getPaths().web.graphql, 'possibleTypes.ts')

Btw do you see or have a GraphQL directory? Perhaps the path is failing when generating possible types?

Contents of my deployed web container:

graphql.config.js
web/dist ->
200.html
assets
build-manifest.json
fonts
index.html

I don't see any fragments, you're right there's no graphql folder! There should be a graphql folder since I see it in my local development under /web right? Funnily enough the Dockerfile is missing that copy, but the app works anyway--I haven't removed my fragments in the web side queries and they still resolve.

The graphql.config.js looks like this (I don't need this in production, do I?):

// This file is used by the VSCode GraphQL extension <---- aha!

const { getPaths } = require('@redwoodjs/project-config')

/** @type {import('graphql-config').IGraphQLConfig} */
const config = {
  schema: getPaths().generated.schema,
  documents: './web/src/fragments/*.ts',
}

module.exports = config

I'll set up a repo tomorrow and link it here but I'll experiment with the Dockerfile tonight 👍

Do I specify the graphql folder here? I thought the first copy copies the whole web folder, which would include graphql, no?


# web build
# ---------
FROM base as web_build

COPY --chown=node:node web web
+COPY --chown=node:node web/graphql web/graphql
RUN yarn rw build web --no-prerender

# web serve
# ---------
FROM node:20-bookworm-slim as web_serve

RUN corepack enable

USER node
WORKDIR /app

COPY --chown=node:node .yarnrc.yml .
COPY --chown=node:node package.json .
COPY --chown=node:node web/package.json web/
COPY --chown=node:node yarn.lock .

RUN mkdir -p /app/.yarn/berry/index
RUN mkdir -p /app/.cache

RUN --mount=type=cache,target=/app/.yarn/berry/cache,uid=1000 \
    --mount=type=cache,target=/app/.cache,uid=1000 \
    CI=1 yarn workspaces focus web --production

COPY --chown=node:node redwood.toml .
COPY --chown=node:node graphql.config.js .

COPY --chown=node:node --from=web_build /app/web/dist /app/web/dist

ENV NODE_ENV=production \
    API_PROXY_TARGET=http://api.app.name:8911

CMD "node_modules/.bin/rw-web-server" "--api-proxy-target" "$API_PROXY_TARGET"

Here's the repo where you can try to deploy it, I just tried it on Coolify and it gave me the same error. Notice when you switch fragments = no in the redwood.toml it works and even the fragments themselves still work!

https://github.com/ladderschool/fragments-deploy-docker

Here's the repo where you can try to deploy it, I just tried it on Coolify and it gave me the same error. Notice when you switch fragments = no in the redwood.toml it works and even the fragments themselves still work!

https://github.com/ladderschool/fragments-deploy-docker

Am trying out this repo locally right now.

May I ask why your Docker setup doesn't follow these instructions? https://docs.redwoodjs.com/docs/docker

FYi with the repo and docker compose -f ./docker-compose.yaml up I do see

 => ERROR [api api_build 3/3] RUN yarn rw build api                        6.9s
------
 > [api api_build 3/3] RUN yarn rw build api:
2.662 ❯ Generating Prisma Client...
3.440 ✔ Generating Prisma Client...
3.440 ❯ Generating types needed for GraphQL Fragments support...
6.823 ✖ Generating types needed for GraphQL Fragments support... [FAILED: The "path" argument must be of type string or an instance of Buffer or URL. Received null]

So reproduces at moment.

OK, thanks to some help from @Josh-Walker-GM we found the problem and have a fix:

# api build
# ---------
FROM base as api_build

COPY --chown=node:node api api
COPY --chown=node:node web web
COPY --chown=node:node scripts ./scripts/
RUN yarn rw build api

# web prerender build
# -------------------
FROM api_build as web_build_with_prerender

COPY --chown=node:node api api
COPY --chown=node:node web web
RUN yarn rw build web

# web build
# ---------
FROM base as web_build

COPY --chown=node:node api api
COPY --chown=node:node web web
RUN yarn rw build web --no-prerender

In short, for each of the build steps you need to copy over both the api and web in Dockerfile because in the fragments case the codegen relies on some file paths for both web and api.

We'll think about either documenting this or changing the template, but if you add those copy steps it should succeed:

 => [web web_serve 10/13] RUN --mount=type=cache,target=/app/.yarn/berry/cache,uid=1000     --mount=type=cache,target=/app/.cache,uid=1000     CI=1 yarn workspaces focus web --production          4.9s
 => [web web_build 2/3] COPY --chown=node:node web web                                                                                                                                              0.0s
 => [web web_build 3/3] RUN yarn rw build web --no-prerender                                                                                                                                       11.2s
 => [web web_serve 11/13] COPY --chown=node:node redwood.toml .                                                                                                                                     0.0s
 => [web web_serve 12/13] COPY --chown=node:node graphql.config.js .                                                                                                                                0.0s 
 => [web web_serve 13/13] COPY --chown=node:node --from=web_build /app/web/dist /app/web/dist                                                                                                       0.0s 
 => [web] exporting to image                                                                                                                                                                        0.5s 
 => => exporting layers                                                                                                                                                                             0.5s
 => => writing image sha256:e510e4ece9d3a28dcd4c48f6557bffb13619690763e2289094a7a198e70e1b8b                                                                                                        0.0s
 => => naming to docker.io/library/fragments-deploy-docker-web                                                                                                                                      0.0s
Error response from daemon: network coolify not found

I don't have the coolify up.

Let us know if this solves the issue and how your cooly experience is!

Btw - thanks so much for taking the time to make the repo that we could use to reproduce. Once we had that and Josh and I could look, it was pretty quick to identify. Without it we would have been scrambling.

Here's the repo where you can try to deploy it, I just tried it on Coolify and it gave me the same error. Notice when you switch fragments = no in the redwood.toml it works and even the fragments themselves still work!
https://github.com/ladderschool/fragments-deploy-docker

Am trying out this repo locally right now.

May I ask why your Docker setup doesn't follow these instructions? https://docs.redwoodjs.com/docs/docker

I tried using the original Dockerfile, sadly it did not work on Coolify. Primarily the issue was how paths for the container environment were copied, hence why I had to add /app to most things. If you look at the docker-compose I had to make a few changes there too, but I'm glad it's deploying properly now. The fix to add api and web copies to both builds works for me. I can confirm that seems to have fixed it.

#34 68.84 ✔ Generating types needed for GraphQL Fragments support...

#61 79.37 ✔ Generating types needed for GraphQL Fragments support...

# -> For both api and web build!

Let us know if this solves the issue and how your cooly experience is!

It's pretty nice, honestly. The UI saves me a lot of time tooling on a baremetal myself and it has a lot of goodies; I can just spin up a minIO S3 storage and implement replication/backups easily even with remote servers. Many other services work just out of the box (postgres, redis,..). Having SSL just work out of the box was also a huge boon. If anything I'd say the network configuration is a bit lacking/buggy in the UI and you have to ssh and command line everything when it comes to that (See my problems in the get help thread on the forums). The biggest discovery I've had is that I can run prisma studio and redis over the internet behind a firewall with an ip whitelist to just allow me to access those resources. Build times are as low as 30-50s as well, sometimes 10-20s for smaller commits.

The app works really well though, I've seen a nice jump in responsiveness since I'm not communicating database queries over the internet anymore. Looking forward to testing Trusted Docs. Thank you for being so amazing and for everything the team does. 💪 🚀

The fix to add api and web copies to both builds works for me. I can confirm that seems to have fixed it.

Excellent. And thanks much for the thoughts on Coolify. The team is always looking for more and easier ways to deploy and with upcoming RSC releases, having a several deploy is going to be needed.

The biggest discovery I've had is that I can run prisma studio and redis over the internet behind a firewall with an ip whitelist to just allow me to access those resources.

That is nice. Having Redis available also makes using GraphQL response caching and Realtime much more powerful.

Looking forward to testing Trusted Docs.

Great. Just be sure to update your app when the next release comes as there is a fix for TD with Auth here that's recently been merged: #10817

Thank you for being so amazing and for everything the team does. 💪 🚀

Welcome! Please do let us know anything we can do to help.