https://github.com/hypertino/service-template
Scala dockerized service template with configuration, DI, logging, graceful shutdown, etc
https://github.com/hypertino/service-template
dockerized scala service-template
Last synced: 11 months ago
JSON representation
Scala dockerized service template with configuration, DI, logging, graceful shutdown, etc
- Host: GitHub
- URL: https://github.com/hypertino/service-template
- Owner: hypertino
- Created: 2018-02-08T15:40:44.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-02-09T15:51:10.000Z (about 8 years ago)
- Last Synced: 2025-02-06T11:57:14.058Z (about 1 year ago)
- Topics: dockerized, scala, service-template
- Language: Scala
- Homepage:
- Size: 13.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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
## [service-config](https://github.com/hypertino/service-config)
Enables configuration file where different environments specified within a single file.
See example in [application.conf](src/main/resources/application.conf)
Also adds transitive dependency to [TypeSafe Config](https://github.com/lightbend/config)
## [typesafe-config-binders](https://github.com/hypertino/typesafe-config-binders)
Read configuration to case class, example in [ExampleService.scala](src/main/scala/com/hypertino/example/ExampleService.scala)
```scala
import com.hypertino.binders.config.ConfigBinders._
private val exampleConfig = config.read[ExampleConfig]("example-service")
```
## [service-control](https://github.com/hypertino/service-control)
Provides basic `Service` interface, simple command-line with default `quit` command and shutdown hook for graceful shutdown.
See example with in [EntryPoint.scala](src/main/scala/com/hypertino/example/EntryPoint.scala)
Also adds transitive dependency to [Scaldi](http://scaldi.org/)
## [logback](https://logback.qos.ch/) with logstash backend + [scala-logging](https://github.com/typesafehub/scala-logging)
Configure in [logback.xml](src/main/resources/logback.xml), [logback-qa.xml](src/main/resources/logback-qa.xml), [logback-prod.xml](src/main/resources/logback-prod.xml)
and add more target environment log files if needed.
## [sbt-buildinfo](https://github.com/sbt/sbt-buildinfo) plugin
Provides compile-time access to build information.