How can I conditionally replace tokens in a config file with Capistrano or Phing?

倖福魔咒の 提交于 2019-12-10 11:42:06

问题


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.

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.

Is this possible in Capistrano? Or would I use something like Phing to do this?


回答1:


In Phing, if your deployment is Phing based, you could use the ReplaceTokens filter.

Example (not tested):

<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>


来源:https://stackoverflow.com/questions/9839081/how-can-i-conditionally-replace-tokens-in-a-config-file-with-capistrano-or-phing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!