如何在Heroku上部署连接到Oracle云数据库的Python/Django应用程序?

mi7gmzs6  于 2023-05-29  发布在  Oracle
关注(0)|答案(1)|浏览(149)

当我将我的Python Django应用部署到Heroku时。我得到以下错误/构建日志输出。

-----> Building on the Heroku-22 stack
-----> Determining which buildpack to use for this app
-----> Python app detected
-----> No Python version was specified. Using the buildpack default: python-3.11.2
       To use a different version, see: https://devcenter.heroku.com/articles/python-runtimes
-----> Installing python-3.11.2
-----> Installing pip 23.0.1, setuptools 63.4.3 and wheel 0.38.4
-----> Installing SQLite3
-----> Installing requirements with pip
       Collecting asgiref==3.6.0
         Downloading asgiref-3.6.0-py3-none-any.whl (23 kB)
       Collecting astroid==2.15.0
         Downloading astroid-2.15.0-py3-none-any.whl (277 kB)
       Collecting certifi==2022.12.7
         Downloading certifi-2022.12.7-py3-none-any.whl (155 kB)
       Collecting cffi==1.15.1
         Downloading cffi-1.15.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (462 kB)
       Collecting channels==3.0.4
         Downloading channels-3.0.4-py3-none-any.whl (38 kB)
       Collecting charset-normalizer==3.1.0
         Downloading charset_normalizer-3.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (197 kB)
       Collecting config==0.5.1
         Downloading config-0.5.1-py2.py3-none-any.whl (20 kB)
       Collecting cryptography==39.0.2
         Downloading cryptography-39.0.2-cp36-abi3-manylinux_2_28_x86_64.whl (4.2 MB)
       Collecting cx-Oracle==8.3.0
         Downloading cx_Oracle-8.3.0.tar.gz (363 kB)
         Installing build dependencies: started
         Installing build dependencies: finished with status 'done'
         Getting requirements to build wheel: started
         Getting requirements to build wheel: finished with status 'done'
         Preparing metadata (pyproject.toml): started
         Preparing metadata (pyproject.toml): finished with status 'done'
       Collecting defusedxml==0.7.1
         Downloading defusedxml-0.7.1-py2.py3-none-any.whl (25 kB)
       Collecting dill==0.3.6
         Downloading dill-0.3.6-py3-none-any.whl (110 kB)
       Collecting Django==4.1.7
         Downloading Django-4.1.7-py3-none-any.whl (8.1 MB)
       Collecting django-allauth==0.52.0
         Downloading django-allauth-0.52.0.tar.gz (728 kB)
         Preparing metadata (setup.py): started
         Preparing metadata (setup.py): finished with status 'done'
       Collecting django-environ==0.10.0
         Downloading django_environ-0.10.0-py2.py3-none-any.whl (19 kB)
       Collecting django-widget-tweaks==1.4.12
         Downloading django_widget_tweaks-1.4.12-py3-none-any.whl (8.9 kB)
       Collecting humanfriendly==10.0
         Downloading humanfriendly-10.0-py2.py3-none-any.whl (86 kB)
       Collecting idna==3.4
         Downloading idna-3.4-py3-none-any.whl (61 kB)
       Collecting isort==5.12.0
         Downloading isort-5.12.0-py3-none-any.whl (91 kB)
       Collecting lazy-object-proxy==1.9.0
         Downloading lazy_object_proxy-1.9.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (64 kB)
       Collecting mccabe==0.7.0
         Downloading mccabe-0.7.0-py2.py3-none-any.whl (7.3 kB)
       Collecting oauthlib==3.2.2
         Downloading oauthlib-3.2.2-py3-none-any.whl (151 kB)
       Collecting oracledb==1.2.2
         Downloading oracledb-1.2.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.0 MB)
       Collecting platformdirs==3.1.1
         Downloading platformdirs-3.1.1-py3-none-any.whl (14 kB)
       Collecting pycparser==2.21
         Downloading pycparser-2.21-py2.py3-none-any.whl (118 kB)
       Collecting PyJWT==2.6.0
         Downloading PyJWT-2.6.0-py3-none-any.whl (20 kB)
       Collecting pylint==2.17.0
         Downloading pylint-2.17.0-py3-none-any.whl (535 kB)
       Collecting pylint-django==2.5.3
         Downloading pylint_django-2.5.3-py3-none-any.whl (81 kB)
       Collecting pylint-plugin-utils==0.7
         Downloading pylint_plugin_utils-0.7-py3-none-any.whl (10 kB)
       Collecting python-dotenv==1.0.0
         Downloading python_dotenv-1.0.0-py3-none-any.whl (19 kB)
       Collecting python-environ==0.4.54
         Downloading python-environ-0.4.54.tar.gz (22 kB)
         Preparing metadata (setup.py): started
         Preparing metadata (setup.py): finished with status 'done'
       Collecting python3-openid==3.2.0
         Downloading python3_openid-3.2.0-py3-none-any.whl (133 kB)
       Collecting requests==2.28.2
         Downloading requests-2.28.2-py3-none-any.whl (62 kB)
       Collecting requests-oauthlib==1.3.1
         Downloading requests_oauthlib-1.3.1-py2.py3-none-any.whl (23 kB)
       Collecting sqlparse==0.4.3
         Downloading sqlparse-0.4.3-py3-none-any.whl (42 kB)
       Collecting tomlkit==0.11.6
         Downloading tomlkit-0.11.6-py3-none-any.whl (35 kB)
       Collecting urllib3==1.26.14
         Downloading urllib3-1.26.14-py2.py3-none-any.whl (140 kB)
       Collecting wrapt==1.15.0
         Downloading wrapt-1.15.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (78 kB)
       Collecting daphne<4,>=3.0
         Downloading daphne-3.0.2-py3-none-any.whl (26 kB)
       Collecting twisted[tls]>=18.7
         Downloading Twisted-22.10.0-py3-none-any.whl (3.1 MB)
       Collecting autobahn>=0.18
         Downloading autobahn-23.1.2.tar.gz (480 kB)
         Preparing metadata (setup.py): started
         Preparing metadata (setup.py): finished with status 'done'
       Collecting txaio>=21.2.1
         Downloading txaio-23.1.1-py2.py3-none-any.whl (30 kB)
       Collecting hyperlink>=21.0.0
         Downloading hyperlink-21.0.0-py2.py3-none-any.whl (74 kB)
       Collecting zope.interface>=4.4.2
         Downloading zope.interface-6.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (249 kB)
       Collecting constantly>=15.1
         Downloading constantly-15.1.0-py2.py3-none-any.whl (7.9 kB)
       Collecting incremental>=21.3.0
         Downloading incremental-22.10.0-py2.py3-none-any.whl (16 kB)
       Collecting Automat>=0.8.0
         Downloading Automat-22.10.0-py2.py3-none-any.whl (26 kB)
       Collecting attrs>=19.2.0
         Downloading attrs-22.2.0-py3-none-any.whl (60 kB)
       Collecting typing-extensions>=3.6.5
         Downloading typing_extensions-4.5.0-py3-none-any.whl (27 kB)
       Collecting pyopenssl>=21.0.0
         Downloading pyOpenSSL-23.1.1-py3-none-any.whl (57 kB)
       Collecting service-identity>=18.1.0
         Downloading service_identity-21.1.0-py2.py3-none-any.whl (12 kB)
       Collecting six
         Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
       Collecting pyasn1-modules
         Downloading pyasn1_modules-0.2.8-py2.py3-none-any.whl (155 kB)
       Collecting pyasn1
         Downloading pyasn1-0.4.8-py2.py3-none-any.whl (77 kB)
       Building wheels for collected packages: cx-Oracle, django-allauth, python-environ, autobahn
         Building wheel for cx-Oracle (pyproject.toml): started
         Building wheel for cx-Oracle (pyproject.toml): finished with status 'done'
         Created wheel for cx-Oracle: filename=cx_Oracle-8.3.0-cp311-cp311-linux_x86_64.whl size=210943 sha256=45e8fd49b82fe4b86643fa8eb0a425d895b0f4b23ef7345407910610694b209d
         Stored in directory: /tmp/pip-ephem-wheel-cache-73oja8kp/wheels/e0/41/f9/63e9c4d1ec7b2e8faffc1d6f3219c2e168c306b042d77e2b6f
         Building wheel for django-allauth (setup.py): started
         Building wheel for django-allauth (setup.py): finished with status 'done'
         Created wheel for django-allauth: filename=django_allauth-0.52.0-py3-none-any.whl size=1063914 sha256=1155c2187de4e64fafe4dda0509fd28bd8d687bcb31330b5fe098121df7cf61c
         Stored in directory: /tmp/pip-ephem-wheel-cache-73oja8kp/wheels/e1/c8/ca/7e4be574a46605642219627189c7a61527cedbf04f507b0b06
         Building wheel for python-environ (setup.py): started
         Building wheel for python-environ (setup.py): finished with status 'done'
         Created wheel for python-environ: filename=python_environ-0.4.54-py2.py3-none-any.whl size=16341 sha256=4f10b16448a2c82a66813e4e6db5392335f28227c2bd645da32aeea559633242
         Stored in directory: /tmp/pip-ephem-wheel-cache-73oja8kp/wheels/98/67/9a/de43dd9ce52d81c220f8382bde233435bd544e8145fc7e49e0
         Building wheel for autobahn (setup.py): started
         Building wheel for autobahn (setup.py): finished with status 'done'
         Created wheel for autobahn: filename=autobahn-23.1.2-py2.py3-none-any.whl size=666855 sha256=b590e20ceaa791e68ddf732bea1289b5f7216e48cf20f362f66003490ae2c65d
         Stored in directory: /tmp/pip-ephem-wheel-cache-73oja8kp/wheels/19/4b/71/60bf756ecc15f1aa77a8dd7aca9907d3599a565807c8d52fb7
       Successfully built cx-Oracle django-allauth python-environ autobahn
       Installing collected packages: python-environ, pyasn1, incremental, cx-Oracle, constantly, config, zope.interface, wrapt, urllib3, typing-extensions, txaio, tomlkit, sqlparse, six, python-dotenv, PyJWT, pycparser, pyasn1-modules, platformdirs, oauthlib, mccabe, lazy-object-proxy, isort, idna, humanfriendly, django-widget-tweaks, django-environ, dill, defusedxml, charset-normalizer, certifi, attrs, asgiref, requests, python3-openid, hyperlink, Django, cffi, Automat, astroid, twisted, requests-oauthlib, pylint, cryptography, service-identity, pyopenssl, pylint-plugin-utils, oracledb, autobahn, pylint-django, django-allauth, daphne, channels
       Successfully installed Automat-22.10.0 Django-4.1.7 PyJWT-2.6.0 asgiref-3.6.0 astroid-2.15.0 attrs-22.2.0 autobahn-23.1.2 certifi-2022.12.7 cffi-1.15.1 channels-3.0.4 charset-normalizer-3.1.0 config-0.5.1 constantly-15.1.0 cryptography-39.0.2 cx-Oracle-8.3.0 daphne-3.0.2 defusedxml-0.7.1 dill-0.3.6 django-allauth-0.52.0 django-environ-0.10.0 django-widget-tweaks-1.4.12 humanfriendly-10.0 hyperlink-21.0.0 idna-3.4 incremental-22.10.0 isort-5.12.0 lazy-object-proxy-1.9.0 mccabe-0.7.0 oauthlib-3.2.2 oracledb-1.2.2 platformdirs-3.1.1 pyasn1-0.4.8 pyasn1-modules-0.2.8 pycparser-2.21 pylint-2.17.0 pylint-django-2.5.3 pylint-plugin-utils-0.7 pyopenssl-23.1.1 python-dotenv-1.0.0 python-environ-0.4.54 python3-openid-3.2.0 requests-2.28.2 requests-oauthlib-1.3.1 service-identity-21.1.0 six-1.16.0 sqlparse-0.4.3 tomlkit-0.11.6 twisted-22.10.0 txaio-23.1.1 typing-extensions-4.5.0 urllib3-1.26.14 wrapt-1.15.0 zope.interface-6.0
-----> $ python manage.py collectstatic --noinput
       Traceback (most recent call last):
         File "/tmp/build_63541e73/manage.py", line 22, in <module>
           main()
         File "/tmp/build_63541e73/manage.py", line 18, in main
           execute_from_command_line(sys.argv)
         File "/app/.heroku/python/lib/python3.11/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
           utility.execute()
         File "/app/.heroku/python/lib/python3.11/site-packages/django/core/management/__init__.py", line 386, in execute
           settings.INSTALLED_APPS
         File "/app/.heroku/python/lib/python3.11/site-packages/django/conf/__init__.py", line 92, in __getattr__
           self._setup(name)
         File "/app/.heroku/python/lib/python3.11/site-packages/django/conf/__init__.py", line 79, in _setup
           self._wrapped = Settings(settings_module)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^
         File "/app/.heroku/python/lib/python3.11/site-packages/django/conf/__init__.py", line 190, in __init__
           mod = importlib.import_module(self.SETTINGS_MODULE)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         File "/app/.heroku/python/lib/python3.11/importlib/__init__.py", line 126, in import_module
           return _bootstrap._gcd_import(name[level:], package, level)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
         File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
         File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
         File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
         File "<frozen importlib._bootstrap_external>", line 940, in exec_module
         File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
         File "/tmp/build_63541e73/config/settings.py", line 20, in <module>
           oracledb.init_oracle_client(
         File "src/oracledb/impl/thick/utils.pyx", line 455, in oracledb.thick_impl.init_oracle_client
         File "src/oracledb/impl/thick/utils.pyx", line 479, in oracledb.thick_impl.init_oracle_client
         File "src/oracledb/impl/thick/utils.pyx", line 400, in oracledb.thick_impl._raise_from_info
       oracledb.exceptions.DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "libclntsh.so: cannot open shared object file: No such file or directory". See https://python-oracledb.readthedocs.io/en//latest/user_guide/initialization.html#setting-the-oracle-client-library-directory for help
 !     Error while running '$ python manage.py collectstatic --noinput'.
       See traceback above for details.
       You may need to update application code to resolve this error.
       Or, you can disable collectstatic for this application:
          $ heroku config:set DISABLE_COLLECTSTATIC=1
       https://devcenter.heroku.com/articles/django-assets
 !     Push rejected, failed to compile Python app.
 !     Push failed

显然,这是因为Oracle Instant Client库没有与应用程序一起部署。
我的问题是如何修改我的应用程序,使其能够部署在Heroku上并能够连接到我的Oracle云数据库?
我会提供所有需要的文件,我只是不知道什么是需要解决的问题atm。
Oracle和Heroku似乎都没有足够的文档来解决这个问题。

k4emjkb1

k4emjkb11#

我看到你正在使用Heroku-22堆栈,看起来像是Ubuntu 22.04 LTS。参见https://devcenter.heroku.com/articles/stack
我们最近构建了一个django -> Oracle ADB docker容器(在Oracle Linux 8上),因此必须在容器构建时安装以下包,以使db客户端为我们的应用程序工作:

oracle-instantclient-release-el8    
oracle-instantclient-basic     
oracle-instantclient-sqlplus

对于OL 8,我们使用:

dnf -y install oracle-instantclient-release-el8

我们跟随这个文档获取背景信息:https://docs.oracle.com/en/database/oracle/oracle-database/21/lacli/install-instant-client-using-rpm.html#GUID-2E81E2AE-E94C-413F-99B2-AE9A3949F05D
我会为您的堆栈选择相关的包管理器,然后尝试在构建时安装上述包。如果没有兼容的软件包管理器,那么您可能需要下载zip并以这种方式安装:https://docs.oracle.com/en/database/oracle/oracle-database/21/lacli/install-instant-client-using-zip.html#GUID-D3DCB4FB-D3CA-4C25-BE48-3A1FB5A22E84
此外,你的settings.py文件需要如下内容,以便django应用程序初始化连接:

import cx_Oracle
    
cx_Oracle.init_oracle_client()

相关问题