Skip to content

Scala dockerized service template with configuration, DI, logging, graceful shutdown, etc

Notifications You must be signed in to change notification settings

hypertino/service-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

service-template

Service template/example with logging, docker packaging, configuration handling and dependency injection. This template utilizes concept of target environment, e.g. qa, stage, prod, local, etc. Target environment should be provided to the service as TARGET_ENV environment variable or targetEnv java system property. If not provided local environment is assumed.

Howto

Build docker image: sbt docker

Build & run on host with target environment:

sbt ';set fork := true; set connectInput in run := true; set javaOptions ++= Seq("-DtargetEnv=qa"); run'

Run in docker as background daemon:

docker run -d --name example-service -e TARGET_ENV=qa com.hypertino/service-template:latest

Run interactively in docker and remove after it stops:

docker run -it --rm -e TARGET_ENV=qa com.hypertino/service-template:latest

Quick run with docker-compose

TARGET_ENV=qa docker-compose up

Dependencies

Enables configuration file where different environments specified within a single file. See example in application.conf

Also adds transitive dependency to TypeSafe Config

Read configuration to case class, example in ExampleService.scala

  import com.hypertino.binders.config.ConfigBinders._
  private val exampleConfig = config.read[ExampleConfig]("example-service")

Provides basic Service interface, simple command-line with default quit command and shutdown hook for graceful shutdown. See example with in EntryPoint.scala

Also adds transitive dependency to Scaldi

logback with logstash backend + scala-logging

Configure in logback.xml, logback-qa.xml, logback-prod.xml and add more target environment log files if needed.

Provides compile-time access to build information.

About

Scala dockerized service template with configuration, DI, logging, graceful shutdown, etc

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages