Skip to content

Commit

Permalink
feat(shared): Add environmnet configuration for Iris DB and bump scal…
Browse files Browse the repository at this point in the history
…a version in other components to enable build (#96)
  • Loading branch information
davidpoltorak-io authored Nov 8, 2022
1 parent 818e9e0 commit a5b583f
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 14 deletions.
2 changes: 1 addition & 1 deletion iris/service/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def commonProject(project: Project): Project =
project.settings(
version := "0.1.0-SNAPSHOT",
organization := "io.iohk.atala",
scalaVersion := "3.1.3",
scalaVersion := "3.2.0",
githubTokenSource := TokenSource.Environment("ATALA_GITHUB_TOKEN"),
resolvers += Resolver
.githubPackages("input-output-hk", "atala-prism-sdk"),
Expand Down
6 changes: 5 additions & 1 deletion iris/service/project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import sbt._
object Dependencies {
object Versions {
val zio = "2.0.2"
val zioConfig = "3.0.2"
val circe = "0.14.1"
val circeOptics = "0.14.1"
val akka = "2.6.19"
Expand All @@ -15,6 +16,9 @@ object Dependencies {
}

private lazy val zio = "dev.zio" %% "zio" % Versions.zio
private lazy val zioConfig = "dev.zio" %% "zio-config" % Versions.zioConfig
private lazy val zioConfigMagnolia = "dev.zio" %% "zio-config-magnolia" % Versions.zioConfig
private lazy val zioConfigTypesafe = "dev.zio" %% "zio-config-typesafe" % Versions.zioConfig
private lazy val zioStream = "dev.zio" %% "zio-streams" % Versions.zio
private lazy val zioCatsInterop = "dev.zio" %% "zio-interop-cats" % Versions.zioCatsInterop
// We have to exclude bouncycastle since for some reason bitcoinj depends on bouncycastle jdk15to18
Expand Down Expand Up @@ -48,7 +52,7 @@ object Dependencies {
private lazy val zioTestMagnolia = "dev.zio" %% "zio-test-magnolia" % "2.0.2" % Test

// Dependency Modules
private lazy val baseDependencies: Seq[ModuleID] = Seq(zio, zioStream, prismCrypto, shared, enumeratum)
private lazy val baseDependencies: Seq[ModuleID] = Seq(zio, zioConfig, zioConfigMagnolia, zioConfigTypesafe, zioStream, prismCrypto, shared, enumeratum)
private lazy val grpcDependencies: Seq[ModuleID] = Seq(grpcNetty, grpcServices, scalaPbProto, scalaPbGrpc)
private lazy val doobieDependencies: Seq[ModuleID] = Seq(doobiePostgres, doobieHikari)
private lazy val circeDependencies: Seq[ModuleID] =
Expand Down
14 changes: 14 additions & 0 deletions iris/service/server/src/main/resources/application.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
iris {
database {
host = "localhost"
host = ${?IRIS_DB_HOST}
port = 5432
port = ${?IRIS_DB_PORT}
databaseName = "iris"
databaseName = ${?IRIS_DB_NAME}
username = "postgres"
username = ${?IRIS_DB_USER}
password = "postgres"
password = ${?IRIS_DB_PASSWORD}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import io.iohk.atala.iris.sql.repository.*
import zio.*
import zio.interop.catz.*
import zio.stream.ZStream
import com.typesafe.config.ConfigFactory
import io.iohk.atala.iris.server.config.AppConfig
import zio.config.typesafe.TypesafeConfigSource
import zio.config.{ReadError, read}

object Modules {
val app: Task[Unit] = {
Expand All @@ -29,6 +33,16 @@ object Modules {
object AppModule {
val publishingServiceLayer: ULayer[PublishingService] = MockPublishingService.layer
val publishingSchedulerLayer: ULayer[PublishingScheduler] = MockPublishingScheduler.layer

val configLayer: Layer[ReadError[String], AppConfig] = ZLayer.fromZIO {
read(
AppConfig.descriptor.from(
TypesafeConfigSource.fromTypesafeConfig(
ZIO.attempt(ConfigFactory.load())
)
)
)
}
}

object GrpcModule {
Expand Down Expand Up @@ -58,19 +72,23 @@ object BlockchainModule {
}

object RepoModule {
val transactorLayer: TaskLayer[Transactor[Task]] =
ZLayer.fromZIO {
Dispatcher[Task].allocated.map { case (dispatcher, _) =>
given Dispatcher[Task] = dispatcher
TransactorLayer.hikari[Task](
TransactorLayer.DbConfig(
username = "postgres",
password = "postgres",
jdbcUrl = "jdbc:postgresql://localhost:5432/iris"
val transactorLayer: TaskLayer[Transactor[Task]] = {
val layerWithConfig = ZLayer.fromZIO {
ZIO.service[AppConfig].map(_.iris.database).flatMap { config =>
Dispatcher[Task].allocated.map { case (dispatcher, _) =>
given Dispatcher[Task] = dispatcher
TransactorLayer.hikari[Task](
TransactorLayer.DbConfig(
username = config.username,
password = config.password,
jdbcUrl = s"jdbc:postgresql://${config.host}:${config.port}/${config.databaseName}"
)
)
)
}
}
}.flatten
AppModule.configLayer >>> layerWithConfig
}

val dbRepositoryTransactor: TaskLayer[JdbcDbRepositoryTransactorIO] =
transactorLayer >>> JdbcDbRepositoryTransactorIO.layer
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.iohk.atala.iris.server.config

import zio.config.*
import zio.config.magnolia.Descriptor

final case class AppConfig(
iris: IrisConfig
)

object AppConfig {
val descriptor: ConfigDescriptor[AppConfig] = Descriptor[AppConfig]
}

final case class IrisConfig(database: DatabaseConfig)

final case class DatabaseConfig(host: String, port: Int, databaseName: String, username: String, password: String)
2 changes: 1 addition & 1 deletion pollux/vc-jwt/build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Dependencies._

ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / scalaVersion := "3.1.3"
ThisBuild / scalaVersion := "3.2.0"
ThisBuild / organization := "io.iohk.atala"

lazy val root = project
Expand Down
2 changes: 1 addition & 1 deletion prism-agent/service/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Dependencies._
import sbtghpackages.GitHubPackagesPlugin.autoImport._

ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / scalaVersion := "3.1.3"
ThisBuild / scalaVersion := "3.2.0"
ThisBuild / organization := "io.iohk.atala"

// Custom keys
Expand Down

0 comments on commit a5b583f

Please sign in to comment.