Skip to content

Commit

Permalink
allow custom setup for ES, plus Docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
fredex42 committed Nov 10, 2023
1 parent 485fc68 commit 77b280b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
4 changes: 3 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
enablePlugins(DebianPlugin, JavaServerAppPackaging, SystemdPlugin)
enablePlugins(DebianPlugin, JavaServerAppPackaging, SystemdPlugin, DockerPlugin, AshScriptPlugin)

ThisBuild / version := "0.1.0"

Expand All @@ -14,6 +14,7 @@ val prometheusVersion = "0.16.0"
lazy val root = (project in file("."))
.settings(
name := "concierge-graphql",
dockerBaseImage := "amazoncorretto:17-alpine",
libraryDependencies ++= Seq(
"org.http4s" %% "http4s-core" % "0.23.21",
"org.http4s" %% "http4s-dsl" % "0.23.21",
Expand Down Expand Up @@ -48,3 +49,4 @@ lazy val root = (project in file("."))
"io.netty" % "netty-codec-http" % "4.1.94.Final",
)
)

16 changes: 16 additions & 0 deletions src/main/scala/ElasticSearchResolver.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import com.sksamuel.elastic4s.ElasticNodeEndpoint

object ElasticSearchResolver {
private def local = Option(ElasticNodeEndpoint("http","localhost",9200, None))
private def fromEnvironment = {
Option(System.getenv("ELASTICSEARCH_HOST")).map(host=>{
val proto = if(System.getenv("ELASTICSEARCH_HTTPS")==null) "http" else "https"
val port = Option(System.getenv("ELASTICSEARCH_PORT")).map(_.toInt).getOrElse(9200)
ElasticNodeEndpoint(proto, host, port, Option(System.getenv("ELASTICSEARCH_PREFIX")))
})
}

def resolve():ElasticNodeEndpoint = {
fromEnvironment orElse local
}.get
}
2 changes: 1 addition & 1 deletion src/main/scala/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import scala.concurrent.duration._
object Main extends IOApp {
private val logger = LoggerFactory.getLogger(getClass)
DefaultExports.initialize()
val documentRepo = new ElasticsearchRepo(ElasticNodeEndpoint("http","localhost",9200, None))
val documentRepo = new ElasticsearchRepo(ElasticSearchResolver.resolve())
val server = new GraphQLServer(documentRepo)

val graphqlService = HttpRoutes.of[IO] {
Expand Down

0 comments on commit 77b280b

Please sign in to comment.