node js app over cloud foundry failing as node oracledb dep is not getting downloaded behind firewall

人走茶凉 提交于 2020-01-06 07:21:34

问题


I have a node js app which needs to be pushed to cloud foundry. The oracle binary download is blocked by firewall so npm install fails to download node oracledb dependency. I have manually installed it under local node_modules folder. Now when i push my app to CF, it agains try to download node oracledb dependency, which is already present in local node_modules folder. My query is how can i mention this in package.json or package-lock.json so that CF does not download node oracledb with every push. I want it to use only bundled dependency. P.S adding proxy won't work here as this platform specific binary is hosted over S3.AWS on internet and is blocked by our org.


回答1:


For offline environments, you need to "vendor" your dependencies. The act of "vendoring", means that you download them in advance and cf push both your app and the dependencies. When you do this, the buildpack won't need to download anything because it all exists already.

The process for Node.js apps is here -> https://docs.cloudfoundry.org/buildpacks/node/index.html#vendoring

For non-native code, this is easy, but for native code there is a complication. To vendor your dependencies, you need to make sure that the architecture of your local machine matches that of the target (i.e. your Cloud Foundry stack). If the architecture doesn't match, the binaries won't run on CF and the buildpack will need to try to download and build those resources for you (this will fail in an offline environment).

At the time of writing, there are two stacks available for Cloud Foundry. The most commonly used is cflinuxfs2. This is basically Ubuntu Trusty 14.04. There is also cflinuxfs3 which is basically Ubuntu Bionic 18.04. As I'm writing this, the latter is pretty new and might not be available in all environments. There are also Windows stacks, but that's not relevant here because the Node.js buildpack only runs on the Linux stacks. You can run cf stacks to see which stacks are available in your environment.

To select the stack you want, run cf push -s <stack>, however that's not usually necessary as most environments will default to using one of the Linux stacks.

To bring this back to vendoring your Node.js dependencies, you need to perform the local vendoring operations in an environment that matches the stack. If you're running Windows or MacOS, that means using a VM or a Docker image. You have a few options in terms of your VM or Docker image.

  • The stacks, also called rootfs, are available as Docker images. You can work on this by running docker run -w /app -vpwd:/app -it cloudfoundry/cflinuxfs2 bash or docker run -w /app -vpwd:/app -it cloudfoundry/cflinuxfs2 bash. That will give you a shell in a matching container where you can run the vendoring process.
  • Do the same thing, but use the base Ubuntu Trusty 14.04 or Ubuntu Bionic 18.04 image. These are basically the same as the cflinuxfsX images, they just come with the stock set of packages. If you need to apt install dev packages so that your native code builds, that is OK.
  • Create an Ubuntu Trusty 14.04 or Ubuntu Bionic 18.04 VM. This is the same as the previous option, but you're using a VM instead of Docker.

Once you've properly vendored your dependencies using the correct architecture, you should be able to cf push your app and the buildpack will run and not need to download anything from the Internet.




回答2:


After much research and experiments, I was able to achieve this without docker image. In package.json -

 "dependencies": {
    "crypto": "^1.0.1",
    "express": "^4.16.3",
    "morgan": "^1.9.0",
    "nan": "^2.11.0",
    "oracledb": "file:oracledb_build",
    "typeorm": "^0.2.7"
  }

if we mention the relative file location in project from where npm should look for oracledb dependency instead of going over to internet, it solves this problem. if we mention - "oracledb": "^2.3.0" --It always goes over to internet to download platform specific binary, even if you manually copy oracledb into node_modules, and provide binary with matching architecture. I have observed this behavior with oracledb 2.3.0. My problem got resolved when i provided oracledb 2.0.15 locally.



来源:https://stackoverflow.com/questions/52217238/node-js-app-over-cloud-foundry-failing-as-node-oracledb-dep-is-not-getting-downl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!