yoga2 icon indicating copy to clipboard operation
yoga2 copied to clipboard

Help: Zeit Now V2 Deployment

Open williamluke4 opened this issue 5 years ago • 27 comments

Does anyone have experence deploying Yoga 2 to Now V2. I have been trying on and off for a week now with no avail. Below is my now.json

{
  "name": "api.domain.com",
  "alias": ["api.domain.com"],
  "version": 2,
  "builds": [{ "src": "dist/src/index.js", "use": "@now/node-server" }],
  "routes": [
    { "src": "/.*", "dest": "dist/src/index.js"}
  ]
}

williamluke4 avatar Apr 11 '19 10:04 williamluke4

I've been working for about two weeks on deploying to Now v2 also.

I've now gotten a Now customer service employee helping me figure out why the deployment isn't working correctly.

So far, the issues seems to be with NCC and on Now's side. However, they are looking at one more deployment of a yoga2 server that did work.

I might know more today; I'll keep this comment updated as I learn more.

DevanB avatar Apr 11 '19 12:04 DevanB

Ok awesome, this has been driving me nuts!!

I am looking in to implementing apollo-server-lambda in to yoga2, do you think that this would be worth while?

williamluke4 avatar Apr 11 '19 13:04 williamluke4

Hey 👋,

Could you please provide a bit more context? We have deployed a yoga2 server recently using the very same now.json file as you do and had no issue doing so

Weakky avatar Apr 11 '19 17:04 Weakky

I've been trying to deploy this project. However, an employee at Zeit tells me it keeps erring out due to NCC not working correctly.

DevanB avatar Apr 11 '19 18:04 DevanB

Hey @DevanB, Have you heard back from Zeit?

williamluke4 avatar Apr 13 '19 08:04 williamluke4

Nope no response. I know another developer I was talking to deployed a yoga2 server with no luck also.

@weakky - I deployed your Prisma e-commerce branch and it deployed, but doesn’t work correctly. For instance, you can’t hit the playground and seems you can’t make any requests into it.

DevanB avatar Apr 13 '19 13:04 DevanB

Hey @DevanB, what output do you get when running now dev bear in mind that this only work on mac and linux atm. If you are on windows you can use wsl

williamluke4 avatar Apr 15 '19 14:04 williamluke4

@williamluke4 I actually got it working with node dev last night. But still no luck deploying

DevanB avatar Apr 15 '19 14:04 DevanB

Running now dev should give you a better idea of why it is not working when deployed. Just want to check to see if it is the same error that I am receiving

williamluke4 avatar Apr 15 '19 14:04 williamluke4

Yep, except for running now dev works, but deploying fails with no errors.

On Apr 15, 2019, at 10:48 AM, William Luke [email protected] wrote:

Running now dev should give you a better idea of why it is not working when deployed. Just want to check to see if it is the same error that I am receiving

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/prisma/yoga2/issues/130#issuecomment-483283532, or mute the thread https://github.com/notifications/unsubscribe-auth/AAVpXM6UMrMiiy_q70b28vPPZKFZo6a4ks5vhJFLgaJpZM4cpQCk.

DevanB avatar Apr 15 '19 14:04 DevanB

Have you tried accessing the playground after running it

williamluke4 avatar Apr 15 '19 14:04 williamluke4

That is very weird as now dev uses ncc

williamluke4 avatar Apr 15 '19 15:04 williamluke4

There are two things to take into consideration here:

  • The playground is disabled by default by apollo-server when NODE_ENV=production
  • Introspection queries are also disabled when NODE_ENV=production

One workaround for now is to eject and set playground: true in the apollo-server instantiation.

Regarding the ncc error, there's nothing I can do without any logging. Someone recently reached to me to deploy yoga to now2 and succeeded without issue (once he knew he had to manually force playground: true)

Weakky avatar Apr 15 '19 15:04 Weakky

@Weakky, Correct... I have tried with both introspection enabled and disabled; The same for the playground

williamluke4 avatar Apr 15 '19 15:04 williamluke4

Here are the logs

will@DESKTOP-4LJJ71K:/mnt/c/Users/willi/Documents/Atto-Byte/Development/api-server$ now dev
 > No existing credentials found. Please log in:
We sent an email to [email protected]. Please follow the steps provided
inside it and make sure the security code matches Famous Dragon.
✔ Email confirmed
Ready! Authentication token and personal details saved in "~/.now"
will@DESKTOP-4LJJ71K:/mnt/c/Users/willi/Documents/Atto-Byte/Development/api-server$ now dev
Running initial builds
downloading user files...
installing dependencies for user's code...
installing to /tmp/co.zeit.now/dev/workPaths/rrlku858/user/dist/src
 > [email protected] postinstall /tmp/co.zeit.now/dev/workPaths/rrlku858/user/node\_modules/protobufjs
node scripts/postinstall
npm WARN [email protected] No description
npm WARN [email protected] No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node\_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
added 1029 packages from 704 contributors in 134.974s
writing ncc package.json...
installing dependencies for ncc...
installing to /tmp/co.zeit.now/dev/workPaths/rrlku858/ncc
yarn install v1.10.1
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
warning Your current version of Yarn is out of date. The latest version is "1.15.2", while you're on "1.10.1".
info To upgrade, run the following command:
$ curl --compressed -o- -L https://yarnpkg.com/install.sh | bash
Done in 11.51s.
running user script...
preparing lambda files...
compiling entrypoint with ncc...
ncc: Version 0.17.3
ncc: Compiling file index.js
ncc: Module directory "/tmp/co.zeit.now/dev/workPaths/rrlku858/user/node\_modules/ws/lib" attempted to require "bufferutil" but could not be resolved, assuming external.
ncc: Module directory "/tmp/co.zeit.now/dev/workPaths/rrlku858/user/node\_modules/ws/lib" attempted to require "utf-8-validate" but could not be resolved, assuming external.
ncc: Module directory "/tmp/co.zeit.now/dev/workPaths/rrlku858/user/node\_modules/subscriptions-transport-ws/node\_modules/ws/lib" attempted to require "utf-8-validate" but could not be resolved, assuming external.
ncc: Module directory "/tmp/co.zeit.now/dev/workPaths/rrlku858/user/node\_modules/subscriptions-transport-ws/node\_modules/ws/lib" attempted to require "bufferutil" but could not be resolved, assuming external.
downloading user files...
installing dependencies for user's code...
installing to /tmp/co.zeit.now/dev/workPaths/pemcn11o/user/dist/src
 > Success! Initial builds completey-parser: sill tarball trying [email protected] by hash: sha512-bn71H9+qWoOQKyZDo25mOMVpSmXROAsTJVVVYzrrtol3d4y+AsKjf4Iwl2Q+IuT0kFSQ1qo166UuIwqYq7mGnA==
Ready! Development server running at http://localhost:3000
 > [email protected] postinstall /tmp/co.zeit.now/dev/workPaths/pemcn11o/user/node\_modules/protobufjs
node scripts/postinstall
npm WARN [email protected] No description
npm WARN [email protected] No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node\_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
added 1029 packages from 704 contributors in 146.816s
writing ncc package.json...
installing dependencies for ncc...
installing to /tmp/co.zeit.now/dev/workPaths/pemcn11o/ncc
yarn install v1.10.1
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
Done in 1.21s.
 > GET /
GraphQL Nexus: Unable to find file or module /tmp/zeit-fun-50baea9e77c81/user/dist/src/context.ts, skipping
GraphQL Nexus: Unable to find file or module /tmp/zeit-fun-50baea9e77c81/user/dist/.yoga/prisma-client/index.ts, skipping
Missing required typegen import: ctx
POST /
Error: Body exceeded 1mb limit
at f (/snapshot/repo/dist/index.js:1:2075329)
at module.exports.7487.t.buffer.Promise.resolve.then.a.then.catch.e (/snapshot/repo/dist/index.js:1:2076888)
at process.\_tickCallback (internal/process/next\_tick.js:68:7)
Error: Unexpected /invocation/response response: {"statusCode":413,"headers":{"content-length":"23","date":"Mon, 15 Apr 2019 12:53:35 GMT","connection":"close"},"body":"Body exceeded 1mb limit"}
at /home/will/src/runtimes/nodejs/bootstrap.ts:155:9
at Generator.next (<anonymous>)
at fulfilled (/home/will/.cache/co.zeit.fun/runtimes/nodejs/bootstrap.js:4:58)
at <anonymous>
at process.\_tickCallback (internal/process/next\_tick.js:188:7)
LambdaError: RequestId: 3f2afa08-8744-44d8-9b13-7e15a576dcee Process exited before completing request
at Lambda.<anonymous> (/snapshot/repo/dist/index.js:1:1987524)
at Generator.next (<anonymous>)
at fulfilled (/snapshot/repo/dist/index.js:1:1985705)
at process.\_tickCallback (internal/process/next\_tick.js:68:7)

williamluke4 avatar Apr 15 '19 15:04 williamluke4

Error: Body exceeded 1mb limit

Isn't your issue related to that? https://github.com/zeit/now-cli/issues/1127

Weakky avatar Apr 15 '19 15:04 Weakky

Yes but this is the error when run locally when deployed the error seems to be different. The Introspection and Playground works when deployed but queries return Only absolute URLs are supported

williamluke4 avatar Apr 15 '19 15:04 williamluke4

Not exactly relevant here but because Zeit is moving to serverless with V2 and doesn't exactly fit the GraphQL model right now, I'm going to try moving to Google Cloud Run which is a Serverless Docker offering. A lot like the serverless docker offering that Zeit offered at one point. It might be easier to deploy a Yoga 2 server on there.

swolidity avatar Apr 24 '19 17:04 swolidity

@andyk91 Could you let me know how you get on :)

williamluke4 avatar Apr 25 '19 07:04 williamluke4

Now + GraphQL are headed in opposite directions and that's ok.

Heroku is a good option for deploying yoga2.

notrab avatar Apr 25 '19 17:04 notrab

Now + GraphQL are headed in opposite directions and that's ok.

Heroku is a good option for deploying yoga2.

That's not true, why are they heading opposite directions? There is an open issue https://github.com/prisma/yoga2/issues/14 and the plan is to build yoga with ncc, which makes the whole thing serverless.

nezdemkovski avatar Apr 25 '19 20:04 nezdemkovski

@yakovlevyuri I don't get the whole serverless push and then all these monolithic GraphQL servers dotted around. If they can make my resolvers lambdas that would be a great paradigm shift, until then, how's Heroku any different to using @now/node-server?

notrab avatar Apr 25 '19 20:04 notrab

To each their own, and this isn't an issue to discuss who prefers what. This issue is titled "Help: Zeit Now V2 Deployment", not "Let's Discuss Open-endedly About the Future of GraphQL, Serverless, Hosting, and What Provider We Prefer".

In fact, there a more relevant issue for that discussion over at #14. @williamluke4 and I are on a mission to help the Zeit team, and future yoga2 users deploy to Zeit v2. So no need to muck up this issue with your opinions on non-relevant topics.

DevanB avatar Apr 25 '19 21:04 DevanB

Hey @DevanB Hold your horses. I've spent the last quarter migrating from Now 1 to 2 and worked with the Zeit team to resolve issues in this space, and for some things (Subscriptions ws) on Now 2 just isn't the right fit. So my experience here kind of tells me Now 2 won't do everything people want moving from 1 to 2 but I certainly didn't mean to say it's not possible! Good luck on your mission! You'll be thanked by many.

notrab avatar Apr 26 '19 09:04 notrab

@DevanB not sure if you figured out how to get it working or not but I believe I did and will post here in case anyone else is looking for help.

You can test the api running on now with the following CURL request:

curl \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{ "query": "{ hello(name: \"Andy\") }" }' \
  https://profile-api.andykay.now.sh

You can also see my setup here: https://github.com/andyk91/profile.im . Yoga2 is in /api.

I might not leave yoga2 in my project though so I think the main two pieces are my now.json file:

{
  "version": 2,
  "name": "profile-api",
  "builds": [
    {
      "src": "dist/src/index.js",
      "use": "@now/node-server",
      "config": {
        "maxLambdaSize": "50mb"
      }
    }
  ],
  "routes": [{ "src": "/.*", "dest": "dist/src/index.js" }]
}

and my .nowignore file:

*
!package.json
!dist
!dist/**

swolidity avatar May 15 '19 13:05 swolidity

I made another repo dedicated to this issue plus a www folder with nextjs + typescript + apollo here: https://github.com/andyk91/yoga2-serverless

swolidity avatar May 17 '19 15:05 swolidity

I was able to get my server to deploy by adding introspection: true to the ApolloServer options.

Also, for what it's worth I had to do the same when I created a raw Apollo Server (not using yoga2)

DevanB avatar May 18 '19 01:05 DevanB