在依赖项安装之前将wget / curl二进制文件添加到OpenShift

时间:2017-07-19 02:38:06

标签: python oracle openshift hook

我正在尝试在OpenShift POD上执行Oracle客户端的干净安装,就在安装依赖项之前(在我的情况下是python requirements.txt),必须安装Oracle才能安装cx_Oracle。 / p>

如何自动化此过程?我可以在其中一个action_hooks中添加一行吗?

感谢。

1 个答案:

答案 0 :(得分:5)

OpenShift 3没有OpenShift 2等动作挂钩的概念。

要实现您想要的目标,您需要执行以下操作。

在应用程序源代码库中创建目录.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构建过程以非root用户身份运行,因此您需要在/opt/app-root的新子目录下安装任何内容。