已构建的React应用程序到Cloud Foundry的staticfile部署似乎都认为是Node部署,即使使用buildpack

时间:2019-07-05 20:33:18

标签: reactjs deployment cloudfoundry

我目前正在尝试将构建的React应用程序部署到Cloud Foundry。 React没什么特别的,它打包成一组静态文件,没有问题。但是,当我尝试部署到CF时,出现以下错误:

16:24:44.467: [APP/PROC/WEB.0] bash: npm: command not found
16:24:44.519: [APP/PROC/WEB.0] Exit status 127

这是我的清单,这就是为什么我对为什么发生此错误感到非常困惑。

applications:
- name: whatever
  path: build
  memory: 64M
  instances: 1
  disk_quota: 1024M
  buildpacks: 
  - https://github.com/cloudfoundry/staticfile-buildpack.git

我已经尝试从顶级文件夹以及build文件夹内部进行部署,并且还尝试包括Node buildpack(我知道这是行不通的,因为它没有npm start的指令。

完整的部署日志在这里:

16:21:27.583: [STG.0] -----> Running go build supply
16:21:27.583: [STG.0] /tmp/buildpackdownloads/49e489d3547d6eb82fdd6227f8309290 ~
16:21:34.358: [STG.0] ~
16:21:34.389: [STG.0] -----> Staticfile Buildpack version 1.4.43
16:21:34.389: [STG.0]        **WARNING** 
16:21:34.389: [STG.0]        !! !!
16:21:34.389: [STG.0]        This application is being deployed on cflinuxfs2 which is being deprecated in April, 2019.
16:21:34.389: [STG.0]        Please migrate this application to cflinuxfs3.
16:21:34.389: [STG.0]        For more information about changing the stack, see https://docs.cloudfoundry.org/devguide/deploy-apps/stacks.html
16:21:34.389: [STG.0]        !! !!
16:21:34.389: [STG.0] -----> Installing nginx
16:21:34.389: [STG.0]        Using nginx version 1.15.12
16:21:34.389: [STG.0] -----> Installing nginx 1.15.12
16:21:34.389: [STG.0]        Copy [/tmp/cache/final/dependencies/742479b4d3f80b641ae394b6c5699e126e53f25198dfbcd9a5e54b66413ecba0/nginx-1.15.12-linux-x64-cflinuxfs2-4d0440ef.tgz]
16:21:34.667: [STG.0] -----> Running go build finalize
16:21:34.667: [STG.0] /tmp/buildpackdownloads/49e489d3547d6eb82fdd6227f8309290 ~
16:21:38.930: [STG.0] ~
16:21:38.951: [STG.0] -----> Root folder /tmp/app
16:21:38.951: [STG.0] -----> Copying project files into public
16:21:38.954: [STG.0] -----> Configuring nginx
16:21:39.207: [API.1] Creating droplet for app with guid 3df28cf5-8faf-40ef-a4e7-4e9658df9926
16:21:40.395: [STG.0] Exit status 0
16:21:40.395: [STG.0] Uploading droplet, build artifacts cache...
16:21:40.396: [STG.0] Uploading build artifacts cache...
16:21:40.396: [STG.0] Uploading droplet...
16:21:40.780: [STG.0] Uploaded build artifacts cache (2.7M)
16:21:42.060: [STG.0] Uploaded droplet (3.1M)
16:21:42.062: [STG.0] Uploading complete
16:21:42.134: [STG.0] Cell 3a98d2c0-2583-48dd-aa40-b72fe78267cf stopping instance bd85c2ad-6a00-405f-bbf0-c96d429fda43
16:21:42.134: [STG.0] Cell 3a98d2c0-2583-48dd-aa40-b72fe78267cf destroying container for instance bd85c2ad-6a00-405f-bbf0-c96d429fda43
16:21:45.333: [STG.0] Cell 3a98d2c0-2583-48dd-aa40-b72fe78267cf successfully destroyed container for instance bd85c2ad-6a00-405f-bbf0-c96d429fda43
16:21:46.397: [API.1] Process has crashed with type: "web"
16:21:46.422: [API.1] App instance exited with guid 3df28cf5-8faf-40ef-a4e7-4e9658df9926 payload: {"instance"=>"60e81bb4-79cd-4a42-6101-359c", "index"=>0, "reason"=>"CRASHED", "exit_description"=>"APP/PROC/WEB: Exited with status 127", "crash_count"=>2, "crash_timestamp"=>1562358175613734337, "version"=>"7e7a157a-d48a-47fc-863b-80193bad0461"}
16:21:47.750: [API.4] Process has crashed with type: "web"
16:21:47.768: [API.4] App instance exited with guid 3df28cf5-8faf-40ef-a4e7-4e9658df9926 payload: {"instance"=>"9059dfda-9fec-4c82-4a11-1ab1", "index"=>0, "reason"=>"CRASHED", "exit_description"=>"APP/PROC/WEB: Exited with status 127", "crash_count"=>1, "crash_timestamp"=>1562358172401034750, "version"=>"7e7a157a-d48a-47fc-863b-80193bad0461"}
16:21:49.934: [API.1] Process has crashed with type: "web"
16:21:49.956: [API.1] App instance exited with guid 3df28cf5-8faf-40ef-a4e7-4e9658df9926 payload: {"instance"=>"7f4ddf22-07d6-4f3f-62c1-ca68", "index"=>0, "reason"=>"CRASHED", "exit_description"=>"APP/PROC/WEB: Exited with status 127", "crash_count"=>3, "crash_timestamp"=>1562358179064113054, "version"=>"7e7a157a-d48a-47fc-863b-80193bad0461"}
16:22:46.283: [CELL.0] Cell 14d1eaac-45f2-4f93-9995-d8d80b86693d creating container for instance 60e81bb4-79cd-4a42-6101-359c
16:22:47.099: [CELL.0] Cell 14d1eaac-45f2-4f93-9995-d8d80b86693d successfully created container for instance 60e81bb4-79cd-4a42-6101-359c
16:22:48.304: [CELL.0] Starting health monitoring of container
16:22:48.821: [APP/PROC/WEB.0] bash: npm: command not found
16:22:48.858: [APP/PROC/WEB.0] Exit status 127
16:22:48.864: [CELL/SSHD.0] Exit status 0
16:22:49.421: [CELL.0] Cell 14d1eaac-45f2-4f93-9995-d8d80b86693d stopping instance 60e81bb4-79cd-4a42-6101-359c
16:22:49.421: [CELL.0] Cell 14d1eaac-45f2-4f93-9995-d8d80b86693d destroying container for instance 60e81bb4-79cd-4a42-6101-359c

我希望应该提供静态文件,但是我不明白为什么需要NPM。我不明白为什么要使用Staticfile buildpack从静态文件的build文件夹中调用NPM。

2 个答案:

答案 0 :(得分:1)

根据 oficial doc 的其他解决方案是:

要将应用与不同的 buildpack 一起使用,您必须删除该应用,然后再次推送

https://docs.cloudfoundry.org/cf-cli/getting-started.html#push-buildpack

答案 1 :(得分:0)

感谢上面的Daniel Mikusa,我能够解决这个问题。在更改工作流以在同一容器上使用Staticfile buildpack之前,我最初是使用Node buildpack作为Node项目部署到Cloud Foundry上的这个专门命名的服务。我相信发生的事情是因为Node buildpack设置了一个启动命令,它仍然缓存在容器上,并且因为Staticfile buildpack没有覆盖它,所以它仍然存在。即使删除并部署到同一个名称服务,start命令仍然存在。我完全按照丹尼尔所说的去做(新命名的服务,将清单更改为仅使用$ python --version Python 3.7.2 $ pytest --version This is pytest version 3.10.1, imported from /home/gene/.pythonz/pythons/CPython-3.7.2/lib/python3.7/site-packages/pytest.py setuptools registered plugins: pytest-xdist-1.26.1 at /home/gene/.pythonz/pythons/CPython-3.7.2/lib/python3.7/site-packages/xdist/plugin.py pytest-xdist-1.26.1 at /home/gene/.pythonz/pythons/CPython-3.7.2/lib/python3.7/site-packages/xdist/looponfail.py pytest-pythonpath-0.7.3 at /home/gene/.pythonz/pythons/CPython-3.7.2/lib/python3.7/site-packages/pytest_pythonpath.py pytest-mock-1.10.0 at /home/gene/.pythonz/pythons/CPython-3.7.2/lib/python3.7/site-packages/pytest_mock.py pytest-forked-1.0.1 at /home/gene/.pythonz/pythons/CPython-3.7.2/lib/python3.7/site-packages/pytest_forked/__init__.py hypothesis-4.4.1 at /home/gene/.pythonz/pythons/CPython-3.7.2/lib/python3.7/site-packages/hypothesis/extra/pytestplugin.py flaky-3.5.3 at /home/gene/.pythonz/pythons/CPython-3.7.2/lib/python3.7/site-packages/flaky/flaky_pytest_plugin.py 而不是任何git链接),并且没有问题。