简体   繁体   English

为什么我的LoopBack / Node应用程序没有在Bluemix中部署工具链上获取环境变量?

[英]Why isn't my LoopBack/Node app getting environment variables on a toolchain deploy in Bluemix?

I am trying to deploy my LoopBack/Node.js app through a toolchain on Bluemix. 我试图通过Bluemix上的工具链部署我的LoopBack / Node.js应用程序。 I am trying to make use of VCAP_SERVICES in my datasources.production.js file. 我正在尝试在我的datasources.production.js文件中使用VCAP_SERVICES My issues seem to be related to not getting access to any environment variables during deploy. 我的问题似乎与部署期间无法访问任何环境变量有关。

I can see in the log output during deploy that NODE_ENV is getting set, but LoopBack loads my datasources.local.js file and not the production one. 我可以在部署期间的日志输出中看到已设置NODE_ENV,但是LoopBack加载了我的datasources.local.js文件,而不是生产文件。 And my console.log of NODE_ENV says undefined. 而且我的console.log中的NODE_ENV表示未定义。 Any my console.log of JSON.parse(process.env.VCAP_SERVICES) results in {} . 我的任何JSON.parse(process.env.VCAP_SERVICES) console.log都将生成{}

I can also see in the Bluemix UI that I have VCAP_SERVICES bound to my app. 我还可以在Bluemix UI中看到我的应用程序绑定了VCAP_SERVICES。

I keep amending this commit but you can see what I am trying to do here, including the console.log calls. 我一直在修改此提交,但是您可以在此处看到我要执行的操作,包括console.log调用。 https://github.com/StrongLoop-Evangelists/band-app/commit/95640d3ffc7cd9e7553062f7a1b8c66ef0fc2815 https://github.com/StrongLoop-Evangelists/band-app/commit/95640d3ffc7cd9e7553062f7a1b8c66ef0fc2815

And here is the relevant console.log output: 这是相关的console.log输出:

2017-05-08T15:38:22.67+0000 [APP/0]      OUT ---datasources.local.js---
2017-05-08T15:38:22.67+0000 [APP/0]      OUT ---env.js---
2017-05-08T15:38:22.67+0000 [APP/0]      OUT in VCAP if check
2017-05-08T15:38:22.67+0000 [APP/0]      OUT VCAP:  {}
2017-05-08T15:38:22.67+0000 [APP/0]      ERR console.log('NODE_ENV: ', NODE_ENV);
2017-05-08T15:38:22.67+0000 [APP/0]      ERR                           ^
2017-05-08T15:38:22.67+0000 [APP/0]      ERR ReferenceError: NODE_ENV is not defined

Joe: If you're using the delivery pipeline as part of the toolchain in Bluemix to deploy a cloud foundry app there is one small thing to know. Joe:如果您将交付管道用作Bluemix中的工具链的一部分来部署云铸造应用程序,那么您需要了解一点。

Setting the "Environment Properties" on a stage will not automatically pass this to the cf app. 在舞台上设置“环境属性”不会自动将其传递给cf应用程序。 It only makes them available to the pipeline doing the deployment. 它仅使它们可用于进行部署的管道。 To also set these on the cf app, you need to do a cf set-env. 要同时在cf应用中设置这些设置,您需要执行cf set-env。 For example: 例如:

cf set-env myApp $MY_ENV_VAR

My issue was manifest.yml related. 我的问题与manifest.yml有关。

This was failing me: 这让我失望了:

---
applications:
  - name: Band-App
    memory: 256M
  - services:
    - bandapp-cloudantdb

This worked: 这工作:

name: Band-App
memory: 256M
services:
  - bandapp-cloudantdb

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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