I have a project that need to be deployed into multiple environments (prod, test, dev). The main differences mainly consist in configuration properties/files.
我有一个项目需要部署到多个环境(prod,test,dev)。主要区别主要在于配置属性/文件。
My idea was to use profiles and overlays to copy/configure the specialized output. But I'm stuck into if I have to generate multiple artifacts with specialized classifiers (ex: "my-app-1.0-prod.zip/jar", "my-app-1.0-dev.zip/jar") or should I create multiple projects, one project for every environment ?!
Should I use maven-assembly-plugin to generate multiple artifacts for every environment ? Anyway, I'll need to generate all them at once so it seams that the profiles does not fit ... still puzzled :(
我的想法是使用配置文件和覆盖来复制/配置专用输出。但是如果我必须使用专门的分类器生成多个工件(例如:“my-app-1.0-prod.zip/jar”,“my-app-1.0-dev.zip/jar”)或者我应该为每个环境创建多个项目,一个项目?!我应该使用maven-assembly-plugin为每个环境生成多个工件吗?无论如何,我需要一次生成所有这些,所以它接缝的配置文件不适合...仍然困惑:(
Any hints/examples/links will be more than welcomed.
任何提示/示例/链接都将受到欢迎。
As a side issue, I'm also wondering how to achieve this in a CI Hudson/Bamboo to generate and deploy these generated artifacts for all the environments, to their proper servers (ex: using SCP Hudson plugin) ?
作为一个侧面问题,我也想知道如何在CI Hudson / Bamboo中实现这一点,以便为所有环境生成和部署这些生成的工件,并将其部署到适当的服务器上(例如:使用SCP Hudson插件)?
6 个解决方案
#1
10
I prefer to package configuration files separately from the application. This allows you to run the EXACT same application and supply the configuration at run time. It also allows you to generate configuration files after the fact for an environment you didn't know you would need at build time. e.g. CERT I use the "assembly" tool to zip up each domain's config files into named files.
我更喜欢将配置文件与应用程序分开打包。这允许您运行EXACT相同的应用程序并在运行时提供配置。它还允许您在事实之后为您在构建时不需要的环境生成配置文件。例如CERT我使用“汇编”工具将每个域的配置文件压缩成命名文件。
#2
2
I would use the version
element (like 1.0-SNAPSHOT, 1.0-UAT, 1.0-PROD) and thus tags/branches at the VCS level in combination with profiles (for environments specific things like machines names, user name passwords, etc), to build the various artifacts.
我会使用版本元素(如1.0-SNAPSHOT,1.0-UAT,1.0-PROD),因此在VCS级别标记/分支与配置文件(用于特定环境,如机器名称,用户名密码等),构建各种工件。
#3
1
We implemented a m2 plugin to build the final .properties using the following approach:
我们使用以下方法实现了m2插件来构建最终的.properties:
- The common, environment-unaware settings are read from common.properties.
- 从common.properties读取常见的,不知道环境的设置。
- The specific, environment-aware settings are read from dev.properties, test.properties or production.properties, thus overriding default values if necessary.
- 从dev.properties,test.properties或production.properties读取特定的环境感知设置,从而在必要时覆盖默认值。
- The final .properties files is written to disk with the Properties instance after reading the files in given order.
- 在按给定顺序读取文件后,最终的.properties文件将使用Properties实例写入磁盘。
- Such .properties file is what gets bundled depending on the target environment.
- 这样的.properties文件是根据目标环境捆绑的内容。
#4
0
We use profiles to achieve that, but we only have the default profile - which we call "development" profile, and has configuration files on it, and we have a "release" profile, where we don't include the configuration files (so they can be properly configured when the application is installed).
我们使用配置文件来实现这一点,但我们只有默认配置文件 - 我们称之为“开发”配置文件,并且配置文件,我们有一个“发布”配置文件,我们不包含配置文件(所以可以在安装应用程序时正确配置它们。
I would use profiles to do it, and I would append the profile in the artifact name if you need to deploy it. I think it is somewhat similar to what Pascal had suggested, only that you will be using profiles and not versions.
我会使用配置文件来执行此操作,如果需要部署它,我会将配置文件附加到工件名称中。我认为它有点类似于Pascal所建议的,只是你将使用配置文件而不是版本。
PS: Another reason why we have dev/ release profiles only, is that whenever we send something for UAT or PROD, it has been released, so if there is a bug we can track down what the state of the code was when the application was released - it is easier to tag it in SVN than trying to find its state from the commit history.
PS:我们只有开发/发布配置文件的另一个原因是,无论何时我们发送UAT或PROD的东西,它都已被释放,所以如果有错误,我们可以追踪应用程序时代码的状态。已发布 - 在SVN中标记它比在提交历史记录中查找状态更容易。
#5
0
I had this exact scenario last summer.
去年夏天我有这个确切的情景。
I ended up using profiles for each higher environment with classifiers. Default profile was "do no harm" development build. I had a DEV, INT, UAT, QA, and PROD profile.
我最终使用分类器为每个更高的环境使用配置文件。默认配置文件是“do no harm”开发版本。我有一个DEV,INT,UAT,QA和PROD配置文件。
I ended up defining multiple jobs within Hudson to generate the region specific artifacts.
我最终在Hudson中定义了多个作业来生成区域特定的工件。
The one thing I would have done differently was to architect the projects a bit differently so that the region specific build was outside of the modularized main project. That was it would simply pull in the lastest artifacts for each specific build rather than rebuild the entire project for each region.
我不同的一件事就是以不同的方式构建项目,以便区域特定的构建不在模块化的主项目中。那就是它只是为每个特定的构建引入最新的工件,而不是为每个区域重建整个项目。
In fact, when I setup the jobs, the QA and PROD jobs were always setup to build off of a tag. Clearly this is something that you would tailor to your specific workplace rules on deployment.
实际上,当我设置作业时,QA和PROD作业总是设置为构建标记。显然,您可以根据部署的特定工作场所规则进行定制。
#6
0
Try using https://github.com/khmarbaise/multienv-maven-plugin to create one main WAR and one configuration JAR for each environment.
尝试使用https://github.com/khmarbaise/multienv-maven-plugin为每个环境创建一个主WAR和一个配置JAR。
#1
10
I prefer to package configuration files separately from the application. This allows you to run the EXACT same application and supply the configuration at run time. It also allows you to generate configuration files after the fact for an environment you didn't know you would need at build time. e.g. CERT I use the "assembly" tool to zip up each domain's config files into named files.
我更喜欢将配置文件与应用程序分开打包。这允许您运行EXACT相同的应用程序并在运行时提供配置。它还允许您在事实之后为您在构建时不需要的环境生成配置文件。例如CERT我使用“汇编”工具将每个域的配置文件压缩成命名文件。
#2
2
I would use the version
element (like 1.0-SNAPSHOT, 1.0-UAT, 1.0-PROD) and thus tags/branches at the VCS level in combination with profiles (for environments specific things like machines names, user name passwords, etc), to build the various artifacts.
我会使用版本元素(如1.0-SNAPSHOT,1.0-UAT,1.0-PROD),因此在VCS级别标记/分支与配置文件(用于特定环境,如机器名称,用户名密码等),构建各种工件。
#3
1
We implemented a m2 plugin to build the final .properties using the following approach:
我们使用以下方法实现了m2插件来构建最终的.properties:
- The common, environment-unaware settings are read from common.properties.
- 从common.properties读取常见的,不知道环境的设置。
- The specific, environment-aware settings are read from dev.properties, test.properties or production.properties, thus overriding default values if necessary.
- 从dev.properties,test.properties或production.properties读取特定的环境感知设置,从而在必要时覆盖默认值。
- The final .properties files is written to disk with the Properties instance after reading the files in given order.
- 在按给定顺序读取文件后,最终的.properties文件将使用Properties实例写入磁盘。
- Such .properties file is what gets bundled depending on the target environment.
- 这样的.properties文件是根据目标环境捆绑的内容。
#4
0
We use profiles to achieve that, but we only have the default profile - which we call "development" profile, and has configuration files on it, and we have a "release" profile, where we don't include the configuration files (so they can be properly configured when the application is installed).
我们使用配置文件来实现这一点,但我们只有默认配置文件 - 我们称之为“开发”配置文件,并且配置文件,我们有一个“发布”配置文件,我们不包含配置文件(所以可以在安装应用程序时正确配置它们。
I would use profiles to do it, and I would append the profile in the artifact name if you need to deploy it. I think it is somewhat similar to what Pascal had suggested, only that you will be using profiles and not versions.
我会使用配置文件来执行此操作,如果需要部署它,我会将配置文件附加到工件名称中。我认为它有点类似于Pascal所建议的,只是你将使用配置文件而不是版本。
PS: Another reason why we have dev/ release profiles only, is that whenever we send something for UAT or PROD, it has been released, so if there is a bug we can track down what the state of the code was when the application was released - it is easier to tag it in SVN than trying to find its state from the commit history.
PS:我们只有开发/发布配置文件的另一个原因是,无论何时我们发送UAT或PROD的东西,它都已被释放,所以如果有错误,我们可以追踪应用程序时代码的状态。已发布 - 在SVN中标记它比在提交历史记录中查找状态更容易。
#5
0
I had this exact scenario last summer.
去年夏天我有这个确切的情景。
I ended up using profiles for each higher environment with classifiers. Default profile was "do no harm" development build. I had a DEV, INT, UAT, QA, and PROD profile.
我最终使用分类器为每个更高的环境使用配置文件。默认配置文件是“do no harm”开发版本。我有一个DEV,INT,UAT,QA和PROD配置文件。
I ended up defining multiple jobs within Hudson to generate the region specific artifacts.
我最终在Hudson中定义了多个作业来生成区域特定的工件。
The one thing I would have done differently was to architect the projects a bit differently so that the region specific build was outside of the modularized main project. That was it would simply pull in the lastest artifacts for each specific build rather than rebuild the entire project for each region.
我不同的一件事就是以不同的方式构建项目,以便区域特定的构建不在模块化的主项目中。那就是它只是为每个特定的构建引入最新的工件,而不是为每个区域重建整个项目。
In fact, when I setup the jobs, the QA and PROD jobs were always setup to build off of a tag. Clearly this is something that you would tailor to your specific workplace rules on deployment.
实际上,当我设置作业时,QA和PROD作业总是设置为构建标记。显然,您可以根据部署的特定工作场所规则进行定制。
#6
0
Try using https://github.com/khmarbaise/multienv-maven-plugin to create one main WAR and one configuration JAR for each environment.
尝试使用https://github.com/khmarbaise/multienv-maven-plugin为每个环境创建一个主WAR和一个配置JAR。