0

I am trying to push a Python (3.6.5) app via Flask to Cloud Foundry (cf version 6.36.1+e3799ad7e.2018-04-04). The application takes a POST request (text file), does some text transformation, saves the new file, and returns a confirmation message. It works locally (tested via Postman). However, when attempting to push it to CF, it gives the following error -

Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-ygzuah5g/logging/

Could you please let me know how I can go about solving this issue? Thanks in advance. The entire files together are ~ 350 MB. I am using a manifest.yml

---
applications:
- name: textsum
  memory: 512M
  command: python server.py
  buildpack: https://github.com/cloudfoundry/buildpack-python.git

PS - Not sure if this is helpful, I do have import queue in one of my files. If I change it to import Queue (Py 2x compatible) and use Py 2.7.15 runtime, the cf push is successful, but it throws runtime errors

ERROR in app: Exception on / [POST]
File "/home/vcap/deps/0/python/lib/python2.7/subprocess.py", line 1047, in _execute_child
ERR   raise child_exception
ERR OSError: [Errno 2] No such file or directory
ERR 10.0.65.11 - - [12/Jun/2018 20:56:16] "POST / HTTP/1.1" 500 -
KRW4
  • 67
  • 2
  • 10

1 Answers1

0

First. Don't do this in your manifest.yml:

buildpack: https://github.com/cloudfoundry/buildpack-python.git

This is telling Cloud Foundry to use the master branch of the buildpack which can change quite frequently and there are no guarantees of it's fitness (i.e. it could even be broken).

Instead, make sure that you are using a release. Releases are tested and the code won't change out from under you.

You can do this by using the platform supplied Python buildpack, simply remove this line or put python_buildpack as the name, or you can point to buildpack: https://github.com/cloudfoundry/buildpack-python.git#v1.6.17 where v1.6.17 is a release from here.

https://github.com/cloudfoundry/python-buildpack/releases

Second, it seems like you need to tell Cloud Foundry & the buildpack which version of Python you want. If you need Python 3, then you should tell it that. See here for instructions on doing that.

https://stackoverflow.com/a/50837696/1585136

Third, this error:

ERR OSError: [Errno 2] No such file or directory

Seems like you're trying to write to a location that does not exist. Where are you trying to write your file? The paths will be different on your local machine vs running on Cloud Foundry. Typically on Cloud Foundry, you would write temporary files to /home/vcap/tmp or /app/tmp (/app is a symlink to /home/vcap) or $HOME/tmp. They all point to the same place.

I'm specifically mentioning temporary files here because you don't want to write permanent files to the local file system on Cloud Foundry. The local file system is ephemeral and your data will not persist for very long. See here for details.

https://docs.cloudfoundry.org/devguide/deploy-apps/prepare-to-deploy.html#filesystem

Hope that helps!

Daniel Mikusa
  • 13,716
  • 1
  • 22
  • 28
  • Thanks for the reply. I have changed the manifest to use a release buildpack (https://github.com/cloudfoundry/buildpack-python.git#v1.6.17) and am using the runtime.txt (python-3.5.x). Also, I am using only temporary file to write into, like so - `tmp_dir = '$HOME/tmp/textfiles'` and I am able to run it locally (via Postman) using Python 3.x. However, in CF the error `Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-ygzuah5g/logging/` still persists while using any python-3.x runtime. Any further ideas on how to go about this would be helpful! – KRW4 Jun 13 '18 at 20:47
  • It's unclear where you're seeing the failure message. Can you provide a larger snippet of log files? Perhaps the entire output from `cf push` to failure? – Daniel Mikusa Jun 14 '18 at 13:48
  • Solved - This issue was due to (redundantly) importing third party library called `logging` into the Python 3 environment, which is hiding the standard library version. The library is, by default, there in Python 3 environment. No need to import it via requirements. Thanks @daniel-mikusa for inputs. – KRW4 Jun 14 '18 at 20:10