3

如何在 Jenkins 正在运行的同一台服务器上本地使用 Jenkins 自动部署 Play Framework (2.4) 应用程序?在某些时候,我们将单独设置一个适当的生产环境,并且可能会以相同的方式实现测试环境,但此时我想检查是否可以设置一个简单的测试环境到 Jenkins 正在运行的同一台服务器。

我有一个运行测试的 Jenkins 工作,它似乎工作正常。基本上是“执行外壳”运行激活器命令(可以合并到一行)。

./activator clean
./activator test

在 Play 1 中,我用play start&play stop来做类似的事情。尝试activator start我的开发环境,我收到消息:

The start command is deprecated, and will be removed in a future version of Play.
To run Play in production mode, run 'stage' instead, and then execute the generated start script in target/universal/stage/bin.
To test your application using production mode, run 'testProd' instead.

所以我用“执行外壳”和阶段评估了两个(不完整的)替代方案:

使用 nohup 暂存和运行:

./activator clean
./activator stage
nohup target/universal/stage/bin/my-app -Dplay.evolutions.db.default.autoApply=true

-> 应用程序启动正常,但 Jenkins 任务没有停止。

在后台使用 nohup 进行舞台和运行:

./activator clean
./activator stage
nohup target/universal/stage/bin/my-app -Dplay.evolutions.db.default.autoApply=true &

-> 应用程序似乎已经启动到某个时间点但没有继续运行?

这里首选(甚至唯一的工作)方式是什么?

4

3 回答 3

3

对于特定情况,我最终使用了 Docker:

  • 将 Docker 安装到服务器
  • 基于play-docker-ci创建了一个 Dockerfile
  • 将 Jenkins 配置为
    • 构建 Docker 镜像
    • 如果正在运行则停止现有容器,如果存在则删除现有容器
    • 运行 Docker 镜像

到目前为止,这似乎工作得很好。

于 2015-06-26T11:09:56.567 回答
2

Jenkins 在构建完成时会杀死所有子进程以避免内存泄漏,因此没有应用程序在运行。设置 jenkins 的最简单方法Playframework 2.4是使用sbttasks 和sbt plugin。如果您想从 jenkins 执行发布,最好的方法是构建debian 包并使用 jenkins shell 安装它 - 不会杀死任何进程。请参阅发布插件

于 2015-06-26T07:18:55.543 回答
0

我通过让 Team City 生成一个 startup.sh 脚本来设置它,该脚本包含将 Play 服务器作为后台进程启动的命令:

nohup /pathToApp/bin/app_name -Dhttp.port=8180 &

然后下一个构建步骤只是运行这个 shell 脚本并启动它。nohup&使它作为后台进程运行,当构建服务器断开连接时,它将继续运行。为了清楚起见,我从启动脚本中删去了很多额外的东西,但是您可以添加任何您想用于应用程序的启动参数。

于 2015-07-06T20:02:31.537 回答