Graphcool / graphcool-framework

Apache License 2.0
1.77k stars 131 forks source link

cli: Bundler includes .build directory and requires itself in build.zip #452

Open marktani opened 6 years ago

marktani commented 6 years ago

Issue by serratus Sunday Jan 07, 2018 at 20:17 GMT Originally opened as https://github.com/graphcool/prisma/issues/1537


Hello graphcool-team,

I've come across a weird behavior of the bundler that caused a few of my deployments to fail or grow very big (10GB build.zip)

Versions graphcool-framework: 0.11.4 MacOS: 10.13.2 Node: 8.9

Current behavior When creating a new deployment with graphcool-framework deploy the resulting ./.build/build.zip file, which is uploaded to the cluster, contains itself.

There are two problems with this:

  1. Build might never finish (because archive references itself)
  2. Build can potentially become very big (mine was over 10GB in size)

Reproduction

> graphcool-framework init build-test
> graphcool-framework deploy

There are two ways to see the results: Using docker, or with a debug flag (see below)

Docker

The following instructions are written with a local cluster (graphcool running on docker) in mind

> docker ps
> docker exec -it {localfaas} /bin/bash

Inside the docker-container:

Find the current deployment

bash-4.3# cd /var/faas/deployments/cjc56e125006e0143y6g2ihga/cjc56e251006z0143jn48xl1c/

view contents of deployment:

bash-4.3# ls -al
total 32
drwxr-xr-x    4 root     root          4096 Jan  7 19:32 .
drwxr-xr-x    3 root     root          4096 Jan  7 19:32 ..
drwxr-xr-x    2 root     root          4096 Jan  7 19:32 .build
-rw-r--r--    1 root     root            63 Jan  7 19:32 .graphcoolrc
-rw-r--r--    1 root     root          1249 Jan  7 19:32 graphcool.yml
-rw-r--r--    1 root     root            89 Jan  7 19:32 package.json
drwxr-xr-x    2 root     root          4096 Jan  7 19:32 src
-rw-r--r--    1 root     root           554 Jan  7 19:32 types.graphql

Here you can already see the presence of a .build folder So let's look inside:

bash-4.3# ls -al .build
total 12
drwxr-xr-x    2 root     root          4096 Jan  7 19:32 .
drwxr-xr-x    4 root     root          4096 Jan  7 19:32 ..
-rw-r--r--    1 root     root          1413 Jan  7 19:32 build.zip

The build.zip file is included within the bundled deployment. But the contents are not readable

bash-4.3# unzip -vl .build/build.zip
Archive:  .build/build.zip
 Length   Method    Size  Cmpr    Date    Time   CRC-32   Name
--------  ------  ------- ---- ---------- ----- --------  ----
unzip: can't find file table

Debug flag

The current behavior can also be observed by setting an env variable DEBUG=bundler when deploying:

> DEBUG=bundler graphcool-framework deploy

This prints the following lines:

bundler /Users/user/work/build-test/.build/build.zip +0ms
Bundling functions...  bundler added files [ '.graphcoolrc',
  'graphcool.yml',
  'package.json',
  'src/',
  'types.graphql',
  '.build/build.zip',
  '.build/dist/',
  'src/hello.graphql' ] +18ms
  bundler converted files [ '/Users/user/work/build-test/src/hello.js' ] +625ms
  bundler createdFiles [ '/Users/user/work/build-test/.build/dist/src/hello.js' ] +0ms
  bundler adding /Users/user/work/build-test/.build/dist/src/ src/ +13ms
  bundler adding /Users/user/work/build-test/.build/dist/src/byline.js src/byline.js +0ms
  bundler adding /Users/user/work/build-test/.build/dist/src/hello-dev.js src/hello-dev.js +0ms
  bundler adding /Users/user/work/build-test/.build/dist/src/hello-lambda.js src/hello-lambda.js +0ms
  bundler adding /Users/user/work/build-test/.build/dist/src/hello.js src/hello.js +0ms
  bundler added build files [ 'src/',
  'src/byline.js',
  'src/hello-dev.js',
  'src/hello-lambda.js',
  'src/hello.js' ] +0ms
  bundler uploading to http://localhost:60050/functions/files/cjc56e125006e0143y6g2ihga/cjc57okzm007q0143bzsxncep +172ms
  bundler {
  bundler   "success" : true
  bundler } +41ms
  bundler bundled 867 +0ms
 868ms

And it's clearly visible that .build/build.zip is added to the bundle, including .build/dist/.

Expected behavior? The absence of the entire .build folder in build.zip

Proposed solution It seems like the error is caused during file-exclusion using globby in the bundler. Here's a reference to the line: cli/packages/graphcool-cli-core/src/commands/deploy/Bundler/Bundler.ts#L82.

Instead of '!.build' it should be '!.build/**' which excludes everything from the .build folder. I can open a PR if needed.

Cheers