使用构建部署到生产的最简单的方法 [英] The simplest way to deploy to production with builds

查看:193
本文介绍了使用构建部署到生产的最简单的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须承认,在世界上生活在怪异的debuild / ant / makefile嵌合体结构的世界之后,我是新来的魔鬼世界。我只是没有这样的感觉,这有助于经验丰富的开发人员选择正确的决定,而且看起来像在maven中有很多不同的方式。



所以,我有一个包含网络应用程序的简单项目。
我想基本上遵循:




  • 部署到开发Tomcat(我正在使用tomcat:deploy),然后什么都不做。 / li>
  • 部署到生产Tomcat,但部署之前 更新git repo,添加标记的提交和升级版本。



为了区分开发和生产,我创建了个人资料, dev 。默认情况下激活 dev 配置文件。当我想部署某些东西到生产中时,我只需键入 mvn -P prod tomcat:deploy



阅读关于版本插件,以及关于buildnumber插件。
但我只是不知道我要走正确的路。



所以,问题是 - 最重要的是什么是最自成体系的mavenish的方式来解决我正在询问的任务。 b $ b

解决方案

Shabunk,正如我被评论的那样,Maven正在推动你做最好的方式,从多年的开发经验中继承。 / p>

我会解释我会(和我自己真正的)做什么。



所以你是对的使用Maven Release Plugin,另加一个(例如货物)
您正在尝试两种不同的事情:




  • 识别一个独特的版本,这意味着标记它,并更新新版本的pom

  • 部署应用程序(无论是哪种环境)






Maven发布插件


$ b $考虑到你自己的进程可能比其他开发团队习惯了。我的意思是在更大的团队(Q& A,用户接受度,非回归调查)中,单元测试和生产部署之间有更多的步骤。看来,您创建了一个链接标签和生产部署的快捷方式。
如果要在不同的环境(集成,用户接受度,性能,preprod等)上部署webapp,您必须确定您的版本,并且必须能够再次构建(确定和可重复)



那个maven-release-plugin是什么意思。它可以帮助您验证源代码是否干净(源代码控制下的所有文件,无需修改),可以编译并通过所有测试阶段。然后,它处理pom版本和标记,并通过存储以备后续使用Maven企业版存储库。



您有很多配置可以设置(ditributionManagement,SCM ,maven插件发行配置)。但一旦到位,发布版本就在一个简单的命令行中:

  mvn release:prepare release:perform 

如果你想要一些例子,我可以给你一些。

 < scm> 
<! - 基本URL存储库 - >
< url> scm:svn:http://svn.myorg.corp/svn/repository/< / url>
<! - 开发者网址(来自中继或分支) - >
< developerConnection> scm:svn:http://svn.myorg.corp/svn/repository/trunk/project1< / developerConnection>
< connection> scm:svn:http://svn.myorg.corp/svn/repository/trunk/project1< / connection>


< / scm>
< build>
< plugins>
< plugin>
< groupId> org.apache.maven.plugins< / groupId>
< artifactId> maven-scm-plugin< / artifactId>
< version> 1.6< / version>
< configuration>
< username> $ {from.settings.xml.user}< / username>
< password> $ {from.settings.xml.password}< / password>
< / configuration>
< / plugin>

< plugin>
< groupId> org.apache.maven.plugins< / groupId>
< artifactId> maven-release-plugin< / artifactId>
< version> 2.2.2< / version>
< configuration>
< tagBase> http://svn.myorg.corp/svn/repository/tags/< / tagBase>
< scmCommentPrefix> [DEV#SCM]< / scmCommentPrefix>
< / configuration>
< / plugin>
< / plugins>
[...]
< / build>
< distributionManagement>
< repository>
< id> enterprise_repo< / id>
< name> Entifrise Rifory on Artifactory - 稳定版本< / name> < URL> HTTP://repo.corp:8080 / artifactory的/ PRJ-XXX-版本< / URL>
< / repository>
< snapshotRepository>
< id> enterprise_repo< / id>
< name> Entifrise Repository on Artifactory - DEV版本< / name>
< url> http://repo.corp:8080 / artifactory / prj-xxx-snapshots< / url>
< / snapshotRepository>
< site>
< id> corporate_site< / id>
< name>企业公共网站< / name>
<! - 必须添加支持该协议的wagon插件 - >
< url> ftp://...< / url>

< / site>
< / distributionManagement>






部署



再次,您可能会有多个环境,您可以根据需要测试您的应用。
有许多插件允许你发送和部署你的战争:一般的货物插件,或更具体的一些tomcat-plugin,glassfish-plugin,...插件给你的可能性做你想要的。然后,可以通过多种方式执行配置。



Full Maven方式:
与Maven完全集成的方式是使用Profile也许过滤器。个人资料可以描述自己和行为,你似乎知道。过滤器是一种.properties,将一组变量分组,该变量将用于将xml配置文件中的模式替换为war(例如,db连接)。这不是我使用的,因为我发现它比外部化文件更不灵活。但是无论如何,无论是在生态系统中,还是使用Maven:
我喜欢的方式是使用Maven和Jenkins来构建我的应用程序(或者连续的集成工具)。这就是为什么我同意亚伦,他说你必须克服你的工具的局限性。使用詹金斯,我运行每个小时/天我的应用程序反对单元测试,生成Q& A报告,文档... ...我有一个发布版本,帮助我生产所有我想提供(我的测试团队或我的客户),我向我的工作提供一些信息,以将其部署到不同的环境中(使用maven配置文件或jenkins内置配置)。



它对我来说很好,我很确定这是正确的做法。








部署



再次,部署意味着生命周期的不同阶段。 p>

本地/开发环境



我永远不会使用tomcat:deploy直到现在,但只因为我更喜欢使用jetty作为轻网容器(并且与maven集成)。但是我确信每一个配置都可以满足您的需求。



持续集成环境
在不断的整合环境,我通常直接与Jenkins(出口* .war在所需的机器)复制战争。我的方式取决于许多事情:




  • 如果CI软件与您的应用服务器(Tomcat)相同(物理|虚拟)服务器,Jboss,Weblogic,Glassfish,...),或远程的=复制时间将显示服务器刷新时间,并将产生不安全的部署(通常损坏的归档)

  • 如果服务器支持热重新加载(Tomcat的网络应用程序爆炸式战争)或至少意识到文件系统修改(JBoss全面战争/部署)

  • 如果您需要在...之前停止服务器。



大多数时候,这是一个简单的副本。如果我不能,我使用一些集成的maven插件(如jahia:部署插件为着名的CMS:www.jahia.com),或只是货物插件: http://cargo.codehaus.org/Maven2+plugin 。我没有任何的例子,但是很容易找到一些互联网,因为这个配置是经常被推荐的。



Q& A / Acceptance / Production environnement



对于那些经常(到目前为止,我在工作中看到的)环境,处理服务级别协议,我们(我或管理团队)写了一些特定的脚本。我相信你会失望,但正如我所说,我不依赖Maven的一切,特别是部署。
IMHO,这是这个工具的一个限制。您可以依靠货物插件或特定的插件,但是发布版本或构建版本与实际部署不符(按时间顺序)。更重要的是,我没有找到允许我轻松部署多个实例的任何插件,甚至值得你不得不以特定的顺序关闭实例(SLA的需要)。
说,我没有提到外部属性,或SQL脚本,或其他任何东西。它们是依靠专用工具的其他原因。



所以,一般来说,我们编写了我们自己的ant / sell脚本。如果其他人有更好的解决方案,我明显被干扰了!



我希望我足够清楚。



请问。


I must confess I'm new to maven world after years of living in the world of monstrous debuild/ant/makefile chimeric constructions. I just don't have yet that very feeling which helps seasoned developer to choose right decisions, and it's looks like there are plenty different ways in maven.

So, I have a simple project containing of web-app. I want basically following:

  • deploy to development Tomcat (I'm using tomcat:deploy), then do nothing.
  • deploy to production Tomcat, but before deployment update git repo, add tagged commit and upgrade build version.

For distinguishing between development and production I've created profiles, dev and prod. The dev profile is activated by default. When I want to deploy something to production, I just type mvn -P prod tomcat:deploy

I've read about release plugin, as well as about buildnumber plugin. But I'm just not sure I'm going the right way.

So, the question is - what is the most succint, self-contained and "mavenish" way to resolve the task I'm asking about.

解决方案

Shabunk, as I was commented out, Maven is driving you on the best way to do what you want, inheriting from years of developpers experience.

I would explain what I would (and what I myself really) do.

So you're right to use Maven Release Plugin, plus another one (cargo for instance) You're trying to do two differents things :

  • Identifying a unique version, which means tagging it, and updating pom for a new version
  • Deploying your app (no matter which environnement it is)

Maven Release Plugin

Consider that your own process is maybe ligher than other dev teams are used to. I mean that there is more steps between unit testing and production deployment in larger teams (Q&A, user acceptance, non regression campains). It seems that you make a shortcut linking tag and production deployement. If you want to deploy your webapp on different environnements (integration, user acceptannce, performance, preprod, and so on) you had to identify your version and had to be able to build it again (sure and "repeatable").

That what maven-release-plugin is intended to. It helps you to verify that your source code is clean (all files under source control, with no modification), can compile and pass all tests phases. Then, it deals with pom version and tagging, and finish by storing it for later use in you Maven enterprise repository.

You have many configurations to set up (ditributionManagement, SCM, maven plugin release configuration). But once it is in place, releasing version stand in one simple command line :

mvn release:prepare release:perform

If you want some examples, I can give you some.

<scm>
    <!-- Base URL repository -->
    <url>scm:svn:http://svn.myorg.corp/svn/repository/</url>
    <!-- Developper URL (from trunk or branche) -->
        <developerConnection>scm:svn:http://svn.myorg.corp/svn/repository/trunk/project1</developerConnection>
  <connection>scm:svn:http://svn.myorg.corp/svn/repository/trunk/project1</connection>


</scm>
<build>
    <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-scm-plugin</artifactId>
                <version>1.6</version>
                <configuration>
            <username>${from.settings.xml.user}</username>
            <password>${from.settings.xml.password}</password>
                </configuration>
    </plugin>

    <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.2.2</version>
                <configuration>
                <tagBase>http://svn.myorg.corp/svn/repository/tags/</tagBase>
            <scmCommentPrefix>[DEV#SCM]</scmCommentPrefix>
        </configuration>
    </plugin>
</plugins>
    [...]
</build>
<distributionManagement>
    <repository>
        <id>enterprise_repo</id>
        <name>Enteprise Repository on Artifactory - Stable versions</name>      <url>http://repo.corp:8080/artifactory/prj-xxx-releases</url>
    </repository>
    <snapshotRepository>
        <id>enterprise_repo</id>
        <name>Enteprise Repository on Artifactory - DEV versions</name>
        <url>http://repo.corp:8080/artifactory/prj-xxx-snapshots</url>
    </snapshotRepository>
    <site>
        <id>corporate_site</id>
        <name>Corporate public site</name>
        <!-- must add wagon plugin that support this protocol -->
        <url>ftp://...</url>

    </site>
</distributionManagement>


Deployement

Once again, you may have multiple environnements on which you want to test your app against. There is many plugins that allow you to send and deploy your war : the general cargo-plugin, or more specific ones tomcat-plugin, glassfish-plugin, ... Plugins are giving you the hability to do what you want. Then, configuration can be performed in many ways.

Full Maven way : The full integrated way with Maven is to use Profile and maybe Filters. Profiles let describe properites and behaviour, as you seem to know. Filters are kind of .properties grouping a set of variable that will be used to replace patterns in you xml configuration file into the war (for instance, db connection). It's not the one I use because I find it less flexible than externalizing files. But no matter

Maven with its ecosystem: The way I prefer is to build my apps with Maven and Jenkins (or Continous Integration tool). This is why I'm agree with Aaron when he says that you had to konw limitations of your tools. Using Jenkins, I run every hours/day my application against Unit Tests, generatio Q&A reports, documentation, ... I have a release build that help me to produce all I want to deliver it (to my test team or my customer), and I provide some information to my jobs to deploy it onto different environnements (using maven profiles or jenkins built-in configuration).

It works really fine for me, and I'm pretty sure this is the right way to do.

[EDIT]


Deployment

Once again, deployment mean different phases of Lifecycle.

Local / Dev environnement

I'd never use tomcat:deploy until now, but only because I'd prefer using jetty as light web container (and well integrated with maven). But I'm pretty sure that every kinf of configuration would fit your needs here.

Continuous Integration Environnement In an continous integration environnement, I usually copy the war directly with Jenkins (exporting *.war on the desired machine). The way I do depends on many things :

  • if CI soft is on the same (physical|virtual) server than your app server (Tomcat, Jboss, Weblogic, Glassfish, ...), or distant one => copy time will outstand server refresh time and will produce unsafe deployement (generally corrupted archives)
  • if server is supporting hot reloading (exploded war in web-apps for Tomcat) or at least aware of file system modifications (full war in /deploy for JBoss)
  • if you need to stop your server before, ...

Most of time, it's a simple copy. If I can't, I use some integrated maven plugins (like jahia:deploy plugin for the famous CMS : www.jahia.com), or just cargo plugin : http://cargo.codehaus.org/Maven2+plugin. I don't have any example, but it's really easy to find some on internet because this configuration is often recommanded.

Q&A / Acceptance / Production environnement

For those kind of environnements, which often (as far I as I saw in my job) deals with Service Level Agreement, we (I or admin team) wrote some specific scripts. I'm sure you will be desapointed, but as I mentionned, I don't rely on Maven for everything, and for deployement in particular. IMHO, this is one limit of this tool. You can maybe rely on cargo plugin, or specific ones, but releasing a version, or building one don't match (in time sequence) with real deployement. Even more, I didn't find any plugin that allow me easily to deploy on multiple instances ... and even worth you had to shutdown instances in a specific order (SLA's needs). That said, I didn't mentionned external properties, or SQL scripts, or anything else. They are additional reasons to rely on a dedicated tool.

So, generally, we wrote our own ant / sell scripts. If somebody else have better solutions, I'm obviously interrested in !

I hope I was clear enough.

Regards.

这篇关于使用构建部署到生产的最简单的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆