playframework-2.0 - 在 cloudbees 上部署时如何为用户指定哪个 application.conf

标签 playframework-2.0 cloudbees

我按照这里的说明 https://developer.cloudbees.com/bin/view/RUN/Playframework并且可以部署。但它只使用application.conf。

我的应用 ID 是“mrm”,所以我在 conf 目录中创建了一个“mrm.conf”。

然后我尝试了“play cloudbees-deploy-config mrm”,但在部署后我收到以下错误消息:

[success] Total time: 110 s, completed Mar 15, 2013 9:08:36 PM
[error] Not a valid command: mrm (similar: run)
[error] Expected '/'
[error] Expected ':'
[error] Not a valid key: mrm (similar: run)
[error] mrm

并且部署仍然使用application.conf

然后我运行play,输入:“cloudbees-deploy-config mrm”我没有错误,但是这种方式也部署了application.conf

我的“mrm.conf”包含以下内容:
include "application.conf"
cloudbees.applicationId=mrm

我尝试按照此拉取请求中描述的说明进行操作:
https://github.com/CloudBees-community/sbt-cloudbees-play-plugin/pull/1

根据 play help 应该是这样的:
cloudbees-deploy-config

  Deploy a configuration of your app to a Run@Cloud app id. Arguments are:
  (1) the base name of a conf file in your project's conf directory, defaulting to     "application"/
  (2) Optional. The application id to which this configuration should deploy. You can omit this
      arg if you have either set cloudbees.applicationId in the config file from the first
      arg or have set the project ID in your PlayProject.

  Example usage: `> cloudbees-deploy-config live`, where live.conf exists in the project's conf/
  directory and contains a key cloudbees.applicationId.

关于我可能做错的任何提示?我需要它在 cloudbees 部署中使用 mrm.conf ......

回答:
play "cloudbees-deploy-config mrm"

更新:刚刚在我的博客上发布了解决方案的摘要:http://www.poornerd.com/2013/04/08/how-deploy-play-framework-apps-with-different-configurations-to-cloudbees/

最佳答案

如何在 CloudBees 上调整应用程序/框架的配置因框架而异。您需要使用的基本技术是:

  • 弄清楚在本地运行时如何告诉您的应用程序加载此备用配置文件
  • 弄清楚如何让 CloudBees 在启动应用程序时做同样的事情

  • 加载备用 Play 配置文件

    基于ConfigurationProductionConfiguration在 Play2 站点上的文档中,您似乎可以指定 -Dconfig.resource=CONF_FILENAME 系统属性来告诉 Play2 加载您的替代配置:

    Using -Dconfig.resource

    It will search for an alternative configuration file in the application classpath (you usually provide these alternative configuration files into your application conf/ directory before packaging).

     $ start -Dconfig.resource=prod.conf
    


    基于此,我们现在知道如何告诉您的运行时框架(Play)加载备用配置文件。接下来,我们需要弄清楚让 CloudBees 做同样的事情。

    在 CloudBees 上设置系统属性

    CloudBees SDK包括setting configuration parameters 的命令行选项对于将在启动期间作为系统属性(对于基于 JVM 的应用程序)注入(inject)的应用程序。这可以通过在 app:deploy 命令行上指定 -Pname=value 选项来完成,或者您可以改用 config:set 命令。

    由于您使用 SBT 插件来部署您的应用程序(可能不支持此功能),因此使用 SDK 的 config:set 命令可能是最简单的:
    bees config:set -a APPID config.resource=mrm.conf
    

    注意:您需要重新启动应用程序才能应用此配置参数

    如果我正确理解 Play2 文档,这应该会导致 Play 在 conf/mrm.conf 中加载配置文件。

    更简单的解决方案? - 只需覆盖 key

    根据您的示例,我注意到您似乎试图仅覆盖默认 application.conf 文件中特定配置键的值...

    看戏ProductionConfiguration docs,似乎覆盖整个配置文件可能是矫枉过正,而您可以简单地使用系统属性指定要覆盖的值。 CloudBees SDK config:set命令专为此用例而设计,并为您提供了一种简单的方法来注入(inject)自定义应用程序参数。 CloudBees 上基于 Java 的堆栈会将这些参数作为系统属性注入(inject),这意味着它们应该由您的 Play 应用程序自动获取。

    根据您的 mrm.conf 文件中的示例覆盖,以下内容应该有效:
    bees config:set -a APPID cloudbees.applicationId=mrm
    

    如果这对您有效,我会将其中一些信息添加回 CloudBees Play文档。

    关于playframework-2.0 - 在 cloudbees 上部署时如何为用户指定哪个 application.conf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15441628/

    相关文章:

    database - Slick 不在 h2 数据库中输入数据

    jpa-2.0 - Play Framework 中的 JPA 2.0 和 @Type 注解

    java - Play/Akka 与 Java OutputStreams 的集成

    java - Play Framework - 表单的多个实例

    java - CloudBees 的 JMS 代理选项?

    java - 是否可以将 glassfish 与 cloudbees 一起使用?

    CloudBees 的沙箱/JRE 限制?

    java - Play JSON : How to use string as proper json

    build - Cloudbees 上的 Redis 版本已过时?