简体   繁体   中英

How do I connect to an external Oracle database using the Python cx_Oracle package on Google App Engine Flex?

My Python App Engine Flex application needs to connect to an external Oracle database. Currently I'm using the cx_Oracle Python package which requires me to install the Oracle Instant Client .

I have successfully run this locally (on macOS) by following the Instant Client installation steps . The steps required me to do the following:

  1. Make a directory called /opt/oracle
  2. Create a symlink from /opt/oracle/instantclient_12_2/libclntsh.dylib.12.1 to ~/lib/

However, I am confused about how to do the same thing in App Engine Flex ( instructions ). Specifically, here's what I'm confused about:

  1. The instructions say I should run sudo yum install libaio to install the libaio package. How do I do this on GAE Flex? Or is this package already available?
  2. I think I can add the Instant Client files to GAE (a whopping ~100MB!), then set the LD_LIBRARY_PATH environment variable in app.yaml to export LD_LIBRARY_PATH=/opt/oracle/instantclient_12_2:$LD_LIBRARY_PATH . Will this work?
  3. Is this even feasible without using custom Docker containers on App Engine Flex?

Overall I'm not sure if I'm on the right track. Would love to hear from someone who has managed this before :)

If any of your dependencies is not available in the base GAE flex images provided by Google and cannot be installed via pip (because it's not a python package or it's not available in PyPI or whatever other reason) then you can't use the requirements.txt file to get it installed in your GAE flex app.

The proper way to satisfy such dependencies would be to build your own custom runtime. From About Custom Runtimes :

Custom runtimes allow you to define new runtime environments, which might include additional components like language interpreters or application servers.

Yes, that means providing a custom Docker file. In your particular case you'd be installing the Instant Client and libaio inside this Dockerfile. See also Building Custom Runtimes .

Answering your first question, I think that the instructions in the oracle website just show that you have to install said library for your application to work.

In the case of App engine flex, they way to ensure that the libraries are present in the deployment is with the requirements.txt textfile. There is a documentation page which does explain how to do so.

On the other hand, I will assume that "Instant Client Files" are not libraries, but necessary data for your App to run. You should use Google Cloud Storage to serve them, or any other alternative of Storage within Google Cloud.

I believe that, if this is all what you need for your App to work, pushing your own custom container should not be necessary.

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