如何将我的 Spray API 部署到生产环境中? [英] How to deploy my spray API into production?

查看:22
本文介绍了如何将我的 Spray API 部署到生产环境中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑如何将我已经在本地测试过的 rest api 部署到云的过程,比如说像亚马逊这样的基础设施即服务(而不是像 Heroku 这样的平台即服务).

I'm thinking about how should be the process to deploy my already locally tested rest api to the cloud, lets say an infrastructure as a service (not a platform as a service such as Heroku) like amazon.

我在本地环境中设置并运行了 sbt,但我的问题是我应该如何在生产环境中部署它?

I have my local envorinment set up with sbt up and running but my question is How should I deploy this in a production environment?

定义一个过程,在这个过程中,devops 从 git repo 中提取最新的更改,然后简单地执行 sbt run?

Is it sane to define a process in which the devops pulls the most recent changes from the git repo and then simply executes sbt run?

我想知道使用scala+spray+sbt的团队是如何将他们的api部署到生产环境的.

I want to know how does the teams that uses scala+spray+sbt deploys their apis to a production environment.

推荐答案

我们服务的核心是 scala + akka + Spray + mongo.所以我们使用 GitHub 进行版本控制.将已检查的 PR 合并到 master 分支后,Jenkins 会自动测试n"构建项目.如果所有测试都成功,那么 Jenking 会运行几个脚本:

The heart of our services is scala + akka + spray + mongo. So we are using GitHub for version control. After merging checked PRs to the master branch, Jenkins automaticaly tests'n'builds project. If all tests were successful then Jenking runs a couple of scripts:

  1. 增量项目版本(目前用shell编写,但会改成sbt)
  2. 使用 sbt-assembly
  3. 运行组装任务
  4. 运行部署脚本(用 Python 和 Fabric 编写)将我们的 jar 部署到 EC2

基本上在第三步,您有几个选择:

Basicaly on the thrid step you have a couple of choices:

使用 IO/Spray 启动文件制作一个可运行的 jar:

object Boot extends App {
  implicit val system = ActorSystem("ServiceName")
  val log = system.log
  val service = system.actorOf(Props[Service], name="serviceActor")
  IO(Http) ! Http.Bind(service, interface = host, port = port)
}

制作一个可运行的 jar 作为 Akka 的微内核:

在这种情况下,您应该扩展 Bootable trait 并覆盖 startupshutdown 方法:

In this case you should extend Bootable trait and override startup and shutdown methods:

class Kernel extends Bootable {
  // many lines of code
  def startup() {
    scheduler.start()
    SomeActorSystem.startup()
  }

  def shutdown() {
    scheduler.shutdown()
    SomeActorSystem.shutdown()
    system.shutdown()
  }
}

使用 TypeSafe 启动脚本:

无法显示示例,但它在 github =)

Can't show an example, but it has a good intro on github =)

我们在不同的情况下使用所有这些方式.

We are using all of this way in different cases.

这篇关于如何将我的 Spray API 部署到生产环境中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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