问题描述
我想尝试使用Capistrano部署一个PHP应用程序,但看不到用于替代不同环境的配置文件中的令牌的选项。
I would like to try out Capistrano to deploy a PHP application but can't see an option for replacing tokens in config files for different environments.
我是使用Slim微框架,它只是在index.php中使用一个数组来配置数据库用户名等变量。我想在那里将令牌,如%dbuser%,在部署时将根据是否部署到分段或生产。
I'm using the Slim microframework which just uses an array in index.php for config variables like database username etc. I would like to put tokens such as %dbuser% in there which would be replaced at deploy time based on whether I am deploying to staging or production.
这是否可能在Capistrano?或者我会像Phing这样做吗?
Is this possible in Capistrano? Or would I use something like Phing to do this?
推荐答案
在Phing中,如果您的部署是Phing,您可以使用。
In Phing, if your deployment is Phing based, you could use the ReplaceTokens filter.
示例:
<target name="-modify-config"
hidden="true" description="Modifies the xyz.conf ">
<copy file="${some.directory}/xyz.conf.dist"
tofile="${some.directory}/xyz.conf"
overwrite="true" >
<filterchain>
<replacetokens begintoken="%" endtoken="%">
<token key="KEY_A" value="${value.a}" />
<token key="KEY_B" value="${value.b}" />
</replacetokens>
</filterchain>
</copy>
</target>
这篇关于如何用Capistrano或Phing有条件地替换配置文件中的令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!