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

awz*_*wzx 3 python oracle hook openshift

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

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

谢谢.

Gra*_*ton 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
Run Code Online (Sandbox Code Playgroud)

确保此assemble脚本可执行.

chmod +x .s2i/bin/assemble
Run Code Online (Sandbox Code Playgroud)

如果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
Run Code Online (Sandbox Code Playgroud)

确保此脚本可执行.

chmod +x .s2i/bin/run
Run Code Online (Sandbox Code Playgroud)

如果您需要通过终端访问pod并运行需要Oracle的脚本,请注意,LD_LIBRARY_PATH如果依赖于这种方式,则不会设置,因此将找不到Oracle库.在这种情况下,最好添加一个.s2i/environment文件并在LD_LIBRARY_PATH那里添加设置.

LD_LIBRARY_PATH=/opt/app-root/oracle/lib
Run Code Online (Sandbox Code Playgroud)

通过设置.s2i/environment,环境变量将在图像中设置并始终设置,即使使用终端访问pod也是如此.

请记住,S2I构建过程以非root用户身份运行,因此您需要在新的子目录下安装任何内容/opt/app-root.