vazand / proverb-app

sbt playframework docker image example with OpenJDK:11-jre

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

App info

This is a proverb app. currently it contains 11 positive proverbs. we can get a random solo proverb using (GET /) and can get all of them using (GET /proverbs) as Json.

SBT docker packaging

Here I have used sbt-native-packager for docker packaging, I'm using playframework so it's already configured.

To build the image you can use:

Terminal

sbt

in sbt console

> compile
> Docker / stage
> Docker / publishLocal

This will create a local docker image with name packageName+version

important env's (For production version )

>APPLICATION_SECRET
>HTTP_PORT

for setting docker env variables we can use like this (in build.sbt)

dockerEnvVars ++= Map( ("APPLICATION_SECRET", "mysecretKey1234567890-!@#$%^&*()_"), ("HTTP_PORT", "9500") )

Notes:

here we're declared APPLICATION_SECRET as an env and you can see it in the build.sbt but it's not a good Idea when creating a production version from this docker image. when creating production version of docker image from this, delete the APPLICATION_SECRET from dockerEnvVars in build.sbt. and when running the image we have to declare that environment variable. ex: docker run -it -p80:9500 -e APPLICATION_SECRET=sdfasdfHEGSHDKSDKSDHKHSKDKSDSKJDSJDHHSDSAHAHAH --name=proverbContainer proverb-app:1.0.1

other docker configs (in build.sbt)

dockerBaseImage := "openjdk:11-jre"

Docker / packageName := "proverb-app"

For running the app using docker

docker run --rm -p 9500:9500 --name myProverbApp proverb-app:1.0.1

here,

  • --rm will remove the container when exit.
  • ImageName -> proverb-app:1.0.1
  • ContainerName -> myProverbApp

Continuous Integration Continuous Deployment(CICD)

Here I'm using Jenkins for automating the CICD Continuous Integration(CI) Steps:

> Build
> Test
> Package
> Storing Package (ex: docker hub/nexus,github)

Continuous Deployment(CD):

> Get package From Storage (ex: docker hub/nexus,github)
> Publish to Production Environment

About

sbt playframework docker image example with OpenJDK:11-jre


Languages

Language:Scala 88.2%Language:HTML 10.6%Language:Shell 1.2%