summaryrefslogtreecommitdiff
path: root/crashbox-server/src/main/scala/io/crashbox/ci/Main.scala
blob: ae9499d6350fd72428ab7b2d6a8d0e9b5a721409 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package io.crashbox.ci

import scala.util.{Failure, Success}

import akka.http.scaladsl.Http
import scala.concurrent._
import scala.concurrent.duration._

object Main {

  implicit val core = new Core()
  import core._

  val storage = new Storage()
  val executor = new DockerExecutor
  val scheduler = new Scheduler(executor, storage)
  val api = new HttpApi(scheduler, storage)


  def main(args: Array[String]): Unit = {
    executor.reapDeadBuilds()
    Await.result(storage.setupDatabase(), 10.seconds)

    val host = config.getString("crashbox.host")
    val port = config.getInt("crashbox.port")
    Http(system).bindAndHandle(api.httpApi, host, port) onComplete {
      case Success(_) =>
        log.info(s"Listening on $host:$port")
      case Failure(ex) =>
        log.error(ex, s"Failed to bind to $host:$port")
        system.terminate()
    }
  }

}