简体   繁体   中英

Google App Engine Standard Node JS how to run build script?

Does GAE standard for Node support a way to have build scripts? I tried using postinstall within package.json but that did not work.

My codebase has subdirectories with package.json within the subdirectories. In my root package.json there is

scripts: { 
    postinstall: cd vendor && npm install 
    ....
}

However I'm not seeing any vendor packages installed so I'm inclined to believe the postinstall does not get triggered on GAE Node standard.

Is there any way for me to install subdirectory dependencies without having to copy and paste all my vendor/package.json dependencies to the root?

Note: I've also tried putting an "install" within the package.json scripts but that didn't seem to get triggered either.

In GAE standard, installation of dependencies are automatically managed. You should add them in your package.json .

As Google documentation mentioned :

When you deploy your app, the Node.js runtime automatically installs all dependencies declared in your package.json file using the npm install command.

{
  "dependencies": {
    "lodash": "^4.0.1"
  }
}

Installation will be done during app deployment via :

gcloud app deploy

To add a build step, run the following:

gcloud beta app gen-config --custom

This will generate the default dockerfile and config that is run. In your .dockerfile, add your build step:

RUN npm run build --unsafe-perm || \
  ((if [ -f npm-debug.log ]; then \
      cat npm-debug.log; \
    fi) && false)

"prestart": "if [ ! -d build ]; then npm run build; fi",

" -d build" here is the build process generated folder, replace it to whatever you actually use.

Not sure if this will work for your case, but seems like GAE standard has added the ability to run a custom build step .

However it does state:

After executing your custom build step, App Engine removes and regenerates the node_modules folder by only installing the production dependencies declared in the dependencies field of your package.json file.

Maybe since the node_modules are in your vendor/ directory, GAE may not detect and remove them, thus accomplishing your goal. This is a pre-install step, unlike postinstall specified in your script. Not sure if it matters.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM