问题描述
我正在将Web应用程序从OpenShift v2迁移到OpenShift Pro。这是一个常规的Java Tomcat应用程序。
I am migrating a webapp from OpenShift v2 to OpenShift Pro. This is a regular Java Tomcat app.
我在OpenShift v2上的Web应用程序在server.xml中指定了一个额外的docBase,如下所示:
My webapp on OpenShift v2 had an additional docBase specified in server.xml like this:
<Context docBase="${OPENSHIFT_DATA_DIR}/documents" path="/documents" />
在部署过程中,环境变量 OPENSHIFT_DATA_DIR 已替换为其值: / opt / app-root / data
During deployment the environment variable OPENSHIFT_DATA_DIR was replaced with its value: /opt/app-root/data
就像您期望的那样。
I已经完成了OpenShift Pro中的等效设置(尽管完全不同),但是部署失败。经过调查,我在日志中看到了这一点:
I have done the equivalent (though quite different) set up in OpenShift Pro but the deployment failed. Upon investigation, I saw this in the log:
Caused by: java.lang.IllegalArgumentException: The main resource set specified [/deployments/${OPENSHIFT_DATA_DIR}/documents] is not valid
要克服这一点,我只是硬编码 / opt / app-root / data :
To overcome this I merely hard coded /opt/app-root/data in server.xml like this:
<Context docBase="/opt/app-root/data/documents" path="/documents" />
下一次部署有效。
我的问题是:
这是部署过程中的错误吗?
将环境变量注入配置文件的方法是否错误?
如果这样,正确的方法是什么?
任何帮助将不胜感激,我不喜欢硬编码东西,它总是会在以后的某个日子再次咬住你...
Any help would be appreciated, I don't like hard coding things, it invariably comes back to bite you at some future date...
推荐答案
如果要设置任何环境变量,请检查和。
If you are looking to set any environment variable, please check this and this (s2i script section).
基本上,您应该引入。 s2i / bin
文件夹放入代码库,它可以覆盖多组脚本并引入任何自定义代码。这类似于V2中的动作挂钩。
Basically, you should introduce .s2i/bin
folder into the codebase, which can have override multiple set of scripts and introduce any custom code. This is similar to action hooks in V2.
在这里,您可能希望在实际运行之前引入设置环境变量
。例如
Here, probably you wish to introduce setting environment variable
before actual run. e.g.
.s2i/bin/run script
#!/bin/bash
echo "Set environment variable before running application"
exec /usr/libexec/s2i/run
需要注意的几件事:
-
通过介绍脚本,它已被完全覆盖。如果您希望在代码后调用标准运行脚本,则必须调用该脚本。例如最后一行
/ usr / libexec / s2i / run
。
默认运行脚本调用应是最后一行。请不要指望控件返回执行之后的任何内容。
The default run script call should be the last line. Please do not expect the control to come back to execute anything written after that.
这篇关于OpenShift迁移-Conf文件中的ENV变量未像以前一样被替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!