Skip to content

Commit

Permalink
feat(infra): [ATL-1889] create local deployment config
Browse files Browse the repository at this point in the history
* feat: Add docker compose and HAProxy configs

* feat(castor,mercury): Added sbt-native-packager as plugin and configured basic docker image

* feat:Updated docker-compose and HA Proxy configs and created run.sh to spin up local instance

* chore(castor): Bump sbt-protoc version to 1.0.6 for M1 support

* chore(infra): Fix castor image name in docker-compose config

* feat(castor): add route to get OAS

* chore(castor): Update OAS server url to localhost

* chore(castor): patch OperationType model

* chore(infra): Fix mercury docker config

* Add pollux service credential API stub

* Update Pollux OAS spec to make it work with Akka

* fix(pollux): fix forward reference issue

* chore(pollux): fix server address in OAS

* chore(infra): integrate Pollux service

* chore(infra): build Pollux image in run.sh

Co-authored-by: Benjamin Voiturier <[email protected]>
Co-authored-by: David <[email protected]>
Co-authored-by: Pat Losoponkul <[email protected]>
  • Loading branch information
4 people authored Sep 30, 2022
1 parent def88ee commit 3f381cd
Show file tree
Hide file tree
Showing 43 changed files with 1,285 additions and 311 deletions.
4 changes: 2 additions & 2 deletions castor/api/http/castor-openapi-spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ info:
name: Core DID
email: [email protected]
servers:
- url: "https://api.atala.io"
- url: "http://localhost/castor"
tags:
- name: DID
description: DID REST API
Expand All @@ -17,7 +17,7 @@ tags:
description: DID Authentication REST API

paths:
/dids/:
/dids:
post:
tags: [ "DID" ]
operationId: createDid
Expand Down
12 changes: 9 additions & 3 deletions castor/service/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,21 @@ lazy val server = project
name := "castor-server",
libraryDependencies ++= apiServerDependencies,
// OpenAPI settings
Compile / unmanagedResourceDirectories += apiBaseDirectory.value / "http",
Compile / sourceGenerators += openApiGenerateClasses,
openApiGeneratorSpec := apiBaseDirectory.value / "http/castor-openapi-spec.yaml",
openApiGeneratorConfig := baseDirectory.value / "openapi/generator-config/config.yaml",
openApiGeneratorImportMapping := Seq("DidType", "DidOperationType", "DidOperationStatus")
openApiGeneratorImportMapping := Seq("DidType", "DidOperationType", "DidOperationStatus", "OperationType")
.map(model => (model, s"io.iohk.atala.castor.server.http.OASModelPatches.$model"))
.toMap,
// gRPC settings
Compile / PB.targets := Seq(scalapb.gen() -> (Compile / sourceManaged).value / "scalapb"),
Compile / PB.protoSources := Seq(apiBaseDirectory.value / "grpc")
Compile / PB.protoSources := Seq(apiBaseDirectory.value / "grpc"),
Docker / maintainer := "[email protected]",
Docker / dockerRepository := Some("atala-prism.io"),
// Docker / packageName := s"atala-prism/${packageName.value}",
dockerExposedPorts := Seq(8080),
dockerBaseImage := "openjdk:11"
)
.enablePlugins(OpenApiGeneratorPlugin)
.enablePlugins(OpenApiGeneratorPlugin, JavaAppPackaging, DockerPlugin)
.dependsOn(core, sql)
1 change: 1 addition & 0 deletions castor/service/project/build.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6")
addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.9.11")

libraryDependencies ++= Seq("org.openapitools" % "openapi-generator" % "6.0.0")
2 changes: 1 addition & 1 deletion castor/service/project/scalapb.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
addSbtPlugin("com.thesamet" % "sbt-protoc" % "1.0.3")
addSbtPlugin("com.thesamet" % "sbt-protoc" % "1.0.6")

libraryDependencies ++= Seq("com.thesamet.scalapb" %% "compilerplugin" % "0.11.11")
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.iohk.atala.castor.server.http

import akka.http.scaladsl.model.{ContentType, ContentTypes}
import akka.http.scaladsl.server.Route
import akka.http.scaladsl.server.Directives.*
import io.iohk.atala.castor.openapi.api.{DIDApi, DIDAuthenticationApi, DIDOperationsApi}
Expand All @@ -12,6 +13,14 @@ object HttpRoutes {
didApi <- ZIO.service[DIDApi]
didOperationsApi <- ZIO.service[DIDOperationsApi]
didAuthApi <- ZIO.service[DIDAuthenticationApi]
} yield didApi.route ~ didOperationsApi.route ~ didAuthApi.route
} yield additionalRoute ~ didApi.route ~ didOperationsApi.route ~ didAuthApi.route

private def additionalRoute: Route = {
path("api" / "openapi-spec.yaml") {
get {
getFromResource("castor-openapi-spec.yaml", ContentTypes.`text/plain(UTF-8)`)
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ object OASModelPatches {
type DidType = String
type DidOperationType = String
type DidOperationStatus = String
type OperationType = String

}
9 changes: 9 additions & 0 deletions infrastructure/local/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# How-to

Use the `run.sh` provided

From root of project

```bash
./infrastructure/local/run.sh
```
33 changes: 33 additions & 0 deletions infrastructure/local/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: '3.8'

services:
castor:
image: atala-prism.io/castor-server:0.1.0-SNAPSHOT

pollux:
image: atala-prism.io/pollux-server:0.1.0-SNAPSHOT

mercury:
image: atala-prism.io/mercury-mediator:0.1.0-SNAPSHOT

swagger-ui:
image: swaggerapi/swagger-ui:v4.14.0
environment:
- 'URLS=[
{ name: "Castor", url: "/castor/api/openapi-spec.yaml" },
{ name: "Pollux", url: "/pollux/api/openapi-spec.yaml" },
{ name: "Mercury", url: "/mercury/api/openapi-spec.yaml" }
]'
- BASE_URL=/apidocs

haproxy:
image: haproxy:2.6.5
ports:
- "80:80" # Http
depends_on:
- castor
- pollux
- mercury
- swagger-ui
volumes:
- ./haproxy:/usr/local/etc/haproxy:ro
58 changes: 58 additions & 0 deletions infrastructure/local/haproxy/haproxy.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
global
log 127.0.0.1 local0 debug
maxconn 4096

ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS
ssl-default-bind-options no-sslv3
tune.ssl.default-dh-param 2048

defaults
mode http
option log-separate-errors
timeout connect 20000ms
timeout client 50000ms
timeout server 50000ms
timeout tunnel 60s
# never fail on address resolution
default-server init-addr last,libc,none

log global
#log-format "%{+Q}o %{-Q}ci - - [%trg] %r %ST %U %B \"\" \"\" %cp %ms %ft %b %s %TR/%Tw/%Tc/%Tr/%Ta %tsc %ac/%fc/%bc/%sc/%rc %sq/%bq \"%CC\" \"%CS\" \"%hr\" \"%hsl\""

frontend https-in
bind *:80
option httplog
option logasap

use_backend castor if { path_beg -i /castor }
use_backend pollux if { path_beg -i /pollux }
use_backend mercury if { path_beg -i /mercury }
use_backend swagger-ui if { path_beg -i /apidocs }

backend castor
balance roundrobin
http-request set-uri %[url,regsub(^/castor,,)] if { path_beg /castor }
option httpclose
option forwardfor
server s1 castor:8080 maxconn 32


backend pollux
balance roundrobin
http-request set-uri %[url,regsub(^/pollux,,)] if { path_beg /pollux }
option httpclose
option forwardfor
server s1 pollux:8080 maxconn 32

backend mercury
balance roundrobin
http-request set-uri %[url,regsub(^/mercury,,)] if { path_beg /mercury }
option httpclose
option forwardfor
server s1 mercury:8080 maxconn 32

backend swagger-ui
balance roundrobin
option httpclose
option forwardfor
server s1 swagger-ui:8080 maxconn 1024
16 changes: 16 additions & 0 deletions infrastructure/local/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

echo "--------------------------------------"
echo "Building docker images"
echo "--------------------------------------"

cd castor/service; sbt docker:publishLocal; cd -
cd mercury/prism-mediator; sbt "project mediator; docker:publishLocal"; cd -
cd pollux/service; sbt docker:publishLocal; cd -

echo "--------------------------------------"
echo "Bringing up stack using docker-compose"
echo "--------------------------------------"

docker-compose -f infrastructure/local/docker-compose.yml up

2 changes: 1 addition & 1 deletion mercury/api/mercury-openapi-spec-auth.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ info:
email: [email protected]

servers:
- url: https://mailbox.mediator.atalaprism.io
- url: http://localhost/mercury

tags:
- name: Mailbox Mediator
Expand Down
5 changes: 5 additions & 0 deletions mercury/prism-mediator/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,12 @@ lazy val mediator = project
),
Compile / unmanagedResourceDirectories += apiBaseDirectory.value,
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework")),
Docker / maintainer := "[email protected]",
Docker / dockerRepository := Some("atala-prism.io"),
dockerExposedPorts := Seq(8080),
dockerBaseImage := "openjdk:11"
)
.enablePlugins(JavaAppPackaging, DockerPlugin)
.dependsOn(agentDidcommx, resolver)
.dependsOn(
protocolConnection,
Expand Down
1 change: 1 addition & 0 deletions mercury/prism-mediator/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6")
addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.9.11")
Loading

0 comments on commit 3f381cd

Please sign in to comment.