我正在尝试将 Oracle 客户端全新安装到 OpenShift POD 上,就在安装依赖项(在我的例子中是 python requirements.txt)之前,必须存在 Oracle 安装才能安装 cx_Oracle。
我怎样才能使这个过程自动化?我可以简单地在其中一个 action_hooks 中添加一行吗?
谢谢。
最佳答案
OpenShift 3 没有像 OpenShift 2 那样的操作 Hook 概念。
要实现您的目标,您需要执行以下操作。
在您的应用程序源代码存储库中创建目录 .s2i/bin
。
在该目录中创建一个名为assemble
的文件。添加到该文件中:
#!/bin/bash
set -eo pipefail
# Add steps here to install Oracle client libraries and header files.
# Install these in a new subdirectory under /opt/app-root. Lets assume
# you use /opt/app-root/oracle.
# ...
# Set and export whatever environment variables you need to set
# to have cx_Oracle when installed pickup header files and libraries
# from under /opt/app-root/oracle. So that Oracle shared libraries
# are found when the Python application is later run, this should
# include setting LD_RUN_PATH environment variable to compile the
# directory where the Oracle libraries are located into the module
# when it is built.
export LD_RUN_PATH=/opt/app-root/oracle/lib
# ...
# Run the original assemble script.
/usr/libexec/s2i/assemble
确保这个assemble
脚本是可执行的。
chmod +x .s2i/bin/assemble
如果 cx_Oracle
作为二进制 Python 轮子出现并且不需要编译,则上面的 LD_RUN_PATH
技巧将不起作用。在这种情况下,还要执行以下操作。
在 .s2i/bin
目录中添加一个 run
脚本。添加到该文件中:
#!/bin/bash
set -eo pipefail
# Set LD_LIBRARY_PATH environment variable to directory containing
# the Oracle client libraries.
export LD_LIBRARY_PATH=/opt/app-root/oracle/lib
# Run the original run script, ensuring exec is used.
exec /usr/libexec/s2i/run
确保这个脚本是可执行的。
chmod +x .s2i/bin/run
如果您需要通过终端访问 pod 并运行需要 Oracle 的脚本,请注意,如果您依赖这种方式,则不会设置 LD_LIBRARY_PATH
,因此不会设置 Oracle 库成立。在这种情况下,最好添加一个 .s2i/environment
文件并在其中添加 LD_LIBRARY_PATH
设置。
LD_LIBRARY_PATH=/opt/app-root/oracle/lib
通过在 .s2i/environment
中设置,环境变量将在镜像中设置并始终设置,即使在使用终端访问 pod 时也是如此。
请记住,S2I 构建过程以非根用户身份运行,因此您需要在 /opt/app-root
的新子目录下安装任何东西。
关于python - 在安装依赖项之前将 wget/curl 二进制文件放到 OpenShift 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45180023/